lpfc_sli.c 526 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <linux/lockdep.h>
  27. #include <scsi/scsi.h>
  28. #include <scsi/scsi_cmnd.h>
  29. #include <scsi/scsi_device.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_transport_fc.h>
  32. #include <scsi/fc/fc_fs.h>
  33. #include <linux/aer.h>
  34. #include "lpfc_hw4.h"
  35. #include "lpfc_hw.h"
  36. #include "lpfc_sli.h"
  37. #include "lpfc_sli4.h"
  38. #include "lpfc_nl.h"
  39. #include "lpfc_disc.h"
  40. #include "lpfc_scsi.h"
  41. #include "lpfc.h"
  42. #include "lpfc_crtn.h"
  43. #include "lpfc_logmsg.h"
  44. #include "lpfc_compat.h"
  45. #include "lpfc_debugfs.h"
  46. #include "lpfc_vport.h"
  47. /* There are only four IOCB completion types. */
  48. typedef enum _lpfc_iocb_type {
  49. LPFC_UNKNOWN_IOCB,
  50. LPFC_UNSOL_IOCB,
  51. LPFC_SOL_IOCB,
  52. LPFC_ABORT_IOCB
  53. } lpfc_iocb_type;
  54. /* Provide function prototypes local to this module. */
  55. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  56. uint32_t);
  57. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  58. uint8_t *, uint32_t *);
  59. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  60. struct lpfc_iocbq *);
  61. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  62. struct hbq_dmabuf *);
  63. static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
  64. struct lpfc_cqe *);
  65. static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *,
  66. int);
  67. static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *,
  68. uint32_t);
  69. static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
  70. static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
  71. static IOCB_t *
  72. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  73. {
  74. return &iocbq->iocb;
  75. }
  76. /**
  77. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  78. * @q: The Work Queue to operate on.
  79. * @wqe: The work Queue Entry to put on the Work queue.
  80. *
  81. * This routine will copy the contents of @wqe to the next available entry on
  82. * the @q. This function will then ring the Work Queue Doorbell to signal the
  83. * HBA to start processing the Work Queue Entry. This function returns 0 if
  84. * successful. If no entries are available on @q then this function will return
  85. * -ENOMEM.
  86. * The caller is expected to hold the hbalock when calling this routine.
  87. **/
  88. static uint32_t
  89. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  90. {
  91. union lpfc_wqe *temp_wqe;
  92. struct lpfc_register doorbell;
  93. uint32_t host_index;
  94. uint32_t idx;
  95. /* sanity check on queue memory */
  96. if (unlikely(!q))
  97. return -ENOMEM;
  98. temp_wqe = q->qe[q->host_index].wqe;
  99. /* If the host has not yet processed the next entry then we are done */
  100. idx = ((q->host_index + 1) % q->entry_count);
  101. if (idx == q->hba_index) {
  102. q->WQ_overflow++;
  103. return -ENOMEM;
  104. }
  105. q->WQ_posted++;
  106. /* set consumption flag every once in a while */
  107. if (!((q->host_index + 1) % q->entry_repost))
  108. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  109. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  110. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  111. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  112. /* Update the host index before invoking device */
  113. host_index = q->host_index;
  114. q->host_index = idx;
  115. /* Ring Doorbell */
  116. doorbell.word0 = 0;
  117. if (q->db_format == LPFC_DB_LIST_FORMAT) {
  118. bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
  119. bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index);
  120. bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
  121. } else if (q->db_format == LPFC_DB_RING_FORMAT) {
  122. bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
  123. bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
  124. } else {
  125. return -EINVAL;
  126. }
  127. writel(doorbell.word0, q->db_regaddr);
  128. return 0;
  129. }
  130. /**
  131. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  132. * @q: The Work Queue to operate on.
  133. * @index: The index to advance the hba index to.
  134. *
  135. * This routine will update the HBA index of a queue to reflect consumption of
  136. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  137. * an entry the host calls this function to update the queue's internal
  138. * pointers. This routine returns the number of entries that were consumed by
  139. * the HBA.
  140. **/
  141. static uint32_t
  142. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  143. {
  144. uint32_t released = 0;
  145. /* sanity check on queue memory */
  146. if (unlikely(!q))
  147. return 0;
  148. if (q->hba_index == index)
  149. return 0;
  150. do {
  151. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  152. released++;
  153. } while (q->hba_index != index);
  154. return released;
  155. }
  156. /**
  157. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  158. * @q: The Mailbox Queue to operate on.
  159. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  160. *
  161. * This routine will copy the contents of @mqe to the next available entry on
  162. * the @q. This function will then ring the Work Queue Doorbell to signal the
  163. * HBA to start processing the Work Queue Entry. This function returns 0 if
  164. * successful. If no entries are available on @q then this function will return
  165. * -ENOMEM.
  166. * The caller is expected to hold the hbalock when calling this routine.
  167. **/
  168. static uint32_t
  169. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  170. {
  171. struct lpfc_mqe *temp_mqe;
  172. struct lpfc_register doorbell;
  173. /* sanity check on queue memory */
  174. if (unlikely(!q))
  175. return -ENOMEM;
  176. temp_mqe = q->qe[q->host_index].mqe;
  177. /* If the host has not yet processed the next entry then we are done */
  178. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  179. return -ENOMEM;
  180. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  181. /* Save off the mailbox pointer for completion */
  182. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  183. /* Update the host index before invoking device */
  184. q->host_index = ((q->host_index + 1) % q->entry_count);
  185. /* Ring Doorbell */
  186. doorbell.word0 = 0;
  187. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  188. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  189. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  190. return 0;
  191. }
  192. /**
  193. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  194. * @q: The Mailbox Queue to operate on.
  195. *
  196. * This routine will update the HBA index of a queue to reflect consumption of
  197. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  198. * an entry the host calls this function to update the queue's internal
  199. * pointers. This routine returns the number of entries that were consumed by
  200. * the HBA.
  201. **/
  202. static uint32_t
  203. lpfc_sli4_mq_release(struct lpfc_queue *q)
  204. {
  205. /* sanity check on queue memory */
  206. if (unlikely(!q))
  207. return 0;
  208. /* Clear the mailbox pointer for completion */
  209. q->phba->mbox = NULL;
  210. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  211. return 1;
  212. }
  213. /**
  214. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  215. * @q: The Event Queue to get the first valid EQE from
  216. *
  217. * This routine will get the first valid Event Queue Entry from @q, update
  218. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  219. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  220. * processed, but not popped back to the HBA then this routine will return NULL.
  221. **/
  222. static struct lpfc_eqe *
  223. lpfc_sli4_eq_get(struct lpfc_queue *q)
  224. {
  225. struct lpfc_eqe *eqe;
  226. uint32_t idx;
  227. /* sanity check on queue memory */
  228. if (unlikely(!q))
  229. return NULL;
  230. eqe = q->qe[q->hba_index].eqe;
  231. /* If the next EQE is not valid then we are done */
  232. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  233. return NULL;
  234. /* If the host has not yet processed the next entry then we are done */
  235. idx = ((q->hba_index + 1) % q->entry_count);
  236. if (idx == q->host_index)
  237. return NULL;
  238. q->hba_index = idx;
  239. /*
  240. * insert barrier for instruction interlock : data from the hardware
  241. * must have the valid bit checked before it can be copied and acted
  242. * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
  243. * instructions allowing action on content before valid bit checked,
  244. * add barrier here as well. May not be needed as "content" is a
  245. * single 32-bit entity here (vs multi word structure for cq's).
  246. */
  247. mb();
  248. return eqe;
  249. }
  250. /**
  251. * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
  252. * @q: The Event Queue to disable interrupts
  253. *
  254. **/
  255. static inline void
  256. lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
  257. {
  258. struct lpfc_register doorbell;
  259. doorbell.word0 = 0;
  260. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  261. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  262. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  263. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  264. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  265. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  266. }
  267. /**
  268. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  269. * @q: The Event Queue that the host has completed processing for.
  270. * @arm: Indicates whether the host wants to arms this CQ.
  271. *
  272. * This routine will mark all Event Queue Entries on @q, from the last
  273. * known completed entry to the last entry that was processed, as completed
  274. * by clearing the valid bit for each completion queue entry. Then it will
  275. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  276. * The internal host index in the @q will be updated by this routine to indicate
  277. * that the host has finished processing the entries. The @arm parameter
  278. * indicates that the queue should be rearmed when ringing the doorbell.
  279. *
  280. * This function will return the number of EQEs that were popped.
  281. **/
  282. uint32_t
  283. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  284. {
  285. uint32_t released = 0;
  286. struct lpfc_eqe *temp_eqe;
  287. struct lpfc_register doorbell;
  288. /* sanity check on queue memory */
  289. if (unlikely(!q))
  290. return 0;
  291. /* while there are valid entries */
  292. while (q->hba_index != q->host_index) {
  293. temp_eqe = q->qe[q->host_index].eqe;
  294. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  295. released++;
  296. q->host_index = ((q->host_index + 1) % q->entry_count);
  297. }
  298. if (unlikely(released == 0 && !arm))
  299. return 0;
  300. /* ring doorbell for number popped */
  301. doorbell.word0 = 0;
  302. if (arm) {
  303. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  304. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  305. }
  306. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  307. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  308. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  309. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  310. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  311. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  312. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  313. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  314. readl(q->phba->sli4_hba.EQCQDBregaddr);
  315. return released;
  316. }
  317. /**
  318. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  319. * @q: The Completion Queue to get the first valid CQE from
  320. *
  321. * This routine will get the first valid Completion Queue Entry from @q, update
  322. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  323. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  324. * processed, but not popped back to the HBA then this routine will return NULL.
  325. **/
  326. static struct lpfc_cqe *
  327. lpfc_sli4_cq_get(struct lpfc_queue *q)
  328. {
  329. struct lpfc_cqe *cqe;
  330. uint32_t idx;
  331. /* sanity check on queue memory */
  332. if (unlikely(!q))
  333. return NULL;
  334. /* If the next CQE is not valid then we are done */
  335. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  336. return NULL;
  337. /* If the host has not yet processed the next entry then we are done */
  338. idx = ((q->hba_index + 1) % q->entry_count);
  339. if (idx == q->host_index)
  340. return NULL;
  341. cqe = q->qe[q->hba_index].cqe;
  342. q->hba_index = idx;
  343. /*
  344. * insert barrier for instruction interlock : data from the hardware
  345. * must have the valid bit checked before it can be copied and acted
  346. * upon. Speculative instructions were allowing a bcopy at the start
  347. * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
  348. * after our return, to copy data before the valid bit check above
  349. * was done. As such, some of the copied data was stale. The barrier
  350. * ensures the check is before any data is copied.
  351. */
  352. mb();
  353. return cqe;
  354. }
  355. /**
  356. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  357. * @q: The Completion Queue that the host has completed processing for.
  358. * @arm: Indicates whether the host wants to arms this CQ.
  359. *
  360. * This routine will mark all Completion queue entries on @q, from the last
  361. * known completed entry to the last entry that was processed, as completed
  362. * by clearing the valid bit for each completion queue entry. Then it will
  363. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  364. * The internal host index in the @q will be updated by this routine to indicate
  365. * that the host has finished processing the entries. The @arm parameter
  366. * indicates that the queue should be rearmed when ringing the doorbell.
  367. *
  368. * This function will return the number of CQEs that were released.
  369. **/
  370. uint32_t
  371. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  372. {
  373. uint32_t released = 0;
  374. struct lpfc_cqe *temp_qe;
  375. struct lpfc_register doorbell;
  376. /* sanity check on queue memory */
  377. if (unlikely(!q))
  378. return 0;
  379. /* while there are valid entries */
  380. while (q->hba_index != q->host_index) {
  381. temp_qe = q->qe[q->host_index].cqe;
  382. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  383. released++;
  384. q->host_index = ((q->host_index + 1) % q->entry_count);
  385. }
  386. if (unlikely(released == 0 && !arm))
  387. return 0;
  388. /* ring doorbell for number popped */
  389. doorbell.word0 = 0;
  390. if (arm)
  391. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  392. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  393. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  394. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  395. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  396. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  397. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  398. return released;
  399. }
  400. /**
  401. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  402. * @q: The Header Receive Queue to operate on.
  403. * @wqe: The Receive Queue Entry to put on the Receive queue.
  404. *
  405. * This routine will copy the contents of @wqe to the next available entry on
  406. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  407. * HBA to start processing the Receive Queue Entry. This function returns the
  408. * index that the rqe was copied to if successful. If no entries are available
  409. * on @q then this function will return -ENOMEM.
  410. * The caller is expected to hold the hbalock when calling this routine.
  411. **/
  412. static int
  413. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  414. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  415. {
  416. struct lpfc_rqe *temp_hrqe;
  417. struct lpfc_rqe *temp_drqe;
  418. struct lpfc_register doorbell;
  419. int put_index;
  420. /* sanity check on queue memory */
  421. if (unlikely(!hq) || unlikely(!dq))
  422. return -ENOMEM;
  423. put_index = hq->host_index;
  424. temp_hrqe = hq->qe[hq->host_index].rqe;
  425. temp_drqe = dq->qe[dq->host_index].rqe;
  426. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  427. return -EINVAL;
  428. if (hq->host_index != dq->host_index)
  429. return -EINVAL;
  430. /* If the host has not yet processed the next entry then we are done */
  431. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  432. return -EBUSY;
  433. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  434. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  435. /* Update the host index to point to the next slot */
  436. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  437. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  438. /* Ring The Header Receive Queue Doorbell */
  439. if (!(hq->host_index % hq->entry_repost)) {
  440. doorbell.word0 = 0;
  441. if (hq->db_format == LPFC_DB_RING_FORMAT) {
  442. bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
  443. hq->entry_repost);
  444. bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
  445. } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
  446. bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
  447. hq->entry_repost);
  448. bf_set(lpfc_rq_db_list_fm_index, &doorbell,
  449. hq->host_index);
  450. bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
  451. } else {
  452. return -EINVAL;
  453. }
  454. writel(doorbell.word0, hq->db_regaddr);
  455. }
  456. return put_index;
  457. }
  458. /**
  459. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  460. * @q: The Header Receive Queue to operate on.
  461. *
  462. * This routine will update the HBA index of a queue to reflect consumption of
  463. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  464. * consumed an entry the host calls this function to update the queue's
  465. * internal pointers. This routine returns the number of entries that were
  466. * consumed by the HBA.
  467. **/
  468. static uint32_t
  469. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  470. {
  471. /* sanity check on queue memory */
  472. if (unlikely(!hq) || unlikely(!dq))
  473. return 0;
  474. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  475. return 0;
  476. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  477. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  478. return 1;
  479. }
  480. /**
  481. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  482. * @phba: Pointer to HBA context object.
  483. * @pring: Pointer to driver SLI ring object.
  484. *
  485. * This function returns pointer to next command iocb entry
  486. * in the command ring. The caller must hold hbalock to prevent
  487. * other threads consume the next command iocb.
  488. * SLI-2/SLI-3 provide different sized iocbs.
  489. **/
  490. static inline IOCB_t *
  491. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  492. {
  493. return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
  494. pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
  495. }
  496. /**
  497. * lpfc_resp_iocb - Get next response iocb entry in the ring
  498. * @phba: Pointer to HBA context object.
  499. * @pring: Pointer to driver SLI ring object.
  500. *
  501. * This function returns pointer to next response iocb entry
  502. * in the response ring. The caller must hold hbalock to make sure
  503. * that no other thread consume the next response iocb.
  504. * SLI-2/SLI-3 provide different sized iocbs.
  505. **/
  506. static inline IOCB_t *
  507. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  508. {
  509. return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
  510. pring->sli.sli3.rspidx * phba->iocb_rsp_size);
  511. }
  512. /**
  513. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  514. * @phba: Pointer to HBA context object.
  515. *
  516. * This function is called with hbalock held. This function
  517. * allocates a new driver iocb object from the iocb pool. If the
  518. * allocation is successful, it returns pointer to the newly
  519. * allocated iocb object else it returns NULL.
  520. **/
  521. struct lpfc_iocbq *
  522. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  523. {
  524. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  525. struct lpfc_iocbq * iocbq = NULL;
  526. lockdep_assert_held(&phba->hbalock);
  527. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  528. if (iocbq)
  529. phba->iocb_cnt++;
  530. if (phba->iocb_cnt > phba->iocb_max)
  531. phba->iocb_max = phba->iocb_cnt;
  532. return iocbq;
  533. }
  534. /**
  535. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  536. * @phba: Pointer to HBA context object.
  537. * @xritag: XRI value.
  538. *
  539. * This function clears the sglq pointer from the array of acive
  540. * sglq's. The xritag that is passed in is used to index into the
  541. * array. Before the xritag can be used it needs to be adjusted
  542. * by subtracting the xribase.
  543. *
  544. * Returns sglq ponter = success, NULL = Failure.
  545. **/
  546. static struct lpfc_sglq *
  547. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  548. {
  549. struct lpfc_sglq *sglq;
  550. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  551. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  552. return sglq;
  553. }
  554. /**
  555. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  556. * @phba: Pointer to HBA context object.
  557. * @xritag: XRI value.
  558. *
  559. * This function returns the sglq pointer from the array of acive
  560. * sglq's. The xritag that is passed in is used to index into the
  561. * array. Before the xritag can be used it needs to be adjusted
  562. * by subtracting the xribase.
  563. *
  564. * Returns sglq ponter = success, NULL = Failure.
  565. **/
  566. struct lpfc_sglq *
  567. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  568. {
  569. struct lpfc_sglq *sglq;
  570. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  571. return sglq;
  572. }
  573. /**
  574. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  575. * @phba: Pointer to HBA context object.
  576. * @xritag: xri used in this exchange.
  577. * @rrq: The RRQ to be cleared.
  578. *
  579. **/
  580. void
  581. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  582. uint16_t xritag,
  583. struct lpfc_node_rrq *rrq)
  584. {
  585. struct lpfc_nodelist *ndlp = NULL;
  586. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  587. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  588. /* The target DID could have been swapped (cable swap)
  589. * we should use the ndlp from the findnode if it is
  590. * available.
  591. */
  592. if ((!ndlp) && rrq->ndlp)
  593. ndlp = rrq->ndlp;
  594. if (!ndlp)
  595. goto out;
  596. if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
  597. rrq->send_rrq = 0;
  598. rrq->xritag = 0;
  599. rrq->rrq_stop_time = 0;
  600. }
  601. out:
  602. mempool_free(rrq, phba->rrq_pool);
  603. }
  604. /**
  605. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  606. * @phba: Pointer to HBA context object.
  607. *
  608. * This function is called with hbalock held. This function
  609. * Checks if stop_time (ratov from setting rrq active) has
  610. * been reached, if it has and the send_rrq flag is set then
  611. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  612. * then it will just call the routine to clear the rrq and
  613. * free the rrq resource.
  614. * The timer is set to the next rrq that is going to expire before
  615. * leaving the routine.
  616. *
  617. **/
  618. void
  619. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  620. {
  621. struct lpfc_node_rrq *rrq;
  622. struct lpfc_node_rrq *nextrrq;
  623. unsigned long next_time;
  624. unsigned long iflags;
  625. LIST_HEAD(send_rrq);
  626. spin_lock_irqsave(&phba->hbalock, iflags);
  627. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  628. next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  629. list_for_each_entry_safe(rrq, nextrrq,
  630. &phba->active_rrq_list, list) {
  631. if (time_after(jiffies, rrq->rrq_stop_time))
  632. list_move(&rrq->list, &send_rrq);
  633. else if (time_before(rrq->rrq_stop_time, next_time))
  634. next_time = rrq->rrq_stop_time;
  635. }
  636. spin_unlock_irqrestore(&phba->hbalock, iflags);
  637. if ((!list_empty(&phba->active_rrq_list)) &&
  638. (!(phba->pport->load_flag & FC_UNLOADING)))
  639. mod_timer(&phba->rrq_tmr, next_time);
  640. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  641. list_del(&rrq->list);
  642. if (!rrq->send_rrq)
  643. /* this call will free the rrq */
  644. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  645. else if (lpfc_send_rrq(phba, rrq)) {
  646. /* if we send the rrq then the completion handler
  647. * will clear the bit in the xribitmap.
  648. */
  649. lpfc_clr_rrq_active(phba, rrq->xritag,
  650. rrq);
  651. }
  652. }
  653. }
  654. /**
  655. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  656. * @vport: Pointer to vport context object.
  657. * @xri: The xri used in the exchange.
  658. * @did: The targets DID for this exchange.
  659. *
  660. * returns NULL = rrq not found in the phba->active_rrq_list.
  661. * rrq = rrq for this xri and target.
  662. **/
  663. struct lpfc_node_rrq *
  664. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  665. {
  666. struct lpfc_hba *phba = vport->phba;
  667. struct lpfc_node_rrq *rrq;
  668. struct lpfc_node_rrq *nextrrq;
  669. unsigned long iflags;
  670. if (phba->sli_rev != LPFC_SLI_REV4)
  671. return NULL;
  672. spin_lock_irqsave(&phba->hbalock, iflags);
  673. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  674. if (rrq->vport == vport && rrq->xritag == xri &&
  675. rrq->nlp_DID == did){
  676. list_del(&rrq->list);
  677. spin_unlock_irqrestore(&phba->hbalock, iflags);
  678. return rrq;
  679. }
  680. }
  681. spin_unlock_irqrestore(&phba->hbalock, iflags);
  682. return NULL;
  683. }
  684. /**
  685. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  686. * @vport: Pointer to vport context object.
  687. * @ndlp: Pointer to the lpfc_node_list structure.
  688. * If ndlp is NULL Remove all active RRQs for this vport from the
  689. * phba->active_rrq_list and clear the rrq.
  690. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  691. **/
  692. void
  693. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  694. {
  695. struct lpfc_hba *phba = vport->phba;
  696. struct lpfc_node_rrq *rrq;
  697. struct lpfc_node_rrq *nextrrq;
  698. unsigned long iflags;
  699. LIST_HEAD(rrq_list);
  700. if (phba->sli_rev != LPFC_SLI_REV4)
  701. return;
  702. if (!ndlp) {
  703. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  704. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  705. }
  706. spin_lock_irqsave(&phba->hbalock, iflags);
  707. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  708. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  709. list_move(&rrq->list, &rrq_list);
  710. spin_unlock_irqrestore(&phba->hbalock, iflags);
  711. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  712. list_del(&rrq->list);
  713. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  714. }
  715. }
  716. /**
  717. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  718. * @phba: Pointer to HBA context object.
  719. * @ndlp: Targets nodelist pointer for this exchange.
  720. * @xritag the xri in the bitmap to test.
  721. *
  722. * This function is called with hbalock held. This function
  723. * returns 0 = rrq not active for this xri
  724. * 1 = rrq is valid for this xri.
  725. **/
  726. int
  727. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  728. uint16_t xritag)
  729. {
  730. lockdep_assert_held(&phba->hbalock);
  731. if (!ndlp)
  732. return 0;
  733. if (!ndlp->active_rrqs_xri_bitmap)
  734. return 0;
  735. if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
  736. return 1;
  737. else
  738. return 0;
  739. }
  740. /**
  741. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  742. * @phba: Pointer to HBA context object.
  743. * @ndlp: nodelist pointer for this target.
  744. * @xritag: xri used in this exchange.
  745. * @rxid: Remote Exchange ID.
  746. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  747. *
  748. * This function takes the hbalock.
  749. * The active bit is always set in the active rrq xri_bitmap even
  750. * if there is no slot avaiable for the other rrq information.
  751. *
  752. * returns 0 rrq actived for this xri
  753. * < 0 No memory or invalid ndlp.
  754. **/
  755. int
  756. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  757. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  758. {
  759. unsigned long iflags;
  760. struct lpfc_node_rrq *rrq;
  761. int empty;
  762. if (!ndlp)
  763. return -EINVAL;
  764. if (!phba->cfg_enable_rrq)
  765. return -EINVAL;
  766. spin_lock_irqsave(&phba->hbalock, iflags);
  767. if (phba->pport->load_flag & FC_UNLOADING) {
  768. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  769. goto out;
  770. }
  771. /*
  772. * set the active bit even if there is no mem available.
  773. */
  774. if (NLP_CHK_FREE_REQ(ndlp))
  775. goto out;
  776. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  777. goto out;
  778. if (!ndlp->active_rrqs_xri_bitmap)
  779. goto out;
  780. if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
  781. goto out;
  782. spin_unlock_irqrestore(&phba->hbalock, iflags);
  783. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  784. if (!rrq) {
  785. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  786. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  787. " DID:0x%x Send:%d\n",
  788. xritag, rxid, ndlp->nlp_DID, send_rrq);
  789. return -EINVAL;
  790. }
  791. if (phba->cfg_enable_rrq == 1)
  792. rrq->send_rrq = send_rrq;
  793. else
  794. rrq->send_rrq = 0;
  795. rrq->xritag = xritag;
  796. rrq->rrq_stop_time = jiffies +
  797. msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  798. rrq->ndlp = ndlp;
  799. rrq->nlp_DID = ndlp->nlp_DID;
  800. rrq->vport = ndlp->vport;
  801. rrq->rxid = rxid;
  802. spin_lock_irqsave(&phba->hbalock, iflags);
  803. empty = list_empty(&phba->active_rrq_list);
  804. list_add_tail(&rrq->list, &phba->active_rrq_list);
  805. phba->hba_flag |= HBA_RRQ_ACTIVE;
  806. if (empty)
  807. lpfc_worker_wake_up(phba);
  808. spin_unlock_irqrestore(&phba->hbalock, iflags);
  809. return 0;
  810. out:
  811. spin_unlock_irqrestore(&phba->hbalock, iflags);
  812. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  813. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  814. " DID:0x%x Send:%d\n",
  815. xritag, rxid, ndlp->nlp_DID, send_rrq);
  816. return -EINVAL;
  817. }
  818. /**
  819. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  820. * @phba: Pointer to HBA context object.
  821. * @piocb: Pointer to the iocbq.
  822. *
  823. * This function is called with the ring lock held. This function
  824. * gets a new driver sglq object from the sglq list. If the
  825. * list is not empty then it is successful, it returns pointer to the newly
  826. * allocated sglq object else it returns NULL.
  827. **/
  828. static struct lpfc_sglq *
  829. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  830. {
  831. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  832. struct lpfc_sglq *sglq = NULL;
  833. struct lpfc_sglq *start_sglq = NULL;
  834. struct lpfc_scsi_buf *lpfc_cmd;
  835. struct lpfc_nodelist *ndlp;
  836. int found = 0;
  837. lockdep_assert_held(&phba->hbalock);
  838. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  839. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  840. ndlp = lpfc_cmd->rdata->pnode;
  841. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  842. !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  843. ndlp = piocbq->context_un.ndlp;
  844. } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) {
  845. if (piocbq->iocb_flag & LPFC_IO_LOOPBACK)
  846. ndlp = NULL;
  847. else
  848. ndlp = piocbq->context_un.ndlp;
  849. } else {
  850. ndlp = piocbq->context1;
  851. }
  852. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  853. start_sglq = sglq;
  854. while (!found) {
  855. if (!sglq)
  856. return NULL;
  857. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
  858. /* This xri has an rrq outstanding for this DID.
  859. * put it back in the list and get another xri.
  860. */
  861. list_add_tail(&sglq->list, lpfc_sgl_list);
  862. sglq = NULL;
  863. list_remove_head(lpfc_sgl_list, sglq,
  864. struct lpfc_sglq, list);
  865. if (sglq == start_sglq) {
  866. sglq = NULL;
  867. break;
  868. } else
  869. continue;
  870. }
  871. sglq->ndlp = ndlp;
  872. found = 1;
  873. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  874. sglq->state = SGL_ALLOCATED;
  875. }
  876. return sglq;
  877. }
  878. /**
  879. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  880. * @phba: Pointer to HBA context object.
  881. *
  882. * This function is called with no lock held. This function
  883. * allocates a new driver iocb object from the iocb pool. If the
  884. * allocation is successful, it returns pointer to the newly
  885. * allocated iocb object else it returns NULL.
  886. **/
  887. struct lpfc_iocbq *
  888. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  889. {
  890. struct lpfc_iocbq * iocbq = NULL;
  891. unsigned long iflags;
  892. spin_lock_irqsave(&phba->hbalock, iflags);
  893. iocbq = __lpfc_sli_get_iocbq(phba);
  894. spin_unlock_irqrestore(&phba->hbalock, iflags);
  895. return iocbq;
  896. }
  897. /**
  898. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  899. * @phba: Pointer to HBA context object.
  900. * @iocbq: Pointer to driver iocb object.
  901. *
  902. * This function is called with hbalock held to release driver
  903. * iocb object to the iocb pool. The iotag in the iocb object
  904. * does not change for each use of the iocb object. This function
  905. * clears all other fields of the iocb object when it is freed.
  906. * The sqlq structure that holds the xritag and phys and virtual
  907. * mappings for the scatter gather list is retrieved from the
  908. * active array of sglq. The get of the sglq pointer also clears
  909. * the entry in the array. If the status of the IO indiactes that
  910. * this IO was aborted then the sglq entry it put on the
  911. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  912. * IO has good status or fails for any other reason then the sglq
  913. * entry is added to the free list (lpfc_sgl_list).
  914. **/
  915. static void
  916. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  917. {
  918. struct lpfc_sglq *sglq;
  919. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  920. unsigned long iflag = 0;
  921. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  922. lockdep_assert_held(&phba->hbalock);
  923. if (iocbq->sli4_xritag == NO_XRI)
  924. sglq = NULL;
  925. else
  926. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  927. if (sglq) {
  928. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  929. (sglq->state != SGL_XRI_ABORTED)) {
  930. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  931. iflag);
  932. list_add(&sglq->list,
  933. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  934. spin_unlock_irqrestore(
  935. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  936. } else {
  937. spin_lock_irqsave(&pring->ring_lock, iflag);
  938. sglq->state = SGL_FREED;
  939. sglq->ndlp = NULL;
  940. list_add_tail(&sglq->list,
  941. &phba->sli4_hba.lpfc_sgl_list);
  942. spin_unlock_irqrestore(&pring->ring_lock, iflag);
  943. /* Check if TXQ queue needs to be serviced */
  944. if (!list_empty(&pring->txq))
  945. lpfc_worker_wake_up(phba);
  946. }
  947. }
  948. /*
  949. * Clean all volatile data fields, preserve iotag and node struct.
  950. */
  951. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  952. iocbq->sli4_lxritag = NO_XRI;
  953. iocbq->sli4_xritag = NO_XRI;
  954. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  955. }
  956. /**
  957. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  958. * @phba: Pointer to HBA context object.
  959. * @iocbq: Pointer to driver iocb object.
  960. *
  961. * This function is called with hbalock held to release driver
  962. * iocb object to the iocb pool. The iotag in the iocb object
  963. * does not change for each use of the iocb object. This function
  964. * clears all other fields of the iocb object when it is freed.
  965. **/
  966. static void
  967. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  968. {
  969. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  970. lockdep_assert_held(&phba->hbalock);
  971. /*
  972. * Clean all volatile data fields, preserve iotag and node struct.
  973. */
  974. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  975. iocbq->sli4_xritag = NO_XRI;
  976. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  977. }
  978. /**
  979. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  980. * @phba: Pointer to HBA context object.
  981. * @iocbq: Pointer to driver iocb object.
  982. *
  983. * This function is called with hbalock held to release driver
  984. * iocb object to the iocb pool. The iotag in the iocb object
  985. * does not change for each use of the iocb object. This function
  986. * clears all other fields of the iocb object when it is freed.
  987. **/
  988. static void
  989. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  990. {
  991. lockdep_assert_held(&phba->hbalock);
  992. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  993. phba->iocb_cnt--;
  994. }
  995. /**
  996. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  997. * @phba: Pointer to HBA context object.
  998. * @iocbq: Pointer to driver iocb object.
  999. *
  1000. * This function is called with no lock held to release the iocb to
  1001. * iocb pool.
  1002. **/
  1003. void
  1004. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1005. {
  1006. unsigned long iflags;
  1007. /*
  1008. * Clean all volatile data fields, preserve iotag and node struct.
  1009. */
  1010. spin_lock_irqsave(&phba->hbalock, iflags);
  1011. __lpfc_sli_release_iocbq(phba, iocbq);
  1012. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1013. }
  1014. /**
  1015. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  1016. * @phba: Pointer to HBA context object.
  1017. * @iocblist: List of IOCBs.
  1018. * @ulpstatus: ULP status in IOCB command field.
  1019. * @ulpWord4: ULP word-4 in IOCB command field.
  1020. *
  1021. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  1022. * on the list by invoking the complete callback function associated with the
  1023. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  1024. * fields.
  1025. **/
  1026. void
  1027. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  1028. uint32_t ulpstatus, uint32_t ulpWord4)
  1029. {
  1030. struct lpfc_iocbq *piocb;
  1031. while (!list_empty(iocblist)) {
  1032. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  1033. if (!piocb->iocb_cmpl)
  1034. lpfc_sli_release_iocbq(phba, piocb);
  1035. else {
  1036. piocb->iocb.ulpStatus = ulpstatus;
  1037. piocb->iocb.un.ulpWord[4] = ulpWord4;
  1038. (piocb->iocb_cmpl) (phba, piocb, piocb);
  1039. }
  1040. }
  1041. return;
  1042. }
  1043. /**
  1044. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1045. * @iocb_cmnd: iocb command code.
  1046. *
  1047. * This function is called by ring event handler function to get the iocb type.
  1048. * This function translates the iocb command to an iocb command type used to
  1049. * decide the final disposition of each completed IOCB.
  1050. * The function returns
  1051. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1052. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1053. * LPFC_ABORT_IOCB if it is an abort iocb
  1054. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1055. *
  1056. * The caller is not required to hold any lock.
  1057. **/
  1058. static lpfc_iocb_type
  1059. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1060. {
  1061. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1062. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1063. return 0;
  1064. switch (iocb_cmnd) {
  1065. case CMD_XMIT_SEQUENCE_CR:
  1066. case CMD_XMIT_SEQUENCE_CX:
  1067. case CMD_XMIT_BCAST_CN:
  1068. case CMD_XMIT_BCAST_CX:
  1069. case CMD_ELS_REQUEST_CR:
  1070. case CMD_ELS_REQUEST_CX:
  1071. case CMD_CREATE_XRI_CR:
  1072. case CMD_CREATE_XRI_CX:
  1073. case CMD_GET_RPI_CN:
  1074. case CMD_XMIT_ELS_RSP_CX:
  1075. case CMD_GET_RPI_CR:
  1076. case CMD_FCP_IWRITE_CR:
  1077. case CMD_FCP_IWRITE_CX:
  1078. case CMD_FCP_IREAD_CR:
  1079. case CMD_FCP_IREAD_CX:
  1080. case CMD_FCP_ICMND_CR:
  1081. case CMD_FCP_ICMND_CX:
  1082. case CMD_FCP_TSEND_CX:
  1083. case CMD_FCP_TRSP_CX:
  1084. case CMD_FCP_TRECEIVE_CX:
  1085. case CMD_FCP_AUTO_TRSP_CX:
  1086. case CMD_ADAPTER_MSG:
  1087. case CMD_ADAPTER_DUMP:
  1088. case CMD_XMIT_SEQUENCE64_CR:
  1089. case CMD_XMIT_SEQUENCE64_CX:
  1090. case CMD_XMIT_BCAST64_CN:
  1091. case CMD_XMIT_BCAST64_CX:
  1092. case CMD_ELS_REQUEST64_CR:
  1093. case CMD_ELS_REQUEST64_CX:
  1094. case CMD_FCP_IWRITE64_CR:
  1095. case CMD_FCP_IWRITE64_CX:
  1096. case CMD_FCP_IREAD64_CR:
  1097. case CMD_FCP_IREAD64_CX:
  1098. case CMD_FCP_ICMND64_CR:
  1099. case CMD_FCP_ICMND64_CX:
  1100. case CMD_FCP_TSEND64_CX:
  1101. case CMD_FCP_TRSP64_CX:
  1102. case CMD_FCP_TRECEIVE64_CX:
  1103. case CMD_GEN_REQUEST64_CR:
  1104. case CMD_GEN_REQUEST64_CX:
  1105. case CMD_XMIT_ELS_RSP64_CX:
  1106. case DSSCMD_IWRITE64_CR:
  1107. case DSSCMD_IWRITE64_CX:
  1108. case DSSCMD_IREAD64_CR:
  1109. case DSSCMD_IREAD64_CX:
  1110. type = LPFC_SOL_IOCB;
  1111. break;
  1112. case CMD_ABORT_XRI_CN:
  1113. case CMD_ABORT_XRI_CX:
  1114. case CMD_CLOSE_XRI_CN:
  1115. case CMD_CLOSE_XRI_CX:
  1116. case CMD_XRI_ABORTED_CX:
  1117. case CMD_ABORT_MXRI64_CN:
  1118. case CMD_XMIT_BLS_RSP64_CX:
  1119. type = LPFC_ABORT_IOCB;
  1120. break;
  1121. case CMD_RCV_SEQUENCE_CX:
  1122. case CMD_RCV_ELS_REQ_CX:
  1123. case CMD_RCV_SEQUENCE64_CX:
  1124. case CMD_RCV_ELS_REQ64_CX:
  1125. case CMD_ASYNC_STATUS:
  1126. case CMD_IOCB_RCV_SEQ64_CX:
  1127. case CMD_IOCB_RCV_ELS64_CX:
  1128. case CMD_IOCB_RCV_CONT64_CX:
  1129. case CMD_IOCB_RET_XRI64_CX:
  1130. type = LPFC_UNSOL_IOCB;
  1131. break;
  1132. case CMD_IOCB_XMIT_MSEQ64_CR:
  1133. case CMD_IOCB_XMIT_MSEQ64_CX:
  1134. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1135. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1136. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1137. case CMD_IOCB_ABORT_EXTENDED_CN:
  1138. case CMD_IOCB_RET_HBQE64_CN:
  1139. case CMD_IOCB_FCP_IBIDIR64_CR:
  1140. case CMD_IOCB_FCP_IBIDIR64_CX:
  1141. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1142. case CMD_IOCB_LOGENTRY_CN:
  1143. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1144. printk("%s - Unhandled SLI-3 Command x%x\n",
  1145. __func__, iocb_cmnd);
  1146. type = LPFC_UNKNOWN_IOCB;
  1147. break;
  1148. default:
  1149. type = LPFC_UNKNOWN_IOCB;
  1150. break;
  1151. }
  1152. return type;
  1153. }
  1154. /**
  1155. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1156. * @phba: Pointer to HBA context object.
  1157. *
  1158. * This function is called from SLI initialization code
  1159. * to configure every ring of the HBA's SLI interface. The
  1160. * caller is not required to hold any lock. This function issues
  1161. * a config_ring mailbox command for each ring.
  1162. * This function returns zero if successful else returns a negative
  1163. * error code.
  1164. **/
  1165. static int
  1166. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1167. {
  1168. struct lpfc_sli *psli = &phba->sli;
  1169. LPFC_MBOXQ_t *pmb;
  1170. MAILBOX_t *pmbox;
  1171. int i, rc, ret = 0;
  1172. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1173. if (!pmb)
  1174. return -ENOMEM;
  1175. pmbox = &pmb->u.mb;
  1176. phba->link_state = LPFC_INIT_MBX_CMDS;
  1177. for (i = 0; i < psli->num_rings; i++) {
  1178. lpfc_config_ring(phba, i, pmb);
  1179. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1180. if (rc != MBX_SUCCESS) {
  1181. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1182. "0446 Adapter failed to init (%d), "
  1183. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1184. "ring %d\n",
  1185. rc, pmbox->mbxCommand,
  1186. pmbox->mbxStatus, i);
  1187. phba->link_state = LPFC_HBA_ERROR;
  1188. ret = -ENXIO;
  1189. break;
  1190. }
  1191. }
  1192. mempool_free(pmb, phba->mbox_mem_pool);
  1193. return ret;
  1194. }
  1195. /**
  1196. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1197. * @phba: Pointer to HBA context object.
  1198. * @pring: Pointer to driver SLI ring object.
  1199. * @piocb: Pointer to the driver iocb object.
  1200. *
  1201. * This function is called with hbalock held. The function adds the
  1202. * new iocb to txcmplq of the given ring. This function always returns
  1203. * 0. If this function is called for ELS ring, this function checks if
  1204. * there is a vport associated with the ELS command. This function also
  1205. * starts els_tmofunc timer if this is an ELS command.
  1206. **/
  1207. static int
  1208. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1209. struct lpfc_iocbq *piocb)
  1210. {
  1211. lockdep_assert_held(&phba->hbalock);
  1212. BUG_ON(!piocb);
  1213. list_add_tail(&piocb->list, &pring->txcmplq);
  1214. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1215. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1216. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1217. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1218. BUG_ON(!piocb->vport);
  1219. if (!(piocb->vport->load_flag & FC_UNLOADING))
  1220. mod_timer(&piocb->vport->els_tmofunc,
  1221. jiffies +
  1222. msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
  1223. }
  1224. return 0;
  1225. }
  1226. /**
  1227. * lpfc_sli_ringtx_get - Get first element of the txq
  1228. * @phba: Pointer to HBA context object.
  1229. * @pring: Pointer to driver SLI ring object.
  1230. *
  1231. * This function is called with hbalock held to get next
  1232. * iocb in txq of the given ring. If there is any iocb in
  1233. * the txq, the function returns first iocb in the list after
  1234. * removing the iocb from the list, else it returns NULL.
  1235. **/
  1236. struct lpfc_iocbq *
  1237. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1238. {
  1239. struct lpfc_iocbq *cmd_iocb;
  1240. lockdep_assert_held(&phba->hbalock);
  1241. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1242. return cmd_iocb;
  1243. }
  1244. /**
  1245. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1246. * @phba: Pointer to HBA context object.
  1247. * @pring: Pointer to driver SLI ring object.
  1248. *
  1249. * This function is called with hbalock held and the caller must post the
  1250. * iocb without releasing the lock. If the caller releases the lock,
  1251. * iocb slot returned by the function is not guaranteed to be available.
  1252. * The function returns pointer to the next available iocb slot if there
  1253. * is available slot in the ring, else it returns NULL.
  1254. * If the get index of the ring is ahead of the put index, the function
  1255. * will post an error attention event to the worker thread to take the
  1256. * HBA to offline state.
  1257. **/
  1258. static IOCB_t *
  1259. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1260. {
  1261. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1262. uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
  1263. lockdep_assert_held(&phba->hbalock);
  1264. if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
  1265. (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
  1266. pring->sli.sli3.next_cmdidx = 0;
  1267. if (unlikely(pring->sli.sli3.local_getidx ==
  1268. pring->sli.sli3.next_cmdidx)) {
  1269. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1270. if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
  1271. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1272. "0315 Ring %d issue: portCmdGet %d "
  1273. "is bigger than cmd ring %d\n",
  1274. pring->ringno,
  1275. pring->sli.sli3.local_getidx,
  1276. max_cmd_idx);
  1277. phba->link_state = LPFC_HBA_ERROR;
  1278. /*
  1279. * All error attention handlers are posted to
  1280. * worker thread
  1281. */
  1282. phba->work_ha |= HA_ERATT;
  1283. phba->work_hs = HS_FFER3;
  1284. lpfc_worker_wake_up(phba);
  1285. return NULL;
  1286. }
  1287. if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
  1288. return NULL;
  1289. }
  1290. return lpfc_cmd_iocb(phba, pring);
  1291. }
  1292. /**
  1293. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1294. * @phba: Pointer to HBA context object.
  1295. * @iocbq: Pointer to driver iocb object.
  1296. *
  1297. * This function gets an iotag for the iocb. If there is no unused iotag and
  1298. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1299. * array and assigns a new iotag.
  1300. * The function returns the allocated iotag if successful, else returns zero.
  1301. * Zero is not a valid iotag.
  1302. * The caller is not required to hold any lock.
  1303. **/
  1304. uint16_t
  1305. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1306. {
  1307. struct lpfc_iocbq **new_arr;
  1308. struct lpfc_iocbq **old_arr;
  1309. size_t new_len;
  1310. struct lpfc_sli *psli = &phba->sli;
  1311. uint16_t iotag;
  1312. spin_lock_irq(&phba->hbalock);
  1313. iotag = psli->last_iotag;
  1314. if(++iotag < psli->iocbq_lookup_len) {
  1315. psli->last_iotag = iotag;
  1316. psli->iocbq_lookup[iotag] = iocbq;
  1317. spin_unlock_irq(&phba->hbalock);
  1318. iocbq->iotag = iotag;
  1319. return iotag;
  1320. } else if (psli->iocbq_lookup_len < (0xffff
  1321. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1322. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1323. spin_unlock_irq(&phba->hbalock);
  1324. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1325. GFP_KERNEL);
  1326. if (new_arr) {
  1327. spin_lock_irq(&phba->hbalock);
  1328. old_arr = psli->iocbq_lookup;
  1329. if (new_len <= psli->iocbq_lookup_len) {
  1330. /* highly unprobable case */
  1331. kfree(new_arr);
  1332. iotag = psli->last_iotag;
  1333. if(++iotag < psli->iocbq_lookup_len) {
  1334. psli->last_iotag = iotag;
  1335. psli->iocbq_lookup[iotag] = iocbq;
  1336. spin_unlock_irq(&phba->hbalock);
  1337. iocbq->iotag = iotag;
  1338. return iotag;
  1339. }
  1340. spin_unlock_irq(&phba->hbalock);
  1341. return 0;
  1342. }
  1343. if (psli->iocbq_lookup)
  1344. memcpy(new_arr, old_arr,
  1345. ((psli->last_iotag + 1) *
  1346. sizeof (struct lpfc_iocbq *)));
  1347. psli->iocbq_lookup = new_arr;
  1348. psli->iocbq_lookup_len = new_len;
  1349. psli->last_iotag = iotag;
  1350. psli->iocbq_lookup[iotag] = iocbq;
  1351. spin_unlock_irq(&phba->hbalock);
  1352. iocbq->iotag = iotag;
  1353. kfree(old_arr);
  1354. return iotag;
  1355. }
  1356. } else
  1357. spin_unlock_irq(&phba->hbalock);
  1358. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1359. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1360. psli->last_iotag);
  1361. return 0;
  1362. }
  1363. /**
  1364. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1365. * @phba: Pointer to HBA context object.
  1366. * @pring: Pointer to driver SLI ring object.
  1367. * @iocb: Pointer to iocb slot in the ring.
  1368. * @nextiocb: Pointer to driver iocb object which need to be
  1369. * posted to firmware.
  1370. *
  1371. * This function is called with hbalock held to post a new iocb to
  1372. * the firmware. This function copies the new iocb to ring iocb slot and
  1373. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1374. * a completion call back for this iocb else the function will free the
  1375. * iocb object.
  1376. **/
  1377. static void
  1378. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1379. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1380. {
  1381. lockdep_assert_held(&phba->hbalock);
  1382. /*
  1383. * Set up an iotag
  1384. */
  1385. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1386. if (pring->ringno == LPFC_ELS_RING) {
  1387. lpfc_debugfs_slow_ring_trc(phba,
  1388. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1389. *(((uint32_t *) &nextiocb->iocb) + 4),
  1390. *(((uint32_t *) &nextiocb->iocb) + 6),
  1391. *(((uint32_t *) &nextiocb->iocb) + 7));
  1392. }
  1393. /*
  1394. * Issue iocb command to adapter
  1395. */
  1396. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1397. wmb();
  1398. pring->stats.iocb_cmd++;
  1399. /*
  1400. * If there is no completion routine to call, we can release the
  1401. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1402. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1403. */
  1404. if (nextiocb->iocb_cmpl)
  1405. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1406. else
  1407. __lpfc_sli_release_iocbq(phba, nextiocb);
  1408. /*
  1409. * Let the HBA know what IOCB slot will be the next one the
  1410. * driver will put a command into.
  1411. */
  1412. pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
  1413. writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1414. }
  1415. /**
  1416. * lpfc_sli_update_full_ring - Update the chip attention register
  1417. * @phba: Pointer to HBA context object.
  1418. * @pring: Pointer to driver SLI ring object.
  1419. *
  1420. * The caller is not required to hold any lock for calling this function.
  1421. * This function updates the chip attention bits for the ring to inform firmware
  1422. * that there are pending work to be done for this ring and requests an
  1423. * interrupt when there is space available in the ring. This function is
  1424. * called when the driver is unable to post more iocbs to the ring due
  1425. * to unavailability of space in the ring.
  1426. **/
  1427. static void
  1428. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1429. {
  1430. int ringno = pring->ringno;
  1431. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1432. wmb();
  1433. /*
  1434. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1435. * The HBA will tell us when an IOCB entry is available.
  1436. */
  1437. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1438. readl(phba->CAregaddr); /* flush */
  1439. pring->stats.iocb_cmd_full++;
  1440. }
  1441. /**
  1442. * lpfc_sli_update_ring - Update chip attention register
  1443. * @phba: Pointer to HBA context object.
  1444. * @pring: Pointer to driver SLI ring object.
  1445. *
  1446. * This function updates the chip attention register bit for the
  1447. * given ring to inform HBA that there is more work to be done
  1448. * in this ring. The caller is not required to hold any lock.
  1449. **/
  1450. static void
  1451. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1452. {
  1453. int ringno = pring->ringno;
  1454. /*
  1455. * Tell the HBA that there is work to do in this ring.
  1456. */
  1457. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1458. wmb();
  1459. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1460. readl(phba->CAregaddr); /* flush */
  1461. }
  1462. }
  1463. /**
  1464. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1465. * @phba: Pointer to HBA context object.
  1466. * @pring: Pointer to driver SLI ring object.
  1467. *
  1468. * This function is called with hbalock held to post pending iocbs
  1469. * in the txq to the firmware. This function is called when driver
  1470. * detects space available in the ring.
  1471. **/
  1472. static void
  1473. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1474. {
  1475. IOCB_t *iocb;
  1476. struct lpfc_iocbq *nextiocb;
  1477. lockdep_assert_held(&phba->hbalock);
  1478. /*
  1479. * Check to see if:
  1480. * (a) there is anything on the txq to send
  1481. * (b) link is up
  1482. * (c) link attention events can be processed (fcp ring only)
  1483. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1484. */
  1485. if (lpfc_is_link_up(phba) &&
  1486. (!list_empty(&pring->txq)) &&
  1487. (pring->ringno != phba->sli.fcp_ring ||
  1488. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1489. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1490. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1491. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1492. if (iocb)
  1493. lpfc_sli_update_ring(phba, pring);
  1494. else
  1495. lpfc_sli_update_full_ring(phba, pring);
  1496. }
  1497. return;
  1498. }
  1499. /**
  1500. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1501. * @phba: Pointer to HBA context object.
  1502. * @hbqno: HBQ number.
  1503. *
  1504. * This function is called with hbalock held to get the next
  1505. * available slot for the given HBQ. If there is free slot
  1506. * available for the HBQ it will return pointer to the next available
  1507. * HBQ entry else it will return NULL.
  1508. **/
  1509. static struct lpfc_hbq_entry *
  1510. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1511. {
  1512. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1513. lockdep_assert_held(&phba->hbalock);
  1514. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1515. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1516. hbqp->next_hbqPutIdx = 0;
  1517. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1518. uint32_t raw_index = phba->hbq_get[hbqno];
  1519. uint32_t getidx = le32_to_cpu(raw_index);
  1520. hbqp->local_hbqGetIdx = getidx;
  1521. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1522. lpfc_printf_log(phba, KERN_ERR,
  1523. LOG_SLI | LOG_VPORT,
  1524. "1802 HBQ %d: local_hbqGetIdx "
  1525. "%u is > than hbqp->entry_count %u\n",
  1526. hbqno, hbqp->local_hbqGetIdx,
  1527. hbqp->entry_count);
  1528. phba->link_state = LPFC_HBA_ERROR;
  1529. return NULL;
  1530. }
  1531. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1532. return NULL;
  1533. }
  1534. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1535. hbqp->hbqPutIdx;
  1536. }
  1537. /**
  1538. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1539. * @phba: Pointer to HBA context object.
  1540. *
  1541. * This function is called with no lock held to free all the
  1542. * hbq buffers while uninitializing the SLI interface. It also
  1543. * frees the HBQ buffers returned by the firmware but not yet
  1544. * processed by the upper layers.
  1545. **/
  1546. void
  1547. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1548. {
  1549. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1550. struct hbq_dmabuf *hbq_buf;
  1551. unsigned long flags;
  1552. int i, hbq_count;
  1553. uint32_t hbqno;
  1554. hbq_count = lpfc_sli_hbq_count();
  1555. /* Return all memory used by all HBQs */
  1556. spin_lock_irqsave(&phba->hbalock, flags);
  1557. for (i = 0; i < hbq_count; ++i) {
  1558. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1559. &phba->hbqs[i].hbq_buffer_list, list) {
  1560. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1561. list_del(&hbq_buf->dbuf.list);
  1562. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1563. }
  1564. phba->hbqs[i].buffer_count = 0;
  1565. }
  1566. /* Return all HBQ buffer that are in-fly */
  1567. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1568. list) {
  1569. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1570. list_del(&hbq_buf->dbuf.list);
  1571. if (hbq_buf->tag == -1) {
  1572. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1573. (phba, hbq_buf);
  1574. } else {
  1575. hbqno = hbq_buf->tag >> 16;
  1576. if (hbqno >= LPFC_MAX_HBQS)
  1577. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1578. (phba, hbq_buf);
  1579. else
  1580. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1581. hbq_buf);
  1582. }
  1583. }
  1584. /* Mark the HBQs not in use */
  1585. phba->hbq_in_use = 0;
  1586. spin_unlock_irqrestore(&phba->hbalock, flags);
  1587. }
  1588. /**
  1589. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1590. * @phba: Pointer to HBA context object.
  1591. * @hbqno: HBQ number.
  1592. * @hbq_buf: Pointer to HBQ buffer.
  1593. *
  1594. * This function is called with the hbalock held to post a
  1595. * hbq buffer to the firmware. If the function finds an empty
  1596. * slot in the HBQ, it will post the buffer. The function will return
  1597. * pointer to the hbq entry if it successfully post the buffer
  1598. * else it will return NULL.
  1599. **/
  1600. static int
  1601. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1602. struct hbq_dmabuf *hbq_buf)
  1603. {
  1604. lockdep_assert_held(&phba->hbalock);
  1605. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1606. }
  1607. /**
  1608. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1609. * @phba: Pointer to HBA context object.
  1610. * @hbqno: HBQ number.
  1611. * @hbq_buf: Pointer to HBQ buffer.
  1612. *
  1613. * This function is called with the hbalock held to post a hbq buffer to the
  1614. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1615. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1616. * it successfully post the buffer else it will return an error.
  1617. **/
  1618. static int
  1619. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1620. struct hbq_dmabuf *hbq_buf)
  1621. {
  1622. struct lpfc_hbq_entry *hbqe;
  1623. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1624. lockdep_assert_held(&phba->hbalock);
  1625. /* Get next HBQ entry slot to use */
  1626. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1627. if (hbqe) {
  1628. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1629. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1630. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1631. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1632. hbqe->bde.tus.f.bdeFlags = 0;
  1633. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1634. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1635. /* Sync SLIM */
  1636. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1637. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1638. /* flush */
  1639. readl(phba->hbq_put + hbqno);
  1640. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1641. return 0;
  1642. } else
  1643. return -ENOMEM;
  1644. }
  1645. /**
  1646. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1647. * @phba: Pointer to HBA context object.
  1648. * @hbqno: HBQ number.
  1649. * @hbq_buf: Pointer to HBQ buffer.
  1650. *
  1651. * This function is called with the hbalock held to post an RQE to the SLI4
  1652. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1653. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1654. **/
  1655. static int
  1656. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1657. struct hbq_dmabuf *hbq_buf)
  1658. {
  1659. int rc;
  1660. struct lpfc_rqe hrqe;
  1661. struct lpfc_rqe drqe;
  1662. lockdep_assert_held(&phba->hbalock);
  1663. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1664. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1665. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1666. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1667. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1668. &hrqe, &drqe);
  1669. if (rc < 0)
  1670. return rc;
  1671. hbq_buf->tag = rc;
  1672. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1673. return 0;
  1674. }
  1675. /* HBQ for ELS and CT traffic. */
  1676. static struct lpfc_hbq_init lpfc_els_hbq = {
  1677. .rn = 1,
  1678. .entry_count = 256,
  1679. .mask_count = 0,
  1680. .profile = 0,
  1681. .ring_mask = (1 << LPFC_ELS_RING),
  1682. .buffer_count = 0,
  1683. .init_count = 40,
  1684. .add_count = 40,
  1685. };
  1686. /* HBQ for the extra ring if needed */
  1687. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1688. .rn = 1,
  1689. .entry_count = 200,
  1690. .mask_count = 0,
  1691. .profile = 0,
  1692. .ring_mask = (1 << LPFC_EXTRA_RING),
  1693. .buffer_count = 0,
  1694. .init_count = 0,
  1695. .add_count = 5,
  1696. };
  1697. /* Array of HBQs */
  1698. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1699. &lpfc_els_hbq,
  1700. &lpfc_extra_hbq,
  1701. };
  1702. /**
  1703. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1704. * @phba: Pointer to HBA context object.
  1705. * @hbqno: HBQ number.
  1706. * @count: Number of HBQ buffers to be posted.
  1707. *
  1708. * This function is called with no lock held to post more hbq buffers to the
  1709. * given HBQ. The function returns the number of HBQ buffers successfully
  1710. * posted.
  1711. **/
  1712. static int
  1713. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1714. {
  1715. uint32_t i, posted = 0;
  1716. unsigned long flags;
  1717. struct hbq_dmabuf *hbq_buffer;
  1718. LIST_HEAD(hbq_buf_list);
  1719. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1720. return 0;
  1721. if ((phba->hbqs[hbqno].buffer_count + count) >
  1722. lpfc_hbq_defs[hbqno]->entry_count)
  1723. count = lpfc_hbq_defs[hbqno]->entry_count -
  1724. phba->hbqs[hbqno].buffer_count;
  1725. if (!count)
  1726. return 0;
  1727. /* Allocate HBQ entries */
  1728. for (i = 0; i < count; i++) {
  1729. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1730. if (!hbq_buffer)
  1731. break;
  1732. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1733. }
  1734. /* Check whether HBQ is still in use */
  1735. spin_lock_irqsave(&phba->hbalock, flags);
  1736. if (!phba->hbq_in_use)
  1737. goto err;
  1738. while (!list_empty(&hbq_buf_list)) {
  1739. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1740. dbuf.list);
  1741. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1742. (hbqno << 16));
  1743. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1744. phba->hbqs[hbqno].buffer_count++;
  1745. posted++;
  1746. } else
  1747. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1748. }
  1749. spin_unlock_irqrestore(&phba->hbalock, flags);
  1750. return posted;
  1751. err:
  1752. spin_unlock_irqrestore(&phba->hbalock, flags);
  1753. while (!list_empty(&hbq_buf_list)) {
  1754. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1755. dbuf.list);
  1756. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1757. }
  1758. return 0;
  1759. }
  1760. /**
  1761. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1762. * @phba: Pointer to HBA context object.
  1763. * @qno: HBQ number.
  1764. *
  1765. * This function posts more buffers to the HBQ. This function
  1766. * is called with no lock held. The function returns the number of HBQ entries
  1767. * successfully allocated.
  1768. **/
  1769. int
  1770. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1771. {
  1772. if (phba->sli_rev == LPFC_SLI_REV4)
  1773. return 0;
  1774. else
  1775. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1776. lpfc_hbq_defs[qno]->add_count);
  1777. }
  1778. /**
  1779. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1780. * @phba: Pointer to HBA context object.
  1781. * @qno: HBQ queue number.
  1782. *
  1783. * This function is called from SLI initialization code path with
  1784. * no lock held to post initial HBQ buffers to firmware. The
  1785. * function returns the number of HBQ entries successfully allocated.
  1786. **/
  1787. static int
  1788. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1789. {
  1790. if (phba->sli_rev == LPFC_SLI_REV4)
  1791. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1792. lpfc_hbq_defs[qno]->entry_count);
  1793. else
  1794. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1795. lpfc_hbq_defs[qno]->init_count);
  1796. }
  1797. /**
  1798. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1799. * @phba: Pointer to HBA context object.
  1800. * @hbqno: HBQ number.
  1801. *
  1802. * This function removes the first hbq buffer on an hbq list and returns a
  1803. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1804. **/
  1805. static struct hbq_dmabuf *
  1806. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1807. {
  1808. struct lpfc_dmabuf *d_buf;
  1809. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1810. if (!d_buf)
  1811. return NULL;
  1812. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1813. }
  1814. /**
  1815. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1816. * @phba: Pointer to HBA context object.
  1817. * @tag: Tag of the hbq buffer.
  1818. *
  1819. * This function searches for the hbq buffer associated with the given tag in
  1820. * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
  1821. * otherwise it returns NULL.
  1822. **/
  1823. static struct hbq_dmabuf *
  1824. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1825. {
  1826. struct lpfc_dmabuf *d_buf;
  1827. struct hbq_dmabuf *hbq_buf;
  1828. uint32_t hbqno;
  1829. hbqno = tag >> 16;
  1830. if (hbqno >= LPFC_MAX_HBQS)
  1831. return NULL;
  1832. spin_lock_irq(&phba->hbalock);
  1833. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1834. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1835. if (hbq_buf->tag == tag) {
  1836. spin_unlock_irq(&phba->hbalock);
  1837. return hbq_buf;
  1838. }
  1839. }
  1840. spin_unlock_irq(&phba->hbalock);
  1841. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1842. "1803 Bad hbq tag. Data: x%x x%x\n",
  1843. tag, phba->hbqs[tag >> 16].buffer_count);
  1844. return NULL;
  1845. }
  1846. /**
  1847. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1848. * @phba: Pointer to HBA context object.
  1849. * @hbq_buffer: Pointer to HBQ buffer.
  1850. *
  1851. * This function is called with hbalock. This function gives back
  1852. * the hbq buffer to firmware. If the HBQ does not have space to
  1853. * post the buffer, it will free the buffer.
  1854. **/
  1855. void
  1856. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1857. {
  1858. uint32_t hbqno;
  1859. if (hbq_buffer) {
  1860. hbqno = hbq_buffer->tag >> 16;
  1861. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1862. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1863. }
  1864. }
  1865. /**
  1866. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1867. * @mbxCommand: mailbox command code.
  1868. *
  1869. * This function is called by the mailbox event handler function to verify
  1870. * that the completed mailbox command is a legitimate mailbox command. If the
  1871. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1872. * and the mailbox event handler will take the HBA offline.
  1873. **/
  1874. static int
  1875. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1876. {
  1877. uint8_t ret;
  1878. switch (mbxCommand) {
  1879. case MBX_LOAD_SM:
  1880. case MBX_READ_NV:
  1881. case MBX_WRITE_NV:
  1882. case MBX_WRITE_VPARMS:
  1883. case MBX_RUN_BIU_DIAG:
  1884. case MBX_INIT_LINK:
  1885. case MBX_DOWN_LINK:
  1886. case MBX_CONFIG_LINK:
  1887. case MBX_CONFIG_RING:
  1888. case MBX_RESET_RING:
  1889. case MBX_READ_CONFIG:
  1890. case MBX_READ_RCONFIG:
  1891. case MBX_READ_SPARM:
  1892. case MBX_READ_STATUS:
  1893. case MBX_READ_RPI:
  1894. case MBX_READ_XRI:
  1895. case MBX_READ_REV:
  1896. case MBX_READ_LNK_STAT:
  1897. case MBX_REG_LOGIN:
  1898. case MBX_UNREG_LOGIN:
  1899. case MBX_CLEAR_LA:
  1900. case MBX_DUMP_MEMORY:
  1901. case MBX_DUMP_CONTEXT:
  1902. case MBX_RUN_DIAGS:
  1903. case MBX_RESTART:
  1904. case MBX_UPDATE_CFG:
  1905. case MBX_DOWN_LOAD:
  1906. case MBX_DEL_LD_ENTRY:
  1907. case MBX_RUN_PROGRAM:
  1908. case MBX_SET_MASK:
  1909. case MBX_SET_VARIABLE:
  1910. case MBX_UNREG_D_ID:
  1911. case MBX_KILL_BOARD:
  1912. case MBX_CONFIG_FARP:
  1913. case MBX_BEACON:
  1914. case MBX_LOAD_AREA:
  1915. case MBX_RUN_BIU_DIAG64:
  1916. case MBX_CONFIG_PORT:
  1917. case MBX_READ_SPARM64:
  1918. case MBX_READ_RPI64:
  1919. case MBX_REG_LOGIN64:
  1920. case MBX_READ_TOPOLOGY:
  1921. case MBX_WRITE_WWN:
  1922. case MBX_SET_DEBUG:
  1923. case MBX_LOAD_EXP_ROM:
  1924. case MBX_ASYNCEVT_ENABLE:
  1925. case MBX_REG_VPI:
  1926. case MBX_UNREG_VPI:
  1927. case MBX_HEARTBEAT:
  1928. case MBX_PORT_CAPABILITIES:
  1929. case MBX_PORT_IOV_CONTROL:
  1930. case MBX_SLI4_CONFIG:
  1931. case MBX_SLI4_REQ_FTRS:
  1932. case MBX_REG_FCFI:
  1933. case MBX_UNREG_FCFI:
  1934. case MBX_REG_VFI:
  1935. case MBX_UNREG_VFI:
  1936. case MBX_INIT_VPI:
  1937. case MBX_INIT_VFI:
  1938. case MBX_RESUME_RPI:
  1939. case MBX_READ_EVENT_LOG_STATUS:
  1940. case MBX_READ_EVENT_LOG:
  1941. case MBX_SECURITY_MGMT:
  1942. case MBX_AUTH_PORT:
  1943. case MBX_ACCESS_VDATA:
  1944. ret = mbxCommand;
  1945. break;
  1946. default:
  1947. ret = MBX_SHUTDOWN;
  1948. break;
  1949. }
  1950. return ret;
  1951. }
  1952. /**
  1953. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1954. * @phba: Pointer to HBA context object.
  1955. * @pmboxq: Pointer to mailbox command.
  1956. *
  1957. * This is completion handler function for mailbox commands issued from
  1958. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1959. * mailbox event handler function with no lock held. This function
  1960. * will wake up thread waiting on the wait queue pointed by context1
  1961. * of the mailbox.
  1962. **/
  1963. void
  1964. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1965. {
  1966. wait_queue_head_t *pdone_q;
  1967. unsigned long drvr_flag;
  1968. /*
  1969. * If pdone_q is empty, the driver thread gave up waiting and
  1970. * continued running.
  1971. */
  1972. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1973. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1974. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1975. if (pdone_q)
  1976. wake_up_interruptible(pdone_q);
  1977. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1978. return;
  1979. }
  1980. /**
  1981. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1982. * @phba: Pointer to HBA context object.
  1983. * @pmb: Pointer to mailbox object.
  1984. *
  1985. * This function is the default mailbox completion handler. It
  1986. * frees the memory resources associated with the completed mailbox
  1987. * command. If the completed command is a REG_LOGIN mailbox command,
  1988. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1989. **/
  1990. void
  1991. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1992. {
  1993. struct lpfc_vport *vport = pmb->vport;
  1994. struct lpfc_dmabuf *mp;
  1995. struct lpfc_nodelist *ndlp;
  1996. struct Scsi_Host *shost;
  1997. uint16_t rpi, vpi;
  1998. int rc;
  1999. mp = (struct lpfc_dmabuf *) (pmb->context1);
  2000. if (mp) {
  2001. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2002. kfree(mp);
  2003. }
  2004. /*
  2005. * If a REG_LOGIN succeeded after node is destroyed or node
  2006. * is in re-discovery driver need to cleanup the RPI.
  2007. */
  2008. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  2009. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  2010. !pmb->u.mb.mbxStatus) {
  2011. rpi = pmb->u.mb.un.varWords[0];
  2012. vpi = pmb->u.mb.un.varRegLogin.vpi;
  2013. lpfc_unreg_login(phba, vpi, rpi, pmb);
  2014. pmb->vport = vport;
  2015. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2016. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2017. if (rc != MBX_NOT_FINISHED)
  2018. return;
  2019. }
  2020. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  2021. !(phba->pport->load_flag & FC_UNLOADING) &&
  2022. !pmb->u.mb.mbxStatus) {
  2023. shost = lpfc_shost_from_vport(vport);
  2024. spin_lock_irq(shost->host_lock);
  2025. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2026. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2027. spin_unlock_irq(shost->host_lock);
  2028. }
  2029. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  2030. ndlp = (struct lpfc_nodelist *)pmb->context2;
  2031. lpfc_nlp_put(ndlp);
  2032. pmb->context2 = NULL;
  2033. }
  2034. /* Check security permission status on INIT_LINK mailbox command */
  2035. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  2036. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  2037. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2038. "2860 SLI authentication is required "
  2039. "for INIT_LINK but has not done yet\n");
  2040. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  2041. lpfc_sli4_mbox_cmd_free(phba, pmb);
  2042. else
  2043. mempool_free(pmb, phba->mbox_mem_pool);
  2044. }
  2045. /**
  2046. * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
  2047. * @phba: Pointer to HBA context object.
  2048. * @pmb: Pointer to mailbox object.
  2049. *
  2050. * This function is the unreg rpi mailbox completion handler. It
  2051. * frees the memory resources associated with the completed mailbox
  2052. * command. An additional refrenece is put on the ndlp to prevent
  2053. * lpfc_nlp_release from freeing the rpi bit in the bitmask before
  2054. * the unreg mailbox command completes, this routine puts the
  2055. * reference back.
  2056. *
  2057. **/
  2058. void
  2059. lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2060. {
  2061. struct lpfc_vport *vport = pmb->vport;
  2062. struct lpfc_nodelist *ndlp;
  2063. ndlp = pmb->context1;
  2064. if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
  2065. if (phba->sli_rev == LPFC_SLI_REV4 &&
  2066. (bf_get(lpfc_sli_intf_if_type,
  2067. &phba->sli4_hba.sli_intf) ==
  2068. LPFC_SLI_INTF_IF_TYPE_2)) {
  2069. if (ndlp) {
  2070. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  2071. "0010 UNREG_LOGIN vpi:%x "
  2072. "rpi:%x DID:%x map:%x %p\n",
  2073. vport->vpi, ndlp->nlp_rpi,
  2074. ndlp->nlp_DID,
  2075. ndlp->nlp_usg_map, ndlp);
  2076. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2077. lpfc_nlp_put(ndlp);
  2078. }
  2079. }
  2080. }
  2081. mempool_free(pmb, phba->mbox_mem_pool);
  2082. }
  2083. /**
  2084. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2085. * @phba: Pointer to HBA context object.
  2086. *
  2087. * This function is called with no lock held. This function processes all
  2088. * the completed mailbox commands and gives it to upper layers. The interrupt
  2089. * service routine processes mailbox completion interrupt and adds completed
  2090. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2091. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2092. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2093. * function returns the mailbox commands to the upper layer by calling the
  2094. * completion handler function of each mailbox.
  2095. **/
  2096. int
  2097. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2098. {
  2099. MAILBOX_t *pmbox;
  2100. LPFC_MBOXQ_t *pmb;
  2101. int rc;
  2102. LIST_HEAD(cmplq);
  2103. phba->sli.slistat.mbox_event++;
  2104. /* Get all completed mailboxe buffers into the cmplq */
  2105. spin_lock_irq(&phba->hbalock);
  2106. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2107. spin_unlock_irq(&phba->hbalock);
  2108. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2109. do {
  2110. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2111. if (pmb == NULL)
  2112. break;
  2113. pmbox = &pmb->u.mb;
  2114. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2115. if (pmb->vport) {
  2116. lpfc_debugfs_disc_trc(pmb->vport,
  2117. LPFC_DISC_TRC_MBOX_VPORT,
  2118. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2119. (uint32_t)pmbox->mbxCommand,
  2120. pmbox->un.varWords[0],
  2121. pmbox->un.varWords[1]);
  2122. }
  2123. else {
  2124. lpfc_debugfs_disc_trc(phba->pport,
  2125. LPFC_DISC_TRC_MBOX,
  2126. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2127. (uint32_t)pmbox->mbxCommand,
  2128. pmbox->un.varWords[0],
  2129. pmbox->un.varWords[1]);
  2130. }
  2131. }
  2132. /*
  2133. * It is a fatal error if unknown mbox command completion.
  2134. */
  2135. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2136. MBX_SHUTDOWN) {
  2137. /* Unknown mailbox command compl */
  2138. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2139. "(%d):0323 Unknown Mailbox command "
  2140. "x%x (x%x/x%x) Cmpl\n",
  2141. pmb->vport ? pmb->vport->vpi : 0,
  2142. pmbox->mbxCommand,
  2143. lpfc_sli_config_mbox_subsys_get(phba,
  2144. pmb),
  2145. lpfc_sli_config_mbox_opcode_get(phba,
  2146. pmb));
  2147. phba->link_state = LPFC_HBA_ERROR;
  2148. phba->work_hs = HS_FFER3;
  2149. lpfc_handle_eratt(phba);
  2150. continue;
  2151. }
  2152. if (pmbox->mbxStatus) {
  2153. phba->sli.slistat.mbox_stat_err++;
  2154. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2155. /* Mbox cmd cmpl error - RETRYing */
  2156. lpfc_printf_log(phba, KERN_INFO,
  2157. LOG_MBOX | LOG_SLI,
  2158. "(%d):0305 Mbox cmd cmpl "
  2159. "error - RETRYing Data: x%x "
  2160. "(x%x/x%x) x%x x%x x%x\n",
  2161. pmb->vport ? pmb->vport->vpi : 0,
  2162. pmbox->mbxCommand,
  2163. lpfc_sli_config_mbox_subsys_get(phba,
  2164. pmb),
  2165. lpfc_sli_config_mbox_opcode_get(phba,
  2166. pmb),
  2167. pmbox->mbxStatus,
  2168. pmbox->un.varWords[0],
  2169. pmb->vport->port_state);
  2170. pmbox->mbxStatus = 0;
  2171. pmbox->mbxOwner = OWN_HOST;
  2172. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2173. if (rc != MBX_NOT_FINISHED)
  2174. continue;
  2175. }
  2176. }
  2177. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2178. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2179. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2180. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  2181. "x%x x%x x%x\n",
  2182. pmb->vport ? pmb->vport->vpi : 0,
  2183. pmbox->mbxCommand,
  2184. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2185. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2186. pmb->mbox_cmpl,
  2187. *((uint32_t *) pmbox),
  2188. pmbox->un.varWords[0],
  2189. pmbox->un.varWords[1],
  2190. pmbox->un.varWords[2],
  2191. pmbox->un.varWords[3],
  2192. pmbox->un.varWords[4],
  2193. pmbox->un.varWords[5],
  2194. pmbox->un.varWords[6],
  2195. pmbox->un.varWords[7],
  2196. pmbox->un.varWords[8],
  2197. pmbox->un.varWords[9],
  2198. pmbox->un.varWords[10]);
  2199. if (pmb->mbox_cmpl)
  2200. pmb->mbox_cmpl(phba,pmb);
  2201. } while (1);
  2202. return 0;
  2203. }
  2204. /**
  2205. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2206. * @phba: Pointer to HBA context object.
  2207. * @pring: Pointer to driver SLI ring object.
  2208. * @tag: buffer tag.
  2209. *
  2210. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2211. * is set in the tag the buffer is posted for a particular exchange,
  2212. * the function will return the buffer without replacing the buffer.
  2213. * If the buffer is for unsolicited ELS or CT traffic, this function
  2214. * returns the buffer and also posts another buffer to the firmware.
  2215. **/
  2216. static struct lpfc_dmabuf *
  2217. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2218. struct lpfc_sli_ring *pring,
  2219. uint32_t tag)
  2220. {
  2221. struct hbq_dmabuf *hbq_entry;
  2222. if (tag & QUE_BUFTAG_BIT)
  2223. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2224. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2225. if (!hbq_entry)
  2226. return NULL;
  2227. return &hbq_entry->dbuf;
  2228. }
  2229. /**
  2230. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2231. * @phba: Pointer to HBA context object.
  2232. * @pring: Pointer to driver SLI ring object.
  2233. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2234. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2235. * @fch_type: the type for the first frame of the sequence.
  2236. *
  2237. * This function is called with no lock held. This function uses the r_ctl and
  2238. * type of the received sequence to find the correct callback function to call
  2239. * to process the sequence.
  2240. **/
  2241. static int
  2242. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2243. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2244. uint32_t fch_type)
  2245. {
  2246. int i;
  2247. /* unSolicited Responses */
  2248. if (pring->prt[0].profile) {
  2249. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2250. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2251. saveq);
  2252. return 1;
  2253. }
  2254. /* We must search, based on rctl / type
  2255. for the right routine */
  2256. for (i = 0; i < pring->num_mask; i++) {
  2257. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2258. (pring->prt[i].type == fch_type)) {
  2259. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2260. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2261. (phba, pring, saveq);
  2262. return 1;
  2263. }
  2264. }
  2265. return 0;
  2266. }
  2267. /**
  2268. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2269. * @phba: Pointer to HBA context object.
  2270. * @pring: Pointer to driver SLI ring object.
  2271. * @saveq: Pointer to the unsolicited iocb.
  2272. *
  2273. * This function is called with no lock held by the ring event handler
  2274. * when there is an unsolicited iocb posted to the response ring by the
  2275. * firmware. This function gets the buffer associated with the iocbs
  2276. * and calls the event handler for the ring. This function handles both
  2277. * qring buffers and hbq buffers.
  2278. * When the function returns 1 the caller can free the iocb object otherwise
  2279. * upper layer functions will free the iocb objects.
  2280. **/
  2281. static int
  2282. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2283. struct lpfc_iocbq *saveq)
  2284. {
  2285. IOCB_t * irsp;
  2286. WORD5 * w5p;
  2287. uint32_t Rctl, Type;
  2288. struct lpfc_iocbq *iocbq;
  2289. struct lpfc_dmabuf *dmzbuf;
  2290. irsp = &(saveq->iocb);
  2291. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2292. if (pring->lpfc_sli_rcv_async_status)
  2293. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2294. else
  2295. lpfc_printf_log(phba,
  2296. KERN_WARNING,
  2297. LOG_SLI,
  2298. "0316 Ring %d handler: unexpected "
  2299. "ASYNC_STATUS iocb received evt_code "
  2300. "0x%x\n",
  2301. pring->ringno,
  2302. irsp->un.asyncstat.evt_code);
  2303. return 1;
  2304. }
  2305. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2306. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2307. if (irsp->ulpBdeCount > 0) {
  2308. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2309. irsp->un.ulpWord[3]);
  2310. lpfc_in_buf_free(phba, dmzbuf);
  2311. }
  2312. if (irsp->ulpBdeCount > 1) {
  2313. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2314. irsp->unsli3.sli3Words[3]);
  2315. lpfc_in_buf_free(phba, dmzbuf);
  2316. }
  2317. if (irsp->ulpBdeCount > 2) {
  2318. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2319. irsp->unsli3.sli3Words[7]);
  2320. lpfc_in_buf_free(phba, dmzbuf);
  2321. }
  2322. return 1;
  2323. }
  2324. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2325. if (irsp->ulpBdeCount != 0) {
  2326. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2327. irsp->un.ulpWord[3]);
  2328. if (!saveq->context2)
  2329. lpfc_printf_log(phba,
  2330. KERN_ERR,
  2331. LOG_SLI,
  2332. "0341 Ring %d Cannot find buffer for "
  2333. "an unsolicited iocb. tag 0x%x\n",
  2334. pring->ringno,
  2335. irsp->un.ulpWord[3]);
  2336. }
  2337. if (irsp->ulpBdeCount == 2) {
  2338. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2339. irsp->unsli3.sli3Words[7]);
  2340. if (!saveq->context3)
  2341. lpfc_printf_log(phba,
  2342. KERN_ERR,
  2343. LOG_SLI,
  2344. "0342 Ring %d Cannot find buffer for an"
  2345. " unsolicited iocb. tag 0x%x\n",
  2346. pring->ringno,
  2347. irsp->unsli3.sli3Words[7]);
  2348. }
  2349. list_for_each_entry(iocbq, &saveq->list, list) {
  2350. irsp = &(iocbq->iocb);
  2351. if (irsp->ulpBdeCount != 0) {
  2352. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2353. irsp->un.ulpWord[3]);
  2354. if (!iocbq->context2)
  2355. lpfc_printf_log(phba,
  2356. KERN_ERR,
  2357. LOG_SLI,
  2358. "0343 Ring %d Cannot find "
  2359. "buffer for an unsolicited iocb"
  2360. ". tag 0x%x\n", pring->ringno,
  2361. irsp->un.ulpWord[3]);
  2362. }
  2363. if (irsp->ulpBdeCount == 2) {
  2364. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2365. irsp->unsli3.sli3Words[7]);
  2366. if (!iocbq->context3)
  2367. lpfc_printf_log(phba,
  2368. KERN_ERR,
  2369. LOG_SLI,
  2370. "0344 Ring %d Cannot find "
  2371. "buffer for an unsolicited "
  2372. "iocb. tag 0x%x\n",
  2373. pring->ringno,
  2374. irsp->unsli3.sli3Words[7]);
  2375. }
  2376. }
  2377. }
  2378. if (irsp->ulpBdeCount != 0 &&
  2379. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2380. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2381. int found = 0;
  2382. /* search continue save q for same XRI */
  2383. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2384. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2385. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2386. list_add_tail(&saveq->list, &iocbq->list);
  2387. found = 1;
  2388. break;
  2389. }
  2390. }
  2391. if (!found)
  2392. list_add_tail(&saveq->clist,
  2393. &pring->iocb_continue_saveq);
  2394. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2395. list_del_init(&iocbq->clist);
  2396. saveq = iocbq;
  2397. irsp = &(saveq->iocb);
  2398. } else
  2399. return 0;
  2400. }
  2401. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2402. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2403. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2404. Rctl = FC_RCTL_ELS_REQ;
  2405. Type = FC_TYPE_ELS;
  2406. } else {
  2407. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2408. Rctl = w5p->hcsw.Rctl;
  2409. Type = w5p->hcsw.Type;
  2410. /* Firmware Workaround */
  2411. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2412. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2413. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2414. Rctl = FC_RCTL_ELS_REQ;
  2415. Type = FC_TYPE_ELS;
  2416. w5p->hcsw.Rctl = Rctl;
  2417. w5p->hcsw.Type = Type;
  2418. }
  2419. }
  2420. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2421. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2422. "0313 Ring %d handler: unexpected Rctl x%x "
  2423. "Type x%x received\n",
  2424. pring->ringno, Rctl, Type);
  2425. return 1;
  2426. }
  2427. /**
  2428. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2429. * @phba: Pointer to HBA context object.
  2430. * @pring: Pointer to driver SLI ring object.
  2431. * @prspiocb: Pointer to response iocb object.
  2432. *
  2433. * This function looks up the iocb_lookup table to get the command iocb
  2434. * corresponding to the given response iocb using the iotag of the
  2435. * response iocb. This function is called with the hbalock held.
  2436. * This function returns the command iocb object if it finds the command
  2437. * iocb else returns NULL.
  2438. **/
  2439. static struct lpfc_iocbq *
  2440. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2441. struct lpfc_sli_ring *pring,
  2442. struct lpfc_iocbq *prspiocb)
  2443. {
  2444. struct lpfc_iocbq *cmd_iocb = NULL;
  2445. uint16_t iotag;
  2446. lockdep_assert_held(&phba->hbalock);
  2447. iotag = prspiocb->iocb.ulpIoTag;
  2448. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2449. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2450. list_del_init(&cmd_iocb->list);
  2451. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2452. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2453. }
  2454. return cmd_iocb;
  2455. }
  2456. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2457. "0317 iotag x%x is out off "
  2458. "range: max iotag x%x wd0 x%x\n",
  2459. iotag, phba->sli.last_iotag,
  2460. *(((uint32_t *) &prspiocb->iocb) + 7));
  2461. return NULL;
  2462. }
  2463. /**
  2464. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2465. * @phba: Pointer to HBA context object.
  2466. * @pring: Pointer to driver SLI ring object.
  2467. * @iotag: IOCB tag.
  2468. *
  2469. * This function looks up the iocb_lookup table to get the command iocb
  2470. * corresponding to the given iotag. This function is called with the
  2471. * hbalock held.
  2472. * This function returns the command iocb object if it finds the command
  2473. * iocb else returns NULL.
  2474. **/
  2475. static struct lpfc_iocbq *
  2476. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2477. struct lpfc_sli_ring *pring, uint16_t iotag)
  2478. {
  2479. struct lpfc_iocbq *cmd_iocb;
  2480. lockdep_assert_held(&phba->hbalock);
  2481. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2482. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2483. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2484. /* remove from txcmpl queue list */
  2485. list_del_init(&cmd_iocb->list);
  2486. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2487. return cmd_iocb;
  2488. }
  2489. }
  2490. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2491. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2492. iotag, phba->sli.last_iotag);
  2493. return NULL;
  2494. }
  2495. /**
  2496. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2497. * @phba: Pointer to HBA context object.
  2498. * @pring: Pointer to driver SLI ring object.
  2499. * @saveq: Pointer to the response iocb to be processed.
  2500. *
  2501. * This function is called by the ring event handler for non-fcp
  2502. * rings when there is a new response iocb in the response ring.
  2503. * The caller is not required to hold any locks. This function
  2504. * gets the command iocb associated with the response iocb and
  2505. * calls the completion handler for the command iocb. If there
  2506. * is no completion handler, the function will free the resources
  2507. * associated with command iocb. If the response iocb is for
  2508. * an already aborted command iocb, the status of the completion
  2509. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2510. * This function always returns 1.
  2511. **/
  2512. static int
  2513. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2514. struct lpfc_iocbq *saveq)
  2515. {
  2516. struct lpfc_iocbq *cmdiocbp;
  2517. int rc = 1;
  2518. unsigned long iflag;
  2519. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2520. spin_lock_irqsave(&phba->hbalock, iflag);
  2521. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2522. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2523. if (cmdiocbp) {
  2524. if (cmdiocbp->iocb_cmpl) {
  2525. /*
  2526. * If an ELS command failed send an event to mgmt
  2527. * application.
  2528. */
  2529. if (saveq->iocb.ulpStatus &&
  2530. (pring->ringno == LPFC_ELS_RING) &&
  2531. (cmdiocbp->iocb.ulpCommand ==
  2532. CMD_ELS_REQUEST64_CR))
  2533. lpfc_send_els_failure_event(phba,
  2534. cmdiocbp, saveq);
  2535. /*
  2536. * Post all ELS completions to the worker thread.
  2537. * All other are passed to the completion callback.
  2538. */
  2539. if (pring->ringno == LPFC_ELS_RING) {
  2540. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2541. (cmdiocbp->iocb_flag &
  2542. LPFC_DRIVER_ABORTED)) {
  2543. spin_lock_irqsave(&phba->hbalock,
  2544. iflag);
  2545. cmdiocbp->iocb_flag &=
  2546. ~LPFC_DRIVER_ABORTED;
  2547. spin_unlock_irqrestore(&phba->hbalock,
  2548. iflag);
  2549. saveq->iocb.ulpStatus =
  2550. IOSTAT_LOCAL_REJECT;
  2551. saveq->iocb.un.ulpWord[4] =
  2552. IOERR_SLI_ABORTED;
  2553. /* Firmware could still be in progress
  2554. * of DMAing payload, so don't free data
  2555. * buffer till after a hbeat.
  2556. */
  2557. spin_lock_irqsave(&phba->hbalock,
  2558. iflag);
  2559. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2560. spin_unlock_irqrestore(&phba->hbalock,
  2561. iflag);
  2562. }
  2563. if (phba->sli_rev == LPFC_SLI_REV4) {
  2564. if (saveq->iocb_flag &
  2565. LPFC_EXCHANGE_BUSY) {
  2566. /* Set cmdiocb flag for the
  2567. * exchange busy so sgl (xri)
  2568. * will not be released until
  2569. * the abort xri is received
  2570. * from hba.
  2571. */
  2572. spin_lock_irqsave(
  2573. &phba->hbalock, iflag);
  2574. cmdiocbp->iocb_flag |=
  2575. LPFC_EXCHANGE_BUSY;
  2576. spin_unlock_irqrestore(
  2577. &phba->hbalock, iflag);
  2578. }
  2579. if (cmdiocbp->iocb_flag &
  2580. LPFC_DRIVER_ABORTED) {
  2581. /*
  2582. * Clear LPFC_DRIVER_ABORTED
  2583. * bit in case it was driver
  2584. * initiated abort.
  2585. */
  2586. spin_lock_irqsave(
  2587. &phba->hbalock, iflag);
  2588. cmdiocbp->iocb_flag &=
  2589. ~LPFC_DRIVER_ABORTED;
  2590. spin_unlock_irqrestore(
  2591. &phba->hbalock, iflag);
  2592. cmdiocbp->iocb.ulpStatus =
  2593. IOSTAT_LOCAL_REJECT;
  2594. cmdiocbp->iocb.un.ulpWord[4] =
  2595. IOERR_ABORT_REQUESTED;
  2596. /*
  2597. * For SLI4, irsiocb contains
  2598. * NO_XRI in sli_xritag, it
  2599. * shall not affect releasing
  2600. * sgl (xri) process.
  2601. */
  2602. saveq->iocb.ulpStatus =
  2603. IOSTAT_LOCAL_REJECT;
  2604. saveq->iocb.un.ulpWord[4] =
  2605. IOERR_SLI_ABORTED;
  2606. spin_lock_irqsave(
  2607. &phba->hbalock, iflag);
  2608. saveq->iocb_flag |=
  2609. LPFC_DELAY_MEM_FREE;
  2610. spin_unlock_irqrestore(
  2611. &phba->hbalock, iflag);
  2612. }
  2613. }
  2614. }
  2615. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2616. } else
  2617. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2618. } else {
  2619. /*
  2620. * Unknown initiating command based on the response iotag.
  2621. * This could be the case on the ELS ring because of
  2622. * lpfc_els_abort().
  2623. */
  2624. if (pring->ringno != LPFC_ELS_RING) {
  2625. /*
  2626. * Ring <ringno> handler: unexpected completion IoTag
  2627. * <IoTag>
  2628. */
  2629. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2630. "0322 Ring %d handler: "
  2631. "unexpected completion IoTag x%x "
  2632. "Data: x%x x%x x%x x%x\n",
  2633. pring->ringno,
  2634. saveq->iocb.ulpIoTag,
  2635. saveq->iocb.ulpStatus,
  2636. saveq->iocb.un.ulpWord[4],
  2637. saveq->iocb.ulpCommand,
  2638. saveq->iocb.ulpContext);
  2639. }
  2640. }
  2641. return rc;
  2642. }
  2643. /**
  2644. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2645. * @phba: Pointer to HBA context object.
  2646. * @pring: Pointer to driver SLI ring object.
  2647. *
  2648. * This function is called from the iocb ring event handlers when
  2649. * put pointer is ahead of the get pointer for a ring. This function signal
  2650. * an error attention condition to the worker thread and the worker
  2651. * thread will transition the HBA to offline state.
  2652. **/
  2653. static void
  2654. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2655. {
  2656. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2657. /*
  2658. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2659. * rsp ring <portRspMax>
  2660. */
  2661. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2662. "0312 Ring %d handler: portRspPut %d "
  2663. "is bigger than rsp ring %d\n",
  2664. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2665. pring->sli.sli3.numRiocb);
  2666. phba->link_state = LPFC_HBA_ERROR;
  2667. /*
  2668. * All error attention handlers are posted to
  2669. * worker thread
  2670. */
  2671. phba->work_ha |= HA_ERATT;
  2672. phba->work_hs = HS_FFER3;
  2673. lpfc_worker_wake_up(phba);
  2674. return;
  2675. }
  2676. /**
  2677. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2678. * @ptr: Pointer to address of HBA context object.
  2679. *
  2680. * This function is invoked by the Error Attention polling timer when the
  2681. * timer times out. It will check the SLI Error Attention register for
  2682. * possible attention events. If so, it will post an Error Attention event
  2683. * and wake up worker thread to process it. Otherwise, it will set up the
  2684. * Error Attention polling timer for the next poll.
  2685. **/
  2686. void lpfc_poll_eratt(unsigned long ptr)
  2687. {
  2688. struct lpfc_hba *phba;
  2689. uint32_t eratt = 0;
  2690. uint64_t sli_intr, cnt;
  2691. phba = (struct lpfc_hba *)ptr;
  2692. /* Here we will also keep track of interrupts per sec of the hba */
  2693. sli_intr = phba->sli.slistat.sli_intr;
  2694. if (phba->sli.slistat.sli_prev_intr > sli_intr)
  2695. cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
  2696. sli_intr);
  2697. else
  2698. cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
  2699. /* 64-bit integer division not supported on 32-bit x86 - use do_div */
  2700. do_div(cnt, phba->eratt_poll_interval);
  2701. phba->sli.slistat.sli_ips = cnt;
  2702. phba->sli.slistat.sli_prev_intr = sli_intr;
  2703. /* Check chip HA register for error event */
  2704. eratt = lpfc_sli_check_eratt(phba);
  2705. if (eratt)
  2706. /* Tell the worker thread there is work to do */
  2707. lpfc_worker_wake_up(phba);
  2708. else
  2709. /* Restart the timer for next eratt poll */
  2710. mod_timer(&phba->eratt_poll,
  2711. jiffies +
  2712. msecs_to_jiffies(1000 * phba->eratt_poll_interval));
  2713. return;
  2714. }
  2715. /**
  2716. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2717. * @phba: Pointer to HBA context object.
  2718. * @pring: Pointer to driver SLI ring object.
  2719. * @mask: Host attention register mask for this ring.
  2720. *
  2721. * This function is called from the interrupt context when there is a ring
  2722. * event for the fcp ring. The caller does not hold any lock.
  2723. * The function processes each response iocb in the response ring until it
  2724. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2725. * LE bit set. The function will call the completion handler of the command iocb
  2726. * if the response iocb indicates a completion for a command iocb or it is
  2727. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2728. * function if this is an unsolicited iocb.
  2729. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2730. * to check it explicitly.
  2731. */
  2732. int
  2733. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2734. struct lpfc_sli_ring *pring, uint32_t mask)
  2735. {
  2736. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2737. IOCB_t *irsp = NULL;
  2738. IOCB_t *entry = NULL;
  2739. struct lpfc_iocbq *cmdiocbq = NULL;
  2740. struct lpfc_iocbq rspiocbq;
  2741. uint32_t status;
  2742. uint32_t portRspPut, portRspMax;
  2743. int rc = 1;
  2744. lpfc_iocb_type type;
  2745. unsigned long iflag;
  2746. uint32_t rsp_cmpl = 0;
  2747. spin_lock_irqsave(&phba->hbalock, iflag);
  2748. pring->stats.iocb_event++;
  2749. /*
  2750. * The next available response entry should never exceed the maximum
  2751. * entries. If it does, treat it as an adapter hardware error.
  2752. */
  2753. portRspMax = pring->sli.sli3.numRiocb;
  2754. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2755. if (unlikely(portRspPut >= portRspMax)) {
  2756. lpfc_sli_rsp_pointers_error(phba, pring);
  2757. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2758. return 1;
  2759. }
  2760. if (phba->fcp_ring_in_use) {
  2761. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2762. return 1;
  2763. } else
  2764. phba->fcp_ring_in_use = 1;
  2765. rmb();
  2766. while (pring->sli.sli3.rspidx != portRspPut) {
  2767. /*
  2768. * Fetch an entry off the ring and copy it into a local data
  2769. * structure. The copy involves a byte-swap since the
  2770. * network byte order and pci byte orders are different.
  2771. */
  2772. entry = lpfc_resp_iocb(phba, pring);
  2773. phba->last_completion_time = jiffies;
  2774. if (++pring->sli.sli3.rspidx >= portRspMax)
  2775. pring->sli.sli3.rspidx = 0;
  2776. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2777. (uint32_t *) &rspiocbq.iocb,
  2778. phba->iocb_rsp_size);
  2779. INIT_LIST_HEAD(&(rspiocbq.list));
  2780. irsp = &rspiocbq.iocb;
  2781. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2782. pring->stats.iocb_rsp++;
  2783. rsp_cmpl++;
  2784. if (unlikely(irsp->ulpStatus)) {
  2785. /*
  2786. * If resource errors reported from HBA, reduce
  2787. * queuedepths of the SCSI device.
  2788. */
  2789. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2790. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2791. IOERR_NO_RESOURCES)) {
  2792. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2793. phba->lpfc_rampdown_queue_depth(phba);
  2794. spin_lock_irqsave(&phba->hbalock, iflag);
  2795. }
  2796. /* Rsp ring <ringno> error: IOCB */
  2797. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2798. "0336 Rsp Ring %d error: IOCB Data: "
  2799. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2800. pring->ringno,
  2801. irsp->un.ulpWord[0],
  2802. irsp->un.ulpWord[1],
  2803. irsp->un.ulpWord[2],
  2804. irsp->un.ulpWord[3],
  2805. irsp->un.ulpWord[4],
  2806. irsp->un.ulpWord[5],
  2807. *(uint32_t *)&irsp->un1,
  2808. *((uint32_t *)&irsp->un1 + 1));
  2809. }
  2810. switch (type) {
  2811. case LPFC_ABORT_IOCB:
  2812. case LPFC_SOL_IOCB:
  2813. /*
  2814. * Idle exchange closed via ABTS from port. No iocb
  2815. * resources need to be recovered.
  2816. */
  2817. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2818. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2819. "0333 IOCB cmd 0x%x"
  2820. " processed. Skipping"
  2821. " completion\n",
  2822. irsp->ulpCommand);
  2823. break;
  2824. }
  2825. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2826. &rspiocbq);
  2827. if (unlikely(!cmdiocbq))
  2828. break;
  2829. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2830. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2831. if (cmdiocbq->iocb_cmpl) {
  2832. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2833. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2834. &rspiocbq);
  2835. spin_lock_irqsave(&phba->hbalock, iflag);
  2836. }
  2837. break;
  2838. case LPFC_UNSOL_IOCB:
  2839. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2840. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2841. spin_lock_irqsave(&phba->hbalock, iflag);
  2842. break;
  2843. default:
  2844. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2845. char adaptermsg[LPFC_MAX_ADPTMSG];
  2846. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2847. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2848. MAX_MSG_DATA);
  2849. dev_warn(&((phba->pcidev)->dev),
  2850. "lpfc%d: %s\n",
  2851. phba->brd_no, adaptermsg);
  2852. } else {
  2853. /* Unknown IOCB command */
  2854. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2855. "0334 Unknown IOCB command "
  2856. "Data: x%x, x%x x%x x%x x%x\n",
  2857. type, irsp->ulpCommand,
  2858. irsp->ulpStatus,
  2859. irsp->ulpIoTag,
  2860. irsp->ulpContext);
  2861. }
  2862. break;
  2863. }
  2864. /*
  2865. * The response IOCB has been processed. Update the ring
  2866. * pointer in SLIM. If the port response put pointer has not
  2867. * been updated, sync the pgp->rspPutInx and fetch the new port
  2868. * response put pointer.
  2869. */
  2870. writel(pring->sli.sli3.rspidx,
  2871. &phba->host_gp[pring->ringno].rspGetInx);
  2872. if (pring->sli.sli3.rspidx == portRspPut)
  2873. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2874. }
  2875. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2876. pring->stats.iocb_rsp_full++;
  2877. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2878. writel(status, phba->CAregaddr);
  2879. readl(phba->CAregaddr);
  2880. }
  2881. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2882. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2883. pring->stats.iocb_cmd_empty++;
  2884. /* Force update of the local copy of cmdGetInx */
  2885. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2886. lpfc_sli_resume_iocb(phba, pring);
  2887. if ((pring->lpfc_sli_cmd_available))
  2888. (pring->lpfc_sli_cmd_available) (phba, pring);
  2889. }
  2890. phba->fcp_ring_in_use = 0;
  2891. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2892. return rc;
  2893. }
  2894. /**
  2895. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2896. * @phba: Pointer to HBA context object.
  2897. * @pring: Pointer to driver SLI ring object.
  2898. * @rspiocbp: Pointer to driver response IOCB object.
  2899. *
  2900. * This function is called from the worker thread when there is a slow-path
  2901. * response IOCB to process. This function chains all the response iocbs until
  2902. * seeing the iocb with the LE bit set. The function will call
  2903. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2904. * completion of a command iocb. The function will call the
  2905. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2906. * The function frees the resources or calls the completion handler if this
  2907. * iocb is an abort completion. The function returns NULL when the response
  2908. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2909. * this function shall chain the iocb on to the iocb_continueq and return the
  2910. * response iocb passed in.
  2911. **/
  2912. static struct lpfc_iocbq *
  2913. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2914. struct lpfc_iocbq *rspiocbp)
  2915. {
  2916. struct lpfc_iocbq *saveq;
  2917. struct lpfc_iocbq *cmdiocbp;
  2918. struct lpfc_iocbq *next_iocb;
  2919. IOCB_t *irsp = NULL;
  2920. uint32_t free_saveq;
  2921. uint8_t iocb_cmd_type;
  2922. lpfc_iocb_type type;
  2923. unsigned long iflag;
  2924. int rc;
  2925. spin_lock_irqsave(&phba->hbalock, iflag);
  2926. /* First add the response iocb to the countinueq list */
  2927. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2928. pring->iocb_continueq_cnt++;
  2929. /* Now, determine whether the list is completed for processing */
  2930. irsp = &rspiocbp->iocb;
  2931. if (irsp->ulpLe) {
  2932. /*
  2933. * By default, the driver expects to free all resources
  2934. * associated with this iocb completion.
  2935. */
  2936. free_saveq = 1;
  2937. saveq = list_get_first(&pring->iocb_continueq,
  2938. struct lpfc_iocbq, list);
  2939. irsp = &(saveq->iocb);
  2940. list_del_init(&pring->iocb_continueq);
  2941. pring->iocb_continueq_cnt = 0;
  2942. pring->stats.iocb_rsp++;
  2943. /*
  2944. * If resource errors reported from HBA, reduce
  2945. * queuedepths of the SCSI device.
  2946. */
  2947. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2948. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2949. IOERR_NO_RESOURCES)) {
  2950. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2951. phba->lpfc_rampdown_queue_depth(phba);
  2952. spin_lock_irqsave(&phba->hbalock, iflag);
  2953. }
  2954. if (irsp->ulpStatus) {
  2955. /* Rsp ring <ringno> error: IOCB */
  2956. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2957. "0328 Rsp Ring %d error: "
  2958. "IOCB Data: "
  2959. "x%x x%x x%x x%x "
  2960. "x%x x%x x%x x%x "
  2961. "x%x x%x x%x x%x "
  2962. "x%x x%x x%x x%x\n",
  2963. pring->ringno,
  2964. irsp->un.ulpWord[0],
  2965. irsp->un.ulpWord[1],
  2966. irsp->un.ulpWord[2],
  2967. irsp->un.ulpWord[3],
  2968. irsp->un.ulpWord[4],
  2969. irsp->un.ulpWord[5],
  2970. *(((uint32_t *) irsp) + 6),
  2971. *(((uint32_t *) irsp) + 7),
  2972. *(((uint32_t *) irsp) + 8),
  2973. *(((uint32_t *) irsp) + 9),
  2974. *(((uint32_t *) irsp) + 10),
  2975. *(((uint32_t *) irsp) + 11),
  2976. *(((uint32_t *) irsp) + 12),
  2977. *(((uint32_t *) irsp) + 13),
  2978. *(((uint32_t *) irsp) + 14),
  2979. *(((uint32_t *) irsp) + 15));
  2980. }
  2981. /*
  2982. * Fetch the IOCB command type and call the correct completion
  2983. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2984. * get freed back to the lpfc_iocb_list by the discovery
  2985. * kernel thread.
  2986. */
  2987. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2988. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2989. switch (type) {
  2990. case LPFC_SOL_IOCB:
  2991. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2992. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2993. spin_lock_irqsave(&phba->hbalock, iflag);
  2994. break;
  2995. case LPFC_UNSOL_IOCB:
  2996. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2997. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2998. spin_lock_irqsave(&phba->hbalock, iflag);
  2999. if (!rc)
  3000. free_saveq = 0;
  3001. break;
  3002. case LPFC_ABORT_IOCB:
  3003. cmdiocbp = NULL;
  3004. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  3005. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  3006. saveq);
  3007. if (cmdiocbp) {
  3008. /* Call the specified completion routine */
  3009. if (cmdiocbp->iocb_cmpl) {
  3010. spin_unlock_irqrestore(&phba->hbalock,
  3011. iflag);
  3012. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  3013. saveq);
  3014. spin_lock_irqsave(&phba->hbalock,
  3015. iflag);
  3016. } else
  3017. __lpfc_sli_release_iocbq(phba,
  3018. cmdiocbp);
  3019. }
  3020. break;
  3021. case LPFC_UNKNOWN_IOCB:
  3022. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  3023. char adaptermsg[LPFC_MAX_ADPTMSG];
  3024. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  3025. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  3026. MAX_MSG_DATA);
  3027. dev_warn(&((phba->pcidev)->dev),
  3028. "lpfc%d: %s\n",
  3029. phba->brd_no, adaptermsg);
  3030. } else {
  3031. /* Unknown IOCB command */
  3032. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3033. "0335 Unknown IOCB "
  3034. "command Data: x%x "
  3035. "x%x x%x x%x\n",
  3036. irsp->ulpCommand,
  3037. irsp->ulpStatus,
  3038. irsp->ulpIoTag,
  3039. irsp->ulpContext);
  3040. }
  3041. break;
  3042. }
  3043. if (free_saveq) {
  3044. list_for_each_entry_safe(rspiocbp, next_iocb,
  3045. &saveq->list, list) {
  3046. list_del_init(&rspiocbp->list);
  3047. __lpfc_sli_release_iocbq(phba, rspiocbp);
  3048. }
  3049. __lpfc_sli_release_iocbq(phba, saveq);
  3050. }
  3051. rspiocbp = NULL;
  3052. }
  3053. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3054. return rspiocbp;
  3055. }
  3056. /**
  3057. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  3058. * @phba: Pointer to HBA context object.
  3059. * @pring: Pointer to driver SLI ring object.
  3060. * @mask: Host attention register mask for this ring.
  3061. *
  3062. * This routine wraps the actual slow_ring event process routine from the
  3063. * API jump table function pointer from the lpfc_hba struct.
  3064. **/
  3065. void
  3066. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  3067. struct lpfc_sli_ring *pring, uint32_t mask)
  3068. {
  3069. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  3070. }
  3071. /**
  3072. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  3073. * @phba: Pointer to HBA context object.
  3074. * @pring: Pointer to driver SLI ring object.
  3075. * @mask: Host attention register mask for this ring.
  3076. *
  3077. * This function is called from the worker thread when there is a ring event
  3078. * for non-fcp rings. The caller does not hold any lock. The function will
  3079. * remove each response iocb in the response ring and calls the handle
  3080. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3081. **/
  3082. static void
  3083. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  3084. struct lpfc_sli_ring *pring, uint32_t mask)
  3085. {
  3086. struct lpfc_pgp *pgp;
  3087. IOCB_t *entry;
  3088. IOCB_t *irsp = NULL;
  3089. struct lpfc_iocbq *rspiocbp = NULL;
  3090. uint32_t portRspPut, portRspMax;
  3091. unsigned long iflag;
  3092. uint32_t status;
  3093. pgp = &phba->port_gp[pring->ringno];
  3094. spin_lock_irqsave(&phba->hbalock, iflag);
  3095. pring->stats.iocb_event++;
  3096. /*
  3097. * The next available response entry should never exceed the maximum
  3098. * entries. If it does, treat it as an adapter hardware error.
  3099. */
  3100. portRspMax = pring->sli.sli3.numRiocb;
  3101. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3102. if (portRspPut >= portRspMax) {
  3103. /*
  3104. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3105. * rsp ring <portRspMax>
  3106. */
  3107. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3108. "0303 Ring %d handler: portRspPut %d "
  3109. "is bigger than rsp ring %d\n",
  3110. pring->ringno, portRspPut, portRspMax);
  3111. phba->link_state = LPFC_HBA_ERROR;
  3112. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3113. phba->work_hs = HS_FFER3;
  3114. lpfc_handle_eratt(phba);
  3115. return;
  3116. }
  3117. rmb();
  3118. while (pring->sli.sli3.rspidx != portRspPut) {
  3119. /*
  3120. * Build a completion list and call the appropriate handler.
  3121. * The process is to get the next available response iocb, get
  3122. * a free iocb from the list, copy the response data into the
  3123. * free iocb, insert to the continuation list, and update the
  3124. * next response index to slim. This process makes response
  3125. * iocb's in the ring available to DMA as fast as possible but
  3126. * pays a penalty for a copy operation. Since the iocb is
  3127. * only 32 bytes, this penalty is considered small relative to
  3128. * the PCI reads for register values and a slim write. When
  3129. * the ulpLe field is set, the entire Command has been
  3130. * received.
  3131. */
  3132. entry = lpfc_resp_iocb(phba, pring);
  3133. phba->last_completion_time = jiffies;
  3134. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3135. if (rspiocbp == NULL) {
  3136. printk(KERN_ERR "%s: out of buffers! Failing "
  3137. "completion.\n", __func__);
  3138. break;
  3139. }
  3140. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3141. phba->iocb_rsp_size);
  3142. irsp = &rspiocbp->iocb;
  3143. if (++pring->sli.sli3.rspidx >= portRspMax)
  3144. pring->sli.sli3.rspidx = 0;
  3145. if (pring->ringno == LPFC_ELS_RING) {
  3146. lpfc_debugfs_slow_ring_trc(phba,
  3147. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3148. *(((uint32_t *) irsp) + 4),
  3149. *(((uint32_t *) irsp) + 6),
  3150. *(((uint32_t *) irsp) + 7));
  3151. }
  3152. writel(pring->sli.sli3.rspidx,
  3153. &phba->host_gp[pring->ringno].rspGetInx);
  3154. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3155. /* Handle the response IOCB */
  3156. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3157. spin_lock_irqsave(&phba->hbalock, iflag);
  3158. /*
  3159. * If the port response put pointer has not been updated, sync
  3160. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3161. * response put pointer.
  3162. */
  3163. if (pring->sli.sli3.rspidx == portRspPut) {
  3164. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3165. }
  3166. } /* while (pring->sli.sli3.rspidx != portRspPut) */
  3167. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3168. /* At least one response entry has been freed */
  3169. pring->stats.iocb_rsp_full++;
  3170. /* SET RxRE_RSP in Chip Att register */
  3171. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3172. writel(status, phba->CAregaddr);
  3173. readl(phba->CAregaddr); /* flush */
  3174. }
  3175. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3176. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3177. pring->stats.iocb_cmd_empty++;
  3178. /* Force update of the local copy of cmdGetInx */
  3179. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3180. lpfc_sli_resume_iocb(phba, pring);
  3181. if ((pring->lpfc_sli_cmd_available))
  3182. (pring->lpfc_sli_cmd_available) (phba, pring);
  3183. }
  3184. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3185. return;
  3186. }
  3187. /**
  3188. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3189. * @phba: Pointer to HBA context object.
  3190. * @pring: Pointer to driver SLI ring object.
  3191. * @mask: Host attention register mask for this ring.
  3192. *
  3193. * This function is called from the worker thread when there is a pending
  3194. * ELS response iocb on the driver internal slow-path response iocb worker
  3195. * queue. The caller does not hold any lock. The function will remove each
  3196. * response iocb from the response worker queue and calls the handle
  3197. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3198. **/
  3199. static void
  3200. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3201. struct lpfc_sli_ring *pring, uint32_t mask)
  3202. {
  3203. struct lpfc_iocbq *irspiocbq;
  3204. struct hbq_dmabuf *dmabuf;
  3205. struct lpfc_cq_event *cq_event;
  3206. unsigned long iflag;
  3207. spin_lock_irqsave(&phba->hbalock, iflag);
  3208. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3209. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3210. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3211. /* Get the response iocb from the head of work queue */
  3212. spin_lock_irqsave(&phba->hbalock, iflag);
  3213. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3214. cq_event, struct lpfc_cq_event, list);
  3215. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3216. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3217. case CQE_CODE_COMPL_WQE:
  3218. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3219. cq_event);
  3220. /* Translate ELS WCQE to response IOCBQ */
  3221. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3222. irspiocbq);
  3223. if (irspiocbq)
  3224. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3225. irspiocbq);
  3226. break;
  3227. case CQE_CODE_RECEIVE:
  3228. case CQE_CODE_RECEIVE_V1:
  3229. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3230. cq_event);
  3231. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3232. break;
  3233. default:
  3234. break;
  3235. }
  3236. }
  3237. }
  3238. /**
  3239. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3240. * @phba: Pointer to HBA context object.
  3241. * @pring: Pointer to driver SLI ring object.
  3242. *
  3243. * This function aborts all iocbs in the given ring and frees all the iocb
  3244. * objects in txq. This function issues an abort iocb for all the iocb commands
  3245. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3246. * the return of this function. The caller is not required to hold any locks.
  3247. **/
  3248. void
  3249. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3250. {
  3251. LIST_HEAD(completions);
  3252. struct lpfc_iocbq *iocb, *next_iocb;
  3253. if (pring->ringno == LPFC_ELS_RING) {
  3254. lpfc_fabric_abort_hba(phba);
  3255. }
  3256. /* Error everything on txq and txcmplq
  3257. * First do the txq.
  3258. */
  3259. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3260. spin_lock_irq(&pring->ring_lock);
  3261. list_splice_init(&pring->txq, &completions);
  3262. pring->txq_cnt = 0;
  3263. spin_unlock_irq(&pring->ring_lock);
  3264. spin_lock_irq(&phba->hbalock);
  3265. /* Next issue ABTS for everything on the txcmplq */
  3266. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3267. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3268. spin_unlock_irq(&phba->hbalock);
  3269. } else {
  3270. spin_lock_irq(&phba->hbalock);
  3271. list_splice_init(&pring->txq, &completions);
  3272. pring->txq_cnt = 0;
  3273. /* Next issue ABTS for everything on the txcmplq */
  3274. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3275. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3276. spin_unlock_irq(&phba->hbalock);
  3277. }
  3278. /* Cancel all the IOCBs from the completions list */
  3279. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3280. IOERR_SLI_ABORTED);
  3281. }
  3282. /**
  3283. * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
  3284. * @phba: Pointer to HBA context object.
  3285. * @pring: Pointer to driver SLI ring object.
  3286. *
  3287. * This function aborts all iocbs in FCP rings and frees all the iocb
  3288. * objects in txq. This function issues an abort iocb for all the iocb commands
  3289. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3290. * the return of this function. The caller is not required to hold any locks.
  3291. **/
  3292. void
  3293. lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
  3294. {
  3295. struct lpfc_sli *psli = &phba->sli;
  3296. struct lpfc_sli_ring *pring;
  3297. uint32_t i;
  3298. /* Look on all the FCP Rings for the iotag */
  3299. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3300. for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
  3301. pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS];
  3302. lpfc_sli_abort_iocb_ring(phba, pring);
  3303. }
  3304. } else {
  3305. pring = &psli->ring[psli->fcp_ring];
  3306. lpfc_sli_abort_iocb_ring(phba, pring);
  3307. }
  3308. }
  3309. /**
  3310. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3311. * @phba: Pointer to HBA context object.
  3312. *
  3313. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3314. * objects in txq and txcmplq. This function will not issue abort iocbs
  3315. * for all the iocb commands in txcmplq, they will just be returned with
  3316. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3317. * slot has been permanently disabled.
  3318. **/
  3319. void
  3320. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3321. {
  3322. LIST_HEAD(txq);
  3323. LIST_HEAD(txcmplq);
  3324. struct lpfc_sli *psli = &phba->sli;
  3325. struct lpfc_sli_ring *pring;
  3326. uint32_t i;
  3327. spin_lock_irq(&phba->hbalock);
  3328. /* Indicate the I/O queues are flushed */
  3329. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3330. spin_unlock_irq(&phba->hbalock);
  3331. /* Look on all the FCP Rings for the iotag */
  3332. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3333. for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
  3334. pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS];
  3335. spin_lock_irq(&pring->ring_lock);
  3336. /* Retrieve everything on txq */
  3337. list_splice_init(&pring->txq, &txq);
  3338. /* Retrieve everything on the txcmplq */
  3339. list_splice_init(&pring->txcmplq, &txcmplq);
  3340. pring->txq_cnt = 0;
  3341. pring->txcmplq_cnt = 0;
  3342. spin_unlock_irq(&pring->ring_lock);
  3343. /* Flush the txq */
  3344. lpfc_sli_cancel_iocbs(phba, &txq,
  3345. IOSTAT_LOCAL_REJECT,
  3346. IOERR_SLI_DOWN);
  3347. /* Flush the txcmpq */
  3348. lpfc_sli_cancel_iocbs(phba, &txcmplq,
  3349. IOSTAT_LOCAL_REJECT,
  3350. IOERR_SLI_DOWN);
  3351. }
  3352. } else {
  3353. pring = &psli->ring[psli->fcp_ring];
  3354. spin_lock_irq(&phba->hbalock);
  3355. /* Retrieve everything on txq */
  3356. list_splice_init(&pring->txq, &txq);
  3357. /* Retrieve everything on the txcmplq */
  3358. list_splice_init(&pring->txcmplq, &txcmplq);
  3359. pring->txq_cnt = 0;
  3360. pring->txcmplq_cnt = 0;
  3361. spin_unlock_irq(&phba->hbalock);
  3362. /* Flush the txq */
  3363. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3364. IOERR_SLI_DOWN);
  3365. /* Flush the txcmpq */
  3366. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3367. IOERR_SLI_DOWN);
  3368. }
  3369. }
  3370. /**
  3371. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3372. * @phba: Pointer to HBA context object.
  3373. * @mask: Bit mask to be checked.
  3374. *
  3375. * This function reads the host status register and compares
  3376. * with the provided bit mask to check if HBA completed
  3377. * the restart. This function will wait in a loop for the
  3378. * HBA to complete restart. If the HBA does not restart within
  3379. * 15 iterations, the function will reset the HBA again. The
  3380. * function returns 1 when HBA fail to restart otherwise returns
  3381. * zero.
  3382. **/
  3383. static int
  3384. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3385. {
  3386. uint32_t status;
  3387. int i = 0;
  3388. int retval = 0;
  3389. /* Read the HBA Host Status Register */
  3390. if (lpfc_readl(phba->HSregaddr, &status))
  3391. return 1;
  3392. /*
  3393. * Check status register every 100ms for 5 retries, then every
  3394. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3395. * every 2.5 sec for 4.
  3396. * Break our of the loop if errors occurred during init.
  3397. */
  3398. while (((status & mask) != mask) &&
  3399. !(status & HS_FFERM) &&
  3400. i++ < 20) {
  3401. if (i <= 5)
  3402. msleep(10);
  3403. else if (i <= 10)
  3404. msleep(500);
  3405. else
  3406. msleep(2500);
  3407. if (i == 15) {
  3408. /* Do post */
  3409. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3410. lpfc_sli_brdrestart(phba);
  3411. }
  3412. /* Read the HBA Host Status Register */
  3413. if (lpfc_readl(phba->HSregaddr, &status)) {
  3414. retval = 1;
  3415. break;
  3416. }
  3417. }
  3418. /* Check to see if any errors occurred during init */
  3419. if ((status & HS_FFERM) || (i >= 20)) {
  3420. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3421. "2751 Adapter failed to restart, "
  3422. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3423. status,
  3424. readl(phba->MBslimaddr + 0xa8),
  3425. readl(phba->MBslimaddr + 0xac));
  3426. phba->link_state = LPFC_HBA_ERROR;
  3427. retval = 1;
  3428. }
  3429. return retval;
  3430. }
  3431. /**
  3432. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3433. * @phba: Pointer to HBA context object.
  3434. * @mask: Bit mask to be checked.
  3435. *
  3436. * This function checks the host status register to check if HBA is
  3437. * ready. This function will wait in a loop for the HBA to be ready
  3438. * If the HBA is not ready , the function will will reset the HBA PCI
  3439. * function again. The function returns 1 when HBA fail to be ready
  3440. * otherwise returns zero.
  3441. **/
  3442. static int
  3443. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3444. {
  3445. uint32_t status;
  3446. int retval = 0;
  3447. /* Read the HBA Host Status Register */
  3448. status = lpfc_sli4_post_status_check(phba);
  3449. if (status) {
  3450. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3451. lpfc_sli_brdrestart(phba);
  3452. status = lpfc_sli4_post_status_check(phba);
  3453. }
  3454. /* Check to see if any errors occurred during init */
  3455. if (status) {
  3456. phba->link_state = LPFC_HBA_ERROR;
  3457. retval = 1;
  3458. } else
  3459. phba->sli4_hba.intr_enable = 0;
  3460. return retval;
  3461. }
  3462. /**
  3463. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3464. * @phba: Pointer to HBA context object.
  3465. * @mask: Bit mask to be checked.
  3466. *
  3467. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3468. * from the API jump table function pointer from the lpfc_hba struct.
  3469. **/
  3470. int
  3471. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3472. {
  3473. return phba->lpfc_sli_brdready(phba, mask);
  3474. }
  3475. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3476. /**
  3477. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3478. * @phba: Pointer to HBA context object.
  3479. *
  3480. * This function is called before resetting an HBA. This function is called
  3481. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3482. **/
  3483. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3484. {
  3485. uint32_t __iomem *resp_buf;
  3486. uint32_t __iomem *mbox_buf;
  3487. volatile uint32_t mbox;
  3488. uint32_t hc_copy, ha_copy, resp_data;
  3489. int i;
  3490. uint8_t hdrtype;
  3491. lockdep_assert_held(&phba->hbalock);
  3492. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3493. if (hdrtype != 0x80 ||
  3494. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3495. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3496. return;
  3497. /*
  3498. * Tell the other part of the chip to suspend temporarily all
  3499. * its DMA activity.
  3500. */
  3501. resp_buf = phba->MBslimaddr;
  3502. /* Disable the error attention */
  3503. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3504. return;
  3505. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3506. readl(phba->HCregaddr); /* flush */
  3507. phba->link_flag |= LS_IGNORE_ERATT;
  3508. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3509. return;
  3510. if (ha_copy & HA_ERATT) {
  3511. /* Clear Chip error bit */
  3512. writel(HA_ERATT, phba->HAregaddr);
  3513. phba->pport->stopped = 1;
  3514. }
  3515. mbox = 0;
  3516. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3517. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3518. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3519. mbox_buf = phba->MBslimaddr;
  3520. writel(mbox, mbox_buf);
  3521. for (i = 0; i < 50; i++) {
  3522. if (lpfc_readl((resp_buf + 1), &resp_data))
  3523. return;
  3524. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3525. mdelay(1);
  3526. else
  3527. break;
  3528. }
  3529. resp_data = 0;
  3530. if (lpfc_readl((resp_buf + 1), &resp_data))
  3531. return;
  3532. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3533. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3534. phba->pport->stopped)
  3535. goto restore_hc;
  3536. else
  3537. goto clear_errat;
  3538. }
  3539. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3540. resp_data = 0;
  3541. for (i = 0; i < 500; i++) {
  3542. if (lpfc_readl(resp_buf, &resp_data))
  3543. return;
  3544. if (resp_data != mbox)
  3545. mdelay(1);
  3546. else
  3547. break;
  3548. }
  3549. clear_errat:
  3550. while (++i < 500) {
  3551. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3552. return;
  3553. if (!(ha_copy & HA_ERATT))
  3554. mdelay(1);
  3555. else
  3556. break;
  3557. }
  3558. if (readl(phba->HAregaddr) & HA_ERATT) {
  3559. writel(HA_ERATT, phba->HAregaddr);
  3560. phba->pport->stopped = 1;
  3561. }
  3562. restore_hc:
  3563. phba->link_flag &= ~LS_IGNORE_ERATT;
  3564. writel(hc_copy, phba->HCregaddr);
  3565. readl(phba->HCregaddr); /* flush */
  3566. }
  3567. /**
  3568. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3569. * @phba: Pointer to HBA context object.
  3570. *
  3571. * This function issues a kill_board mailbox command and waits for
  3572. * the error attention interrupt. This function is called for stopping
  3573. * the firmware processing. The caller is not required to hold any
  3574. * locks. This function calls lpfc_hba_down_post function to free
  3575. * any pending commands after the kill. The function will return 1 when it
  3576. * fails to kill the board else will return 0.
  3577. **/
  3578. int
  3579. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3580. {
  3581. struct lpfc_sli *psli;
  3582. LPFC_MBOXQ_t *pmb;
  3583. uint32_t status;
  3584. uint32_t ha_copy;
  3585. int retval;
  3586. int i = 0;
  3587. psli = &phba->sli;
  3588. /* Kill HBA */
  3589. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3590. "0329 Kill HBA Data: x%x x%x\n",
  3591. phba->pport->port_state, psli->sli_flag);
  3592. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3593. if (!pmb)
  3594. return 1;
  3595. /* Disable the error attention */
  3596. spin_lock_irq(&phba->hbalock);
  3597. if (lpfc_readl(phba->HCregaddr, &status)) {
  3598. spin_unlock_irq(&phba->hbalock);
  3599. mempool_free(pmb, phba->mbox_mem_pool);
  3600. return 1;
  3601. }
  3602. status &= ~HC_ERINT_ENA;
  3603. writel(status, phba->HCregaddr);
  3604. readl(phba->HCregaddr); /* flush */
  3605. phba->link_flag |= LS_IGNORE_ERATT;
  3606. spin_unlock_irq(&phba->hbalock);
  3607. lpfc_kill_board(phba, pmb);
  3608. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3609. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3610. if (retval != MBX_SUCCESS) {
  3611. if (retval != MBX_BUSY)
  3612. mempool_free(pmb, phba->mbox_mem_pool);
  3613. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3614. "2752 KILL_BOARD command failed retval %d\n",
  3615. retval);
  3616. spin_lock_irq(&phba->hbalock);
  3617. phba->link_flag &= ~LS_IGNORE_ERATT;
  3618. spin_unlock_irq(&phba->hbalock);
  3619. return 1;
  3620. }
  3621. spin_lock_irq(&phba->hbalock);
  3622. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3623. spin_unlock_irq(&phba->hbalock);
  3624. mempool_free(pmb, phba->mbox_mem_pool);
  3625. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3626. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3627. * 3 seconds we still set HBA_ERROR state because the status of the
  3628. * board is now undefined.
  3629. */
  3630. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3631. return 1;
  3632. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3633. mdelay(100);
  3634. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3635. return 1;
  3636. }
  3637. del_timer_sync(&psli->mbox_tmo);
  3638. if (ha_copy & HA_ERATT) {
  3639. writel(HA_ERATT, phba->HAregaddr);
  3640. phba->pport->stopped = 1;
  3641. }
  3642. spin_lock_irq(&phba->hbalock);
  3643. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3644. psli->mbox_active = NULL;
  3645. phba->link_flag &= ~LS_IGNORE_ERATT;
  3646. spin_unlock_irq(&phba->hbalock);
  3647. lpfc_hba_down_post(phba);
  3648. phba->link_state = LPFC_HBA_ERROR;
  3649. return ha_copy & HA_ERATT ? 0 : 1;
  3650. }
  3651. /**
  3652. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3653. * @phba: Pointer to HBA context object.
  3654. *
  3655. * This function resets the HBA by writing HC_INITFF to the control
  3656. * register. After the HBA resets, this function resets all the iocb ring
  3657. * indices. This function disables PCI layer parity checking during
  3658. * the reset.
  3659. * This function returns 0 always.
  3660. * The caller is not required to hold any locks.
  3661. **/
  3662. int
  3663. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3664. {
  3665. struct lpfc_sli *psli;
  3666. struct lpfc_sli_ring *pring;
  3667. uint16_t cfg_value;
  3668. int i;
  3669. psli = &phba->sli;
  3670. /* Reset HBA */
  3671. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3672. "0325 Reset HBA Data: x%x x%x\n",
  3673. phba->pport->port_state, psli->sli_flag);
  3674. /* perform board reset */
  3675. phba->fc_eventTag = 0;
  3676. phba->link_events = 0;
  3677. phba->pport->fc_myDID = 0;
  3678. phba->pport->fc_prevDID = 0;
  3679. /* Turn off parity checking and serr during the physical reset */
  3680. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3681. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3682. (cfg_value &
  3683. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3684. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3685. /* Now toggle INITFF bit in the Host Control Register */
  3686. writel(HC_INITFF, phba->HCregaddr);
  3687. mdelay(1);
  3688. readl(phba->HCregaddr); /* flush */
  3689. writel(0, phba->HCregaddr);
  3690. readl(phba->HCregaddr); /* flush */
  3691. /* Restore PCI cmd register */
  3692. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3693. /* Initialize relevant SLI info */
  3694. for (i = 0; i < psli->num_rings; i++) {
  3695. pring = &psli->ring[i];
  3696. pring->flag = 0;
  3697. pring->sli.sli3.rspidx = 0;
  3698. pring->sli.sli3.next_cmdidx = 0;
  3699. pring->sli.sli3.local_getidx = 0;
  3700. pring->sli.sli3.cmdidx = 0;
  3701. pring->missbufcnt = 0;
  3702. }
  3703. phba->link_state = LPFC_WARM_START;
  3704. return 0;
  3705. }
  3706. /**
  3707. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3708. * @phba: Pointer to HBA context object.
  3709. *
  3710. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3711. * checking during resets the device. The caller is not required to hold
  3712. * any locks.
  3713. *
  3714. * This function returns 0 always.
  3715. **/
  3716. int
  3717. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3718. {
  3719. struct lpfc_sli *psli = &phba->sli;
  3720. uint16_t cfg_value;
  3721. int rc = 0;
  3722. /* Reset HBA */
  3723. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3724. "0295 Reset HBA Data: x%x x%x x%x\n",
  3725. phba->pport->port_state, psli->sli_flag,
  3726. phba->hba_flag);
  3727. /* perform board reset */
  3728. phba->fc_eventTag = 0;
  3729. phba->link_events = 0;
  3730. phba->pport->fc_myDID = 0;
  3731. phba->pport->fc_prevDID = 0;
  3732. spin_lock_irq(&phba->hbalock);
  3733. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3734. phba->fcf.fcf_flag = 0;
  3735. spin_unlock_irq(&phba->hbalock);
  3736. /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
  3737. if (phba->hba_flag & HBA_FW_DUMP_OP) {
  3738. phba->hba_flag &= ~HBA_FW_DUMP_OP;
  3739. return rc;
  3740. }
  3741. /* Now physically reset the device */
  3742. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3743. "0389 Performing PCI function reset!\n");
  3744. /* Turn off parity checking and serr during the physical reset */
  3745. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3746. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3747. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3748. /* Perform FCoE PCI function reset before freeing queue memory */
  3749. rc = lpfc_pci_function_reset(phba);
  3750. lpfc_sli4_queue_destroy(phba);
  3751. /* Restore PCI cmd register */
  3752. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3753. return rc;
  3754. }
  3755. /**
  3756. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3757. * @phba: Pointer to HBA context object.
  3758. *
  3759. * This function is called in the SLI initialization code path to
  3760. * restart the HBA. The caller is not required to hold any lock.
  3761. * This function writes MBX_RESTART mailbox command to the SLIM and
  3762. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3763. * function to free any pending commands. The function enables
  3764. * POST only during the first initialization. The function returns zero.
  3765. * The function does not guarantee completion of MBX_RESTART mailbox
  3766. * command before the return of this function.
  3767. **/
  3768. static int
  3769. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3770. {
  3771. MAILBOX_t *mb;
  3772. struct lpfc_sli *psli;
  3773. volatile uint32_t word0;
  3774. void __iomem *to_slim;
  3775. uint32_t hba_aer_enabled;
  3776. spin_lock_irq(&phba->hbalock);
  3777. /* Take PCIe device Advanced Error Reporting (AER) state */
  3778. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3779. psli = &phba->sli;
  3780. /* Restart HBA */
  3781. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3782. "0337 Restart HBA Data: x%x x%x\n",
  3783. phba->pport->port_state, psli->sli_flag);
  3784. word0 = 0;
  3785. mb = (MAILBOX_t *) &word0;
  3786. mb->mbxCommand = MBX_RESTART;
  3787. mb->mbxHc = 1;
  3788. lpfc_reset_barrier(phba);
  3789. to_slim = phba->MBslimaddr;
  3790. writel(*(uint32_t *) mb, to_slim);
  3791. readl(to_slim); /* flush */
  3792. /* Only skip post after fc_ffinit is completed */
  3793. if (phba->pport->port_state)
  3794. word0 = 1; /* This is really setting up word1 */
  3795. else
  3796. word0 = 0; /* This is really setting up word1 */
  3797. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3798. writel(*(uint32_t *) mb, to_slim);
  3799. readl(to_slim); /* flush */
  3800. lpfc_sli_brdreset(phba);
  3801. phba->pport->stopped = 0;
  3802. phba->link_state = LPFC_INIT_START;
  3803. phba->hba_flag = 0;
  3804. spin_unlock_irq(&phba->hbalock);
  3805. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3806. psli->stats_start = get_seconds();
  3807. /* Give the INITFF and Post time to settle. */
  3808. mdelay(100);
  3809. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3810. if (hba_aer_enabled)
  3811. pci_disable_pcie_error_reporting(phba->pcidev);
  3812. lpfc_hba_down_post(phba);
  3813. return 0;
  3814. }
  3815. /**
  3816. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3817. * @phba: Pointer to HBA context object.
  3818. *
  3819. * This function is called in the SLI initialization code path to restart
  3820. * a SLI4 HBA. The caller is not required to hold any lock.
  3821. * At the end of the function, it calls lpfc_hba_down_post function to
  3822. * free any pending commands.
  3823. **/
  3824. static int
  3825. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3826. {
  3827. struct lpfc_sli *psli = &phba->sli;
  3828. uint32_t hba_aer_enabled;
  3829. int rc;
  3830. /* Restart HBA */
  3831. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3832. "0296 Restart HBA Data: x%x x%x\n",
  3833. phba->pport->port_state, psli->sli_flag);
  3834. /* Take PCIe device Advanced Error Reporting (AER) state */
  3835. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3836. rc = lpfc_sli4_brdreset(phba);
  3837. spin_lock_irq(&phba->hbalock);
  3838. phba->pport->stopped = 0;
  3839. phba->link_state = LPFC_INIT_START;
  3840. phba->hba_flag = 0;
  3841. spin_unlock_irq(&phba->hbalock);
  3842. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3843. psli->stats_start = get_seconds();
  3844. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3845. if (hba_aer_enabled)
  3846. pci_disable_pcie_error_reporting(phba->pcidev);
  3847. lpfc_hba_down_post(phba);
  3848. return rc;
  3849. }
  3850. /**
  3851. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3852. * @phba: Pointer to HBA context object.
  3853. *
  3854. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3855. * API jump table function pointer from the lpfc_hba struct.
  3856. **/
  3857. int
  3858. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3859. {
  3860. return phba->lpfc_sli_brdrestart(phba);
  3861. }
  3862. /**
  3863. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3864. * @phba: Pointer to HBA context object.
  3865. *
  3866. * This function is called after a HBA restart to wait for successful
  3867. * restart of the HBA. Successful restart of the HBA is indicated by
  3868. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3869. * iteration, the function will restart the HBA again. The function returns
  3870. * zero if HBA successfully restarted else returns negative error code.
  3871. **/
  3872. static int
  3873. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3874. {
  3875. uint32_t status, i = 0;
  3876. /* Read the HBA Host Status Register */
  3877. if (lpfc_readl(phba->HSregaddr, &status))
  3878. return -EIO;
  3879. /* Check status register to see what current state is */
  3880. i = 0;
  3881. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3882. /* Check every 10ms for 10 retries, then every 100ms for 90
  3883. * retries, then every 1 sec for 50 retires for a total of
  3884. * ~60 seconds before reset the board again and check every
  3885. * 1 sec for 50 retries. The up to 60 seconds before the
  3886. * board ready is required by the Falcon FIPS zeroization
  3887. * complete, and any reset the board in between shall cause
  3888. * restart of zeroization, further delay the board ready.
  3889. */
  3890. if (i++ >= 200) {
  3891. /* Adapter failed to init, timeout, status reg
  3892. <status> */
  3893. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3894. "0436 Adapter failed to init, "
  3895. "timeout, status reg x%x, "
  3896. "FW Data: A8 x%x AC x%x\n", status,
  3897. readl(phba->MBslimaddr + 0xa8),
  3898. readl(phba->MBslimaddr + 0xac));
  3899. phba->link_state = LPFC_HBA_ERROR;
  3900. return -ETIMEDOUT;
  3901. }
  3902. /* Check to see if any errors occurred during init */
  3903. if (status & HS_FFERM) {
  3904. /* ERROR: During chipset initialization */
  3905. /* Adapter failed to init, chipset, status reg
  3906. <status> */
  3907. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3908. "0437 Adapter failed to init, "
  3909. "chipset, status reg x%x, "
  3910. "FW Data: A8 x%x AC x%x\n", status,
  3911. readl(phba->MBslimaddr + 0xa8),
  3912. readl(phba->MBslimaddr + 0xac));
  3913. phba->link_state = LPFC_HBA_ERROR;
  3914. return -EIO;
  3915. }
  3916. if (i <= 10)
  3917. msleep(10);
  3918. else if (i <= 100)
  3919. msleep(100);
  3920. else
  3921. msleep(1000);
  3922. if (i == 150) {
  3923. /* Do post */
  3924. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3925. lpfc_sli_brdrestart(phba);
  3926. }
  3927. /* Read the HBA Host Status Register */
  3928. if (lpfc_readl(phba->HSregaddr, &status))
  3929. return -EIO;
  3930. }
  3931. /* Check to see if any errors occurred during init */
  3932. if (status & HS_FFERM) {
  3933. /* ERROR: During chipset initialization */
  3934. /* Adapter failed to init, chipset, status reg <status> */
  3935. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3936. "0438 Adapter failed to init, chipset, "
  3937. "status reg x%x, "
  3938. "FW Data: A8 x%x AC x%x\n", status,
  3939. readl(phba->MBslimaddr + 0xa8),
  3940. readl(phba->MBslimaddr + 0xac));
  3941. phba->link_state = LPFC_HBA_ERROR;
  3942. return -EIO;
  3943. }
  3944. /* Clear all interrupt enable conditions */
  3945. writel(0, phba->HCregaddr);
  3946. readl(phba->HCregaddr); /* flush */
  3947. /* setup host attn register */
  3948. writel(0xffffffff, phba->HAregaddr);
  3949. readl(phba->HAregaddr); /* flush */
  3950. return 0;
  3951. }
  3952. /**
  3953. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3954. *
  3955. * This function calculates and returns the number of HBQs required to be
  3956. * configured.
  3957. **/
  3958. int
  3959. lpfc_sli_hbq_count(void)
  3960. {
  3961. return ARRAY_SIZE(lpfc_hbq_defs);
  3962. }
  3963. /**
  3964. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3965. *
  3966. * This function adds the number of hbq entries in every HBQ to get
  3967. * the total number of hbq entries required for the HBA and returns
  3968. * the total count.
  3969. **/
  3970. static int
  3971. lpfc_sli_hbq_entry_count(void)
  3972. {
  3973. int hbq_count = lpfc_sli_hbq_count();
  3974. int count = 0;
  3975. int i;
  3976. for (i = 0; i < hbq_count; ++i)
  3977. count += lpfc_hbq_defs[i]->entry_count;
  3978. return count;
  3979. }
  3980. /**
  3981. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3982. *
  3983. * This function calculates amount of memory required for all hbq entries
  3984. * to be configured and returns the total memory required.
  3985. **/
  3986. int
  3987. lpfc_sli_hbq_size(void)
  3988. {
  3989. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3990. }
  3991. /**
  3992. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3993. * @phba: Pointer to HBA context object.
  3994. *
  3995. * This function is called during the SLI initialization to configure
  3996. * all the HBQs and post buffers to the HBQ. The caller is not
  3997. * required to hold any locks. This function will return zero if successful
  3998. * else it will return negative error code.
  3999. **/
  4000. static int
  4001. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  4002. {
  4003. int hbq_count = lpfc_sli_hbq_count();
  4004. LPFC_MBOXQ_t *pmb;
  4005. MAILBOX_t *pmbox;
  4006. uint32_t hbqno;
  4007. uint32_t hbq_entry_index;
  4008. /* Get a Mailbox buffer to setup mailbox
  4009. * commands for HBA initialization
  4010. */
  4011. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4012. if (!pmb)
  4013. return -ENOMEM;
  4014. pmbox = &pmb->u.mb;
  4015. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  4016. phba->link_state = LPFC_INIT_MBX_CMDS;
  4017. phba->hbq_in_use = 1;
  4018. hbq_entry_index = 0;
  4019. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  4020. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  4021. phba->hbqs[hbqno].hbqPutIdx = 0;
  4022. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  4023. phba->hbqs[hbqno].entry_count =
  4024. lpfc_hbq_defs[hbqno]->entry_count;
  4025. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  4026. hbq_entry_index, pmb);
  4027. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  4028. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  4029. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  4030. mbxStatus <status>, ring <num> */
  4031. lpfc_printf_log(phba, KERN_ERR,
  4032. LOG_SLI | LOG_VPORT,
  4033. "1805 Adapter failed to init. "
  4034. "Data: x%x x%x x%x\n",
  4035. pmbox->mbxCommand,
  4036. pmbox->mbxStatus, hbqno);
  4037. phba->link_state = LPFC_HBA_ERROR;
  4038. mempool_free(pmb, phba->mbox_mem_pool);
  4039. return -ENXIO;
  4040. }
  4041. }
  4042. phba->hbq_count = hbq_count;
  4043. mempool_free(pmb, phba->mbox_mem_pool);
  4044. /* Initially populate or replenish the HBQs */
  4045. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  4046. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  4047. return 0;
  4048. }
  4049. /**
  4050. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  4051. * @phba: Pointer to HBA context object.
  4052. *
  4053. * This function is called during the SLI initialization to configure
  4054. * all the HBQs and post buffers to the HBQ. The caller is not
  4055. * required to hold any locks. This function will return zero if successful
  4056. * else it will return negative error code.
  4057. **/
  4058. static int
  4059. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  4060. {
  4061. phba->hbq_in_use = 1;
  4062. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  4063. phba->hbq_count = 1;
  4064. /* Initially populate or replenish the HBQs */
  4065. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  4066. return 0;
  4067. }
  4068. /**
  4069. * lpfc_sli_config_port - Issue config port mailbox command
  4070. * @phba: Pointer to HBA context object.
  4071. * @sli_mode: sli mode - 2/3
  4072. *
  4073. * This function is called by the sli intialization code path
  4074. * to issue config_port mailbox command. This function restarts the
  4075. * HBA firmware and issues a config_port mailbox command to configure
  4076. * the SLI interface in the sli mode specified by sli_mode
  4077. * variable. The caller is not required to hold any locks.
  4078. * The function returns 0 if successful, else returns negative error
  4079. * code.
  4080. **/
  4081. int
  4082. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  4083. {
  4084. LPFC_MBOXQ_t *pmb;
  4085. uint32_t resetcount = 0, rc = 0, done = 0;
  4086. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4087. if (!pmb) {
  4088. phba->link_state = LPFC_HBA_ERROR;
  4089. return -ENOMEM;
  4090. }
  4091. phba->sli_rev = sli_mode;
  4092. while (resetcount < 2 && !done) {
  4093. spin_lock_irq(&phba->hbalock);
  4094. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4095. spin_unlock_irq(&phba->hbalock);
  4096. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  4097. lpfc_sli_brdrestart(phba);
  4098. rc = lpfc_sli_chipset_init(phba);
  4099. if (rc)
  4100. break;
  4101. spin_lock_irq(&phba->hbalock);
  4102. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4103. spin_unlock_irq(&phba->hbalock);
  4104. resetcount++;
  4105. /* Call pre CONFIG_PORT mailbox command initialization. A
  4106. * value of 0 means the call was successful. Any other
  4107. * nonzero value is a failure, but if ERESTART is returned,
  4108. * the driver may reset the HBA and try again.
  4109. */
  4110. rc = lpfc_config_port_prep(phba);
  4111. if (rc == -ERESTART) {
  4112. phba->link_state = LPFC_LINK_UNKNOWN;
  4113. continue;
  4114. } else if (rc)
  4115. break;
  4116. phba->link_state = LPFC_INIT_MBX_CMDS;
  4117. lpfc_config_port(phba, pmb);
  4118. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4119. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  4120. LPFC_SLI3_HBQ_ENABLED |
  4121. LPFC_SLI3_CRP_ENABLED |
  4122. LPFC_SLI3_BG_ENABLED |
  4123. LPFC_SLI3_DSS_ENABLED);
  4124. if (rc != MBX_SUCCESS) {
  4125. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4126. "0442 Adapter failed to init, mbxCmd x%x "
  4127. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  4128. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  4129. spin_lock_irq(&phba->hbalock);
  4130. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  4131. spin_unlock_irq(&phba->hbalock);
  4132. rc = -ENXIO;
  4133. } else {
  4134. /* Allow asynchronous mailbox command to go through */
  4135. spin_lock_irq(&phba->hbalock);
  4136. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4137. spin_unlock_irq(&phba->hbalock);
  4138. done = 1;
  4139. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  4140. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  4141. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4142. "3110 Port did not grant ASABT\n");
  4143. }
  4144. }
  4145. if (!done) {
  4146. rc = -EINVAL;
  4147. goto do_prep_failed;
  4148. }
  4149. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  4150. if (!pmb->u.mb.un.varCfgPort.cMA) {
  4151. rc = -ENXIO;
  4152. goto do_prep_failed;
  4153. }
  4154. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  4155. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  4156. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  4157. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  4158. phba->max_vpi : phba->max_vports;
  4159. } else
  4160. phba->max_vpi = 0;
  4161. phba->fips_level = 0;
  4162. phba->fips_spec_rev = 0;
  4163. if (pmb->u.mb.un.varCfgPort.gdss) {
  4164. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  4165. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  4166. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  4167. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4168. "2850 Security Crypto Active. FIPS x%d "
  4169. "(Spec Rev: x%d)",
  4170. phba->fips_level, phba->fips_spec_rev);
  4171. }
  4172. if (pmb->u.mb.un.varCfgPort.sec_err) {
  4173. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4174. "2856 Config Port Security Crypto "
  4175. "Error: x%x ",
  4176. pmb->u.mb.un.varCfgPort.sec_err);
  4177. }
  4178. if (pmb->u.mb.un.varCfgPort.gerbm)
  4179. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  4180. if (pmb->u.mb.un.varCfgPort.gcrp)
  4181. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  4182. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  4183. phba->port_gp = phba->mbox->us.s3_pgp.port;
  4184. if (phba->cfg_enable_bg) {
  4185. if (pmb->u.mb.un.varCfgPort.gbg)
  4186. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  4187. else
  4188. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4189. "0443 Adapter did not grant "
  4190. "BlockGuard\n");
  4191. }
  4192. } else {
  4193. phba->hbq_get = NULL;
  4194. phba->port_gp = phba->mbox->us.s2.port;
  4195. phba->max_vpi = 0;
  4196. }
  4197. do_prep_failed:
  4198. mempool_free(pmb, phba->mbox_mem_pool);
  4199. return rc;
  4200. }
  4201. /**
  4202. * lpfc_sli_hba_setup - SLI intialization function
  4203. * @phba: Pointer to HBA context object.
  4204. *
  4205. * This function is the main SLI intialization function. This function
  4206. * is called by the HBA intialization code, HBA reset code and HBA
  4207. * error attention handler code. Caller is not required to hold any
  4208. * locks. This function issues config_port mailbox command to configure
  4209. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4210. * calls the config_port_post function to issue init_link mailbox
  4211. * command and to start the discovery. The function will return zero
  4212. * if successful, else it will return negative error code.
  4213. **/
  4214. int
  4215. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4216. {
  4217. uint32_t rc;
  4218. int mode = 3, i;
  4219. int longs;
  4220. switch (phba->cfg_sli_mode) {
  4221. case 2:
  4222. if (phba->cfg_enable_npiv) {
  4223. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4224. "1824 NPIV enabled: Override sli_mode "
  4225. "parameter (%d) to auto (0).\n",
  4226. phba->cfg_sli_mode);
  4227. break;
  4228. }
  4229. mode = 2;
  4230. break;
  4231. case 0:
  4232. case 3:
  4233. break;
  4234. default:
  4235. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4236. "1819 Unrecognized sli_mode parameter: %d.\n",
  4237. phba->cfg_sli_mode);
  4238. break;
  4239. }
  4240. phba->fcp_embed_io = 0; /* SLI4 FC support only */
  4241. rc = lpfc_sli_config_port(phba, mode);
  4242. if (rc && phba->cfg_sli_mode == 3)
  4243. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4244. "1820 Unable to select SLI-3. "
  4245. "Not supported by adapter.\n");
  4246. if (rc && mode != 2)
  4247. rc = lpfc_sli_config_port(phba, 2);
  4248. else if (rc && mode == 2)
  4249. rc = lpfc_sli_config_port(phba, 3);
  4250. if (rc)
  4251. goto lpfc_sli_hba_setup_error;
  4252. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4253. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4254. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4255. if (!rc) {
  4256. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4257. "2709 This device supports "
  4258. "Advanced Error Reporting (AER)\n");
  4259. spin_lock_irq(&phba->hbalock);
  4260. phba->hba_flag |= HBA_AER_ENABLED;
  4261. spin_unlock_irq(&phba->hbalock);
  4262. } else {
  4263. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4264. "2708 This device does not support "
  4265. "Advanced Error Reporting (AER): %d\n",
  4266. rc);
  4267. phba->cfg_aer_support = 0;
  4268. }
  4269. }
  4270. if (phba->sli_rev == 3) {
  4271. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4272. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4273. } else {
  4274. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4275. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4276. phba->sli3_options = 0;
  4277. }
  4278. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4279. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4280. phba->sli_rev, phba->max_vpi);
  4281. rc = lpfc_sli_ring_map(phba);
  4282. if (rc)
  4283. goto lpfc_sli_hba_setup_error;
  4284. /* Initialize VPIs. */
  4285. if (phba->sli_rev == LPFC_SLI_REV3) {
  4286. /*
  4287. * The VPI bitmask and physical ID array are allocated
  4288. * and initialized once only - at driver load. A port
  4289. * reset doesn't need to reinitialize this memory.
  4290. */
  4291. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4292. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4293. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4294. GFP_KERNEL);
  4295. if (!phba->vpi_bmask) {
  4296. rc = -ENOMEM;
  4297. goto lpfc_sli_hba_setup_error;
  4298. }
  4299. phba->vpi_ids = kzalloc(
  4300. (phba->max_vpi+1) * sizeof(uint16_t),
  4301. GFP_KERNEL);
  4302. if (!phba->vpi_ids) {
  4303. kfree(phba->vpi_bmask);
  4304. rc = -ENOMEM;
  4305. goto lpfc_sli_hba_setup_error;
  4306. }
  4307. for (i = 0; i < phba->max_vpi; i++)
  4308. phba->vpi_ids[i] = i;
  4309. }
  4310. }
  4311. /* Init HBQs */
  4312. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4313. rc = lpfc_sli_hbq_setup(phba);
  4314. if (rc)
  4315. goto lpfc_sli_hba_setup_error;
  4316. }
  4317. spin_lock_irq(&phba->hbalock);
  4318. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4319. spin_unlock_irq(&phba->hbalock);
  4320. rc = lpfc_config_port_post(phba);
  4321. if (rc)
  4322. goto lpfc_sli_hba_setup_error;
  4323. return rc;
  4324. lpfc_sli_hba_setup_error:
  4325. phba->link_state = LPFC_HBA_ERROR;
  4326. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4327. "0445 Firmware initialization failed\n");
  4328. return rc;
  4329. }
  4330. /**
  4331. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4332. * @phba: Pointer to HBA context object.
  4333. * @mboxq: mailbox pointer.
  4334. * This function issue a dump mailbox command to read config region
  4335. * 23 and parse the records in the region and populate driver
  4336. * data structure.
  4337. **/
  4338. static int
  4339. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4340. {
  4341. LPFC_MBOXQ_t *mboxq;
  4342. struct lpfc_dmabuf *mp;
  4343. struct lpfc_mqe *mqe;
  4344. uint32_t data_length;
  4345. int rc;
  4346. /* Program the default value of vlan_id and fc_map */
  4347. phba->valid_vlan = 0;
  4348. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4349. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4350. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4351. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4352. if (!mboxq)
  4353. return -ENOMEM;
  4354. mqe = &mboxq->u.mqe;
  4355. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4356. rc = -ENOMEM;
  4357. goto out_free_mboxq;
  4358. }
  4359. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4360. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4361. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4362. "(%d):2571 Mailbox cmd x%x Status x%x "
  4363. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4364. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4365. "CQ: x%x x%x x%x x%x\n",
  4366. mboxq->vport ? mboxq->vport->vpi : 0,
  4367. bf_get(lpfc_mqe_command, mqe),
  4368. bf_get(lpfc_mqe_status, mqe),
  4369. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4370. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4371. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4372. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4373. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4374. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4375. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4376. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4377. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4378. mboxq->mcqe.word0,
  4379. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4380. mboxq->mcqe.trailer);
  4381. if (rc) {
  4382. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4383. kfree(mp);
  4384. rc = -EIO;
  4385. goto out_free_mboxq;
  4386. }
  4387. data_length = mqe->un.mb_words[5];
  4388. if (data_length > DMP_RGN23_SIZE) {
  4389. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4390. kfree(mp);
  4391. rc = -EIO;
  4392. goto out_free_mboxq;
  4393. }
  4394. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4395. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4396. kfree(mp);
  4397. rc = 0;
  4398. out_free_mboxq:
  4399. mempool_free(mboxq, phba->mbox_mem_pool);
  4400. return rc;
  4401. }
  4402. /**
  4403. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4404. * @phba: pointer to lpfc hba data structure.
  4405. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4406. * @vpd: pointer to the memory to hold resulting port vpd data.
  4407. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4408. * On output, the number of data bytes in @vpd.
  4409. *
  4410. * This routine executes a READ_REV SLI4 mailbox command. In
  4411. * addition, this routine gets the port vpd data.
  4412. *
  4413. * Return codes
  4414. * 0 - successful
  4415. * -ENOMEM - could not allocated memory.
  4416. **/
  4417. static int
  4418. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4419. uint8_t *vpd, uint32_t *vpd_size)
  4420. {
  4421. int rc = 0;
  4422. uint32_t dma_size;
  4423. struct lpfc_dmabuf *dmabuf;
  4424. struct lpfc_mqe *mqe;
  4425. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4426. if (!dmabuf)
  4427. return -ENOMEM;
  4428. /*
  4429. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4430. * mailbox command.
  4431. */
  4432. dma_size = *vpd_size;
  4433. dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size,
  4434. &dmabuf->phys, GFP_KERNEL);
  4435. if (!dmabuf->virt) {
  4436. kfree(dmabuf);
  4437. return -ENOMEM;
  4438. }
  4439. /*
  4440. * The SLI4 implementation of READ_REV conflicts at word1,
  4441. * bits 31:16 and SLI4 adds vpd functionality not present
  4442. * in SLI3. This code corrects the conflicts.
  4443. */
  4444. lpfc_read_rev(phba, mboxq);
  4445. mqe = &mboxq->u.mqe;
  4446. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4447. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4448. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4449. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4450. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4451. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4452. if (rc) {
  4453. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4454. dmabuf->virt, dmabuf->phys);
  4455. kfree(dmabuf);
  4456. return -EIO;
  4457. }
  4458. /*
  4459. * The available vpd length cannot be bigger than the
  4460. * DMA buffer passed to the port. Catch the less than
  4461. * case and update the caller's size.
  4462. */
  4463. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4464. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4465. memcpy(vpd, dmabuf->virt, *vpd_size);
  4466. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4467. dmabuf->virt, dmabuf->phys);
  4468. kfree(dmabuf);
  4469. return 0;
  4470. }
  4471. /**
  4472. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4473. * @phba: pointer to lpfc hba data structure.
  4474. *
  4475. * This routine retrieves SLI4 device physical port name this PCI function
  4476. * is attached to.
  4477. *
  4478. * Return codes
  4479. * 0 - successful
  4480. * otherwise - failed to retrieve physical port name
  4481. **/
  4482. static int
  4483. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4484. {
  4485. LPFC_MBOXQ_t *mboxq;
  4486. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4487. struct lpfc_controller_attribute *cntl_attr;
  4488. struct lpfc_mbx_get_port_name *get_port_name;
  4489. void *virtaddr = NULL;
  4490. uint32_t alloclen, reqlen;
  4491. uint32_t shdr_status, shdr_add_status;
  4492. union lpfc_sli4_cfg_shdr *shdr;
  4493. char cport_name = 0;
  4494. int rc;
  4495. /* We assume nothing at this point */
  4496. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4497. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4498. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4499. if (!mboxq)
  4500. return -ENOMEM;
  4501. /* obtain link type and link number via READ_CONFIG */
  4502. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4503. lpfc_sli4_read_config(phba);
  4504. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4505. goto retrieve_ppname;
  4506. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4507. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4508. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4509. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4510. LPFC_SLI4_MBX_NEMBED);
  4511. if (alloclen < reqlen) {
  4512. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4513. "3084 Allocated DMA memory size (%d) is "
  4514. "less than the requested DMA memory size "
  4515. "(%d)\n", alloclen, reqlen);
  4516. rc = -ENOMEM;
  4517. goto out_free_mboxq;
  4518. }
  4519. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4520. virtaddr = mboxq->sge_array->addr[0];
  4521. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4522. shdr = &mbx_cntl_attr->cfg_shdr;
  4523. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4524. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4525. if (shdr_status || shdr_add_status || rc) {
  4526. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4527. "3085 Mailbox x%x (x%x/x%x) failed, "
  4528. "rc:x%x, status:x%x, add_status:x%x\n",
  4529. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4530. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4531. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4532. rc, shdr_status, shdr_add_status);
  4533. rc = -ENXIO;
  4534. goto out_free_mboxq;
  4535. }
  4536. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4537. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4538. phba->sli4_hba.lnk_info.lnk_tp =
  4539. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4540. phba->sli4_hba.lnk_info.lnk_no =
  4541. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4542. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4543. "3086 lnk_type:%d, lnk_numb:%d\n",
  4544. phba->sli4_hba.lnk_info.lnk_tp,
  4545. phba->sli4_hba.lnk_info.lnk_no);
  4546. retrieve_ppname:
  4547. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4548. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4549. sizeof(struct lpfc_mbx_get_port_name) -
  4550. sizeof(struct lpfc_sli4_cfg_mhdr),
  4551. LPFC_SLI4_MBX_EMBED);
  4552. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4553. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4554. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4555. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4556. phba->sli4_hba.lnk_info.lnk_tp);
  4557. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4558. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4559. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4560. if (shdr_status || shdr_add_status || rc) {
  4561. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4562. "3087 Mailbox x%x (x%x/x%x) failed: "
  4563. "rc:x%x, status:x%x, add_status:x%x\n",
  4564. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4565. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4566. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4567. rc, shdr_status, shdr_add_status);
  4568. rc = -ENXIO;
  4569. goto out_free_mboxq;
  4570. }
  4571. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4572. case LPFC_LINK_NUMBER_0:
  4573. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4574. &get_port_name->u.response);
  4575. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4576. break;
  4577. case LPFC_LINK_NUMBER_1:
  4578. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4579. &get_port_name->u.response);
  4580. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4581. break;
  4582. case LPFC_LINK_NUMBER_2:
  4583. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4584. &get_port_name->u.response);
  4585. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4586. break;
  4587. case LPFC_LINK_NUMBER_3:
  4588. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4589. &get_port_name->u.response);
  4590. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4591. break;
  4592. default:
  4593. break;
  4594. }
  4595. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4596. phba->Port[0] = cport_name;
  4597. phba->Port[1] = '\0';
  4598. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4599. "3091 SLI get port name: %s\n", phba->Port);
  4600. }
  4601. out_free_mboxq:
  4602. if (rc != MBX_TIMEOUT) {
  4603. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4604. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4605. else
  4606. mempool_free(mboxq, phba->mbox_mem_pool);
  4607. }
  4608. return rc;
  4609. }
  4610. /**
  4611. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4612. * @phba: pointer to lpfc hba data structure.
  4613. *
  4614. * This routine is called to explicitly arm the SLI4 device's completion and
  4615. * event queues
  4616. **/
  4617. static void
  4618. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4619. {
  4620. int fcp_eqidx;
  4621. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4622. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4623. fcp_eqidx = 0;
  4624. if (phba->sli4_hba.fcp_cq) {
  4625. do {
  4626. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4627. LPFC_QUEUE_REARM);
  4628. } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
  4629. }
  4630. if (phba->cfg_fof)
  4631. lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM);
  4632. if (phba->sli4_hba.hba_eq) {
  4633. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
  4634. fcp_eqidx++)
  4635. lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
  4636. LPFC_QUEUE_REARM);
  4637. }
  4638. if (phba->cfg_fof)
  4639. lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM);
  4640. }
  4641. /**
  4642. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4643. * @phba: Pointer to HBA context object.
  4644. * @type: The resource extent type.
  4645. * @extnt_count: buffer to hold port available extent count.
  4646. * @extnt_size: buffer to hold element count per extent.
  4647. *
  4648. * This function calls the port and retrievs the number of available
  4649. * extents and their size for a particular extent type.
  4650. *
  4651. * Returns: 0 if successful. Nonzero otherwise.
  4652. **/
  4653. int
  4654. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4655. uint16_t *extnt_count, uint16_t *extnt_size)
  4656. {
  4657. int rc = 0;
  4658. uint32_t length;
  4659. uint32_t mbox_tmo;
  4660. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4661. LPFC_MBOXQ_t *mbox;
  4662. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4663. if (!mbox)
  4664. return -ENOMEM;
  4665. /* Find out how many extents are available for this resource type */
  4666. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4667. sizeof(struct lpfc_sli4_cfg_mhdr));
  4668. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4669. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4670. length, LPFC_SLI4_MBX_EMBED);
  4671. /* Send an extents count of 0 - the GET doesn't use it. */
  4672. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4673. LPFC_SLI4_MBX_EMBED);
  4674. if (unlikely(rc)) {
  4675. rc = -EIO;
  4676. goto err_exit;
  4677. }
  4678. if (!phba->sli4_hba.intr_enable)
  4679. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4680. else {
  4681. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4682. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4683. }
  4684. if (unlikely(rc)) {
  4685. rc = -EIO;
  4686. goto err_exit;
  4687. }
  4688. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4689. if (bf_get(lpfc_mbox_hdr_status,
  4690. &rsrc_info->header.cfg_shdr.response)) {
  4691. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4692. "2930 Failed to get resource extents "
  4693. "Status 0x%x Add'l Status 0x%x\n",
  4694. bf_get(lpfc_mbox_hdr_status,
  4695. &rsrc_info->header.cfg_shdr.response),
  4696. bf_get(lpfc_mbox_hdr_add_status,
  4697. &rsrc_info->header.cfg_shdr.response));
  4698. rc = -EIO;
  4699. goto err_exit;
  4700. }
  4701. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4702. &rsrc_info->u.rsp);
  4703. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4704. &rsrc_info->u.rsp);
  4705. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4706. "3162 Retrieved extents type-%d from port: count:%d, "
  4707. "size:%d\n", type, *extnt_count, *extnt_size);
  4708. err_exit:
  4709. mempool_free(mbox, phba->mbox_mem_pool);
  4710. return rc;
  4711. }
  4712. /**
  4713. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4714. * @phba: Pointer to HBA context object.
  4715. * @type: The extent type to check.
  4716. *
  4717. * This function reads the current available extents from the port and checks
  4718. * if the extent count or extent size has changed since the last access.
  4719. * Callers use this routine post port reset to understand if there is a
  4720. * extent reprovisioning requirement.
  4721. *
  4722. * Returns:
  4723. * -Error: error indicates problem.
  4724. * 1: Extent count or size has changed.
  4725. * 0: No changes.
  4726. **/
  4727. static int
  4728. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4729. {
  4730. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4731. uint16_t size_diff, rsrc_ext_size;
  4732. int rc = 0;
  4733. struct lpfc_rsrc_blks *rsrc_entry;
  4734. struct list_head *rsrc_blk_list = NULL;
  4735. size_diff = 0;
  4736. curr_ext_cnt = 0;
  4737. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4738. &rsrc_ext_cnt,
  4739. &rsrc_ext_size);
  4740. if (unlikely(rc))
  4741. return -EIO;
  4742. switch (type) {
  4743. case LPFC_RSC_TYPE_FCOE_RPI:
  4744. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4745. break;
  4746. case LPFC_RSC_TYPE_FCOE_VPI:
  4747. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4748. break;
  4749. case LPFC_RSC_TYPE_FCOE_XRI:
  4750. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4751. break;
  4752. case LPFC_RSC_TYPE_FCOE_VFI:
  4753. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4754. break;
  4755. default:
  4756. break;
  4757. }
  4758. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4759. curr_ext_cnt++;
  4760. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4761. size_diff++;
  4762. }
  4763. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4764. rc = 1;
  4765. return rc;
  4766. }
  4767. /**
  4768. * lpfc_sli4_cfg_post_extnts -
  4769. * @phba: Pointer to HBA context object.
  4770. * @extnt_cnt - number of available extents.
  4771. * @type - the extent type (rpi, xri, vfi, vpi).
  4772. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4773. * @mbox - pointer to the caller's allocated mailbox structure.
  4774. *
  4775. * This function executes the extents allocation request. It also
  4776. * takes care of the amount of memory needed to allocate or get the
  4777. * allocated extents. It is the caller's responsibility to evaluate
  4778. * the response.
  4779. *
  4780. * Returns:
  4781. * -Error: Error value describes the condition found.
  4782. * 0: if successful
  4783. **/
  4784. static int
  4785. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4786. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4787. {
  4788. int rc = 0;
  4789. uint32_t req_len;
  4790. uint32_t emb_len;
  4791. uint32_t alloc_len, mbox_tmo;
  4792. /* Calculate the total requested length of the dma memory */
  4793. req_len = extnt_cnt * sizeof(uint16_t);
  4794. /*
  4795. * Calculate the size of an embedded mailbox. The uint32_t
  4796. * accounts for extents-specific word.
  4797. */
  4798. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4799. sizeof(uint32_t);
  4800. /*
  4801. * Presume the allocation and response will fit into an embedded
  4802. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4803. */
  4804. *emb = LPFC_SLI4_MBX_EMBED;
  4805. if (req_len > emb_len) {
  4806. req_len = extnt_cnt * sizeof(uint16_t) +
  4807. sizeof(union lpfc_sli4_cfg_shdr) +
  4808. sizeof(uint32_t);
  4809. *emb = LPFC_SLI4_MBX_NEMBED;
  4810. }
  4811. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4812. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4813. req_len, *emb);
  4814. if (alloc_len < req_len) {
  4815. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4816. "2982 Allocated DMA memory size (x%x) is "
  4817. "less than the requested DMA memory "
  4818. "size (x%x)\n", alloc_len, req_len);
  4819. return -ENOMEM;
  4820. }
  4821. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4822. if (unlikely(rc))
  4823. return -EIO;
  4824. if (!phba->sli4_hba.intr_enable)
  4825. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4826. else {
  4827. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4828. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4829. }
  4830. if (unlikely(rc))
  4831. rc = -EIO;
  4832. return rc;
  4833. }
  4834. /**
  4835. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4836. * @phba: Pointer to HBA context object.
  4837. * @type: The resource extent type to allocate.
  4838. *
  4839. * This function allocates the number of elements for the specified
  4840. * resource type.
  4841. **/
  4842. static int
  4843. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4844. {
  4845. bool emb = false;
  4846. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4847. uint16_t rsrc_id, rsrc_start, j, k;
  4848. uint16_t *ids;
  4849. int i, rc;
  4850. unsigned long longs;
  4851. unsigned long *bmask;
  4852. struct lpfc_rsrc_blks *rsrc_blks;
  4853. LPFC_MBOXQ_t *mbox;
  4854. uint32_t length;
  4855. struct lpfc_id_range *id_array = NULL;
  4856. void *virtaddr = NULL;
  4857. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4858. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4859. struct list_head *ext_blk_list;
  4860. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4861. &rsrc_cnt,
  4862. &rsrc_size);
  4863. if (unlikely(rc))
  4864. return -EIO;
  4865. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4866. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4867. "3009 No available Resource Extents "
  4868. "for resource type 0x%x: Count: 0x%x, "
  4869. "Size 0x%x\n", type, rsrc_cnt,
  4870. rsrc_size);
  4871. return -ENOMEM;
  4872. }
  4873. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4874. "2903 Post resource extents type-0x%x: "
  4875. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4876. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4877. if (!mbox)
  4878. return -ENOMEM;
  4879. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4880. if (unlikely(rc)) {
  4881. rc = -EIO;
  4882. goto err_exit;
  4883. }
  4884. /*
  4885. * Figure out where the response is located. Then get local pointers
  4886. * to the response data. The port does not guarantee to respond to
  4887. * all extents counts request so update the local variable with the
  4888. * allocated count from the port.
  4889. */
  4890. if (emb == LPFC_SLI4_MBX_EMBED) {
  4891. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4892. id_array = &rsrc_ext->u.rsp.id[0];
  4893. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4894. } else {
  4895. virtaddr = mbox->sge_array->addr[0];
  4896. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4897. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4898. id_array = &n_rsrc->id;
  4899. }
  4900. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4901. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4902. /*
  4903. * Based on the resource size and count, correct the base and max
  4904. * resource values.
  4905. */
  4906. length = sizeof(struct lpfc_rsrc_blks);
  4907. switch (type) {
  4908. case LPFC_RSC_TYPE_FCOE_RPI:
  4909. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4910. sizeof(unsigned long),
  4911. GFP_KERNEL);
  4912. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4913. rc = -ENOMEM;
  4914. goto err_exit;
  4915. }
  4916. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4917. sizeof(uint16_t),
  4918. GFP_KERNEL);
  4919. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4920. kfree(phba->sli4_hba.rpi_bmask);
  4921. rc = -ENOMEM;
  4922. goto err_exit;
  4923. }
  4924. /*
  4925. * The next_rpi was initialized with the maximum available
  4926. * count but the port may allocate a smaller number. Catch
  4927. * that case and update the next_rpi.
  4928. */
  4929. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4930. /* Initialize local ptrs for common extent processing later. */
  4931. bmask = phba->sli4_hba.rpi_bmask;
  4932. ids = phba->sli4_hba.rpi_ids;
  4933. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4934. break;
  4935. case LPFC_RSC_TYPE_FCOE_VPI:
  4936. phba->vpi_bmask = kzalloc(longs *
  4937. sizeof(unsigned long),
  4938. GFP_KERNEL);
  4939. if (unlikely(!phba->vpi_bmask)) {
  4940. rc = -ENOMEM;
  4941. goto err_exit;
  4942. }
  4943. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4944. sizeof(uint16_t),
  4945. GFP_KERNEL);
  4946. if (unlikely(!phba->vpi_ids)) {
  4947. kfree(phba->vpi_bmask);
  4948. rc = -ENOMEM;
  4949. goto err_exit;
  4950. }
  4951. /* Initialize local ptrs for common extent processing later. */
  4952. bmask = phba->vpi_bmask;
  4953. ids = phba->vpi_ids;
  4954. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4955. break;
  4956. case LPFC_RSC_TYPE_FCOE_XRI:
  4957. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4958. sizeof(unsigned long),
  4959. GFP_KERNEL);
  4960. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4961. rc = -ENOMEM;
  4962. goto err_exit;
  4963. }
  4964. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4965. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4966. sizeof(uint16_t),
  4967. GFP_KERNEL);
  4968. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4969. kfree(phba->sli4_hba.xri_bmask);
  4970. rc = -ENOMEM;
  4971. goto err_exit;
  4972. }
  4973. /* Initialize local ptrs for common extent processing later. */
  4974. bmask = phba->sli4_hba.xri_bmask;
  4975. ids = phba->sli4_hba.xri_ids;
  4976. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4977. break;
  4978. case LPFC_RSC_TYPE_FCOE_VFI:
  4979. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4980. sizeof(unsigned long),
  4981. GFP_KERNEL);
  4982. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4983. rc = -ENOMEM;
  4984. goto err_exit;
  4985. }
  4986. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4987. sizeof(uint16_t),
  4988. GFP_KERNEL);
  4989. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4990. kfree(phba->sli4_hba.vfi_bmask);
  4991. rc = -ENOMEM;
  4992. goto err_exit;
  4993. }
  4994. /* Initialize local ptrs for common extent processing later. */
  4995. bmask = phba->sli4_hba.vfi_bmask;
  4996. ids = phba->sli4_hba.vfi_ids;
  4997. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4998. break;
  4999. default:
  5000. /* Unsupported Opcode. Fail call. */
  5001. id_array = NULL;
  5002. bmask = NULL;
  5003. ids = NULL;
  5004. ext_blk_list = NULL;
  5005. goto err_exit;
  5006. }
  5007. /*
  5008. * Complete initializing the extent configuration with the
  5009. * allocated ids assigned to this function. The bitmask serves
  5010. * as an index into the array and manages the available ids. The
  5011. * array just stores the ids communicated to the port via the wqes.
  5012. */
  5013. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  5014. if ((i % 2) == 0)
  5015. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  5016. &id_array[k]);
  5017. else
  5018. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  5019. &id_array[k]);
  5020. rsrc_blks = kzalloc(length, GFP_KERNEL);
  5021. if (unlikely(!rsrc_blks)) {
  5022. rc = -ENOMEM;
  5023. kfree(bmask);
  5024. kfree(ids);
  5025. goto err_exit;
  5026. }
  5027. rsrc_blks->rsrc_start = rsrc_id;
  5028. rsrc_blks->rsrc_size = rsrc_size;
  5029. list_add_tail(&rsrc_blks->list, ext_blk_list);
  5030. rsrc_start = rsrc_id;
  5031. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  5032. phba->sli4_hba.scsi_xri_start = rsrc_start +
  5033. lpfc_sli4_get_els_iocb_cnt(phba);
  5034. while (rsrc_id < (rsrc_start + rsrc_size)) {
  5035. ids[j] = rsrc_id;
  5036. rsrc_id++;
  5037. j++;
  5038. }
  5039. /* Entire word processed. Get next word.*/
  5040. if ((i % 2) == 1)
  5041. k++;
  5042. }
  5043. err_exit:
  5044. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5045. return rc;
  5046. }
  5047. /**
  5048. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  5049. * @phba: Pointer to HBA context object.
  5050. * @type: the extent's type.
  5051. *
  5052. * This function deallocates all extents of a particular resource type.
  5053. * SLI4 does not allow for deallocating a particular extent range. It
  5054. * is the caller's responsibility to release all kernel memory resources.
  5055. **/
  5056. static int
  5057. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  5058. {
  5059. int rc;
  5060. uint32_t length, mbox_tmo = 0;
  5061. LPFC_MBOXQ_t *mbox;
  5062. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  5063. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  5064. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5065. if (!mbox)
  5066. return -ENOMEM;
  5067. /*
  5068. * This function sends an embedded mailbox because it only sends the
  5069. * the resource type. All extents of this type are released by the
  5070. * port.
  5071. */
  5072. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  5073. sizeof(struct lpfc_sli4_cfg_mhdr));
  5074. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5075. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  5076. length, LPFC_SLI4_MBX_EMBED);
  5077. /* Send an extents count of 0 - the dealloc doesn't use it. */
  5078. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  5079. LPFC_SLI4_MBX_EMBED);
  5080. if (unlikely(rc)) {
  5081. rc = -EIO;
  5082. goto out_free_mbox;
  5083. }
  5084. if (!phba->sli4_hba.intr_enable)
  5085. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5086. else {
  5087. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5088. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5089. }
  5090. if (unlikely(rc)) {
  5091. rc = -EIO;
  5092. goto out_free_mbox;
  5093. }
  5094. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  5095. if (bf_get(lpfc_mbox_hdr_status,
  5096. &dealloc_rsrc->header.cfg_shdr.response)) {
  5097. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5098. "2919 Failed to release resource extents "
  5099. "for type %d - Status 0x%x Add'l Status 0x%x. "
  5100. "Resource memory not released.\n",
  5101. type,
  5102. bf_get(lpfc_mbox_hdr_status,
  5103. &dealloc_rsrc->header.cfg_shdr.response),
  5104. bf_get(lpfc_mbox_hdr_add_status,
  5105. &dealloc_rsrc->header.cfg_shdr.response));
  5106. rc = -EIO;
  5107. goto out_free_mbox;
  5108. }
  5109. /* Release kernel memory resources for the specific type. */
  5110. switch (type) {
  5111. case LPFC_RSC_TYPE_FCOE_VPI:
  5112. kfree(phba->vpi_bmask);
  5113. kfree(phba->vpi_ids);
  5114. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5115. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5116. &phba->lpfc_vpi_blk_list, list) {
  5117. list_del_init(&rsrc_blk->list);
  5118. kfree(rsrc_blk);
  5119. }
  5120. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5121. break;
  5122. case LPFC_RSC_TYPE_FCOE_XRI:
  5123. kfree(phba->sli4_hba.xri_bmask);
  5124. kfree(phba->sli4_hba.xri_ids);
  5125. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5126. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  5127. list_del_init(&rsrc_blk->list);
  5128. kfree(rsrc_blk);
  5129. }
  5130. break;
  5131. case LPFC_RSC_TYPE_FCOE_VFI:
  5132. kfree(phba->sli4_hba.vfi_bmask);
  5133. kfree(phba->sli4_hba.vfi_ids);
  5134. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5135. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5136. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  5137. list_del_init(&rsrc_blk->list);
  5138. kfree(rsrc_blk);
  5139. }
  5140. break;
  5141. case LPFC_RSC_TYPE_FCOE_RPI:
  5142. /* RPI bitmask and physical id array are cleaned up earlier. */
  5143. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5144. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  5145. list_del_init(&rsrc_blk->list);
  5146. kfree(rsrc_blk);
  5147. }
  5148. break;
  5149. default:
  5150. break;
  5151. }
  5152. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5153. out_free_mbox:
  5154. mempool_free(mbox, phba->mbox_mem_pool);
  5155. return rc;
  5156. }
  5157. static void
  5158. lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
  5159. uint32_t feature)
  5160. {
  5161. uint32_t len;
  5162. len = sizeof(struct lpfc_mbx_set_feature) -
  5163. sizeof(struct lpfc_sli4_cfg_mhdr);
  5164. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5165. LPFC_MBOX_OPCODE_SET_FEATURES, len,
  5166. LPFC_SLI4_MBX_EMBED);
  5167. switch (feature) {
  5168. case LPFC_SET_UE_RECOVERY:
  5169. bf_set(lpfc_mbx_set_feature_UER,
  5170. &mbox->u.mqe.un.set_feature, 1);
  5171. mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
  5172. mbox->u.mqe.un.set_feature.param_len = 8;
  5173. break;
  5174. case LPFC_SET_MDS_DIAGS:
  5175. bf_set(lpfc_mbx_set_feature_mds,
  5176. &mbox->u.mqe.un.set_feature, 1);
  5177. bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
  5178. &mbox->u.mqe.un.set_feature, 0);
  5179. mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
  5180. mbox->u.mqe.un.set_feature.param_len = 8;
  5181. break;
  5182. }
  5183. return;
  5184. }
  5185. /**
  5186. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  5187. * @phba: Pointer to HBA context object.
  5188. *
  5189. * This function allocates all SLI4 resource identifiers.
  5190. **/
  5191. int
  5192. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  5193. {
  5194. int i, rc, error = 0;
  5195. uint16_t count, base;
  5196. unsigned long longs;
  5197. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5198. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  5199. if (phba->sli4_hba.extents_in_use) {
  5200. /*
  5201. * The port supports resource extents. The XRI, VPI, VFI, RPI
  5202. * resource extent count must be read and allocated before
  5203. * provisioning the resource id arrays.
  5204. */
  5205. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5206. LPFC_IDX_RSRC_RDY) {
  5207. /*
  5208. * Extent-based resources are set - the driver could
  5209. * be in a port reset. Figure out if any corrective
  5210. * actions need to be taken.
  5211. */
  5212. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5213. LPFC_RSC_TYPE_FCOE_VFI);
  5214. if (rc != 0)
  5215. error++;
  5216. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5217. LPFC_RSC_TYPE_FCOE_VPI);
  5218. if (rc != 0)
  5219. error++;
  5220. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5221. LPFC_RSC_TYPE_FCOE_XRI);
  5222. if (rc != 0)
  5223. error++;
  5224. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5225. LPFC_RSC_TYPE_FCOE_RPI);
  5226. if (rc != 0)
  5227. error++;
  5228. /*
  5229. * It's possible that the number of resources
  5230. * provided to this port instance changed between
  5231. * resets. Detect this condition and reallocate
  5232. * resources. Otherwise, there is no action.
  5233. */
  5234. if (error) {
  5235. lpfc_printf_log(phba, KERN_INFO,
  5236. LOG_MBOX | LOG_INIT,
  5237. "2931 Detected extent resource "
  5238. "change. Reallocating all "
  5239. "extents.\n");
  5240. rc = lpfc_sli4_dealloc_extent(phba,
  5241. LPFC_RSC_TYPE_FCOE_VFI);
  5242. rc = lpfc_sli4_dealloc_extent(phba,
  5243. LPFC_RSC_TYPE_FCOE_VPI);
  5244. rc = lpfc_sli4_dealloc_extent(phba,
  5245. LPFC_RSC_TYPE_FCOE_XRI);
  5246. rc = lpfc_sli4_dealloc_extent(phba,
  5247. LPFC_RSC_TYPE_FCOE_RPI);
  5248. } else
  5249. return 0;
  5250. }
  5251. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5252. if (unlikely(rc))
  5253. goto err_exit;
  5254. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5255. if (unlikely(rc))
  5256. goto err_exit;
  5257. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5258. if (unlikely(rc))
  5259. goto err_exit;
  5260. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5261. if (unlikely(rc))
  5262. goto err_exit;
  5263. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5264. LPFC_IDX_RSRC_RDY);
  5265. return rc;
  5266. } else {
  5267. /*
  5268. * The port does not support resource extents. The XRI, VPI,
  5269. * VFI, RPI resource ids were determined from READ_CONFIG.
  5270. * Just allocate the bitmasks and provision the resource id
  5271. * arrays. If a port reset is active, the resources don't
  5272. * need any action - just exit.
  5273. */
  5274. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5275. LPFC_IDX_RSRC_RDY) {
  5276. lpfc_sli4_dealloc_resource_identifiers(phba);
  5277. lpfc_sli4_remove_rpis(phba);
  5278. }
  5279. /* RPIs. */
  5280. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5281. if (count <= 0) {
  5282. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5283. "3279 Invalid provisioning of "
  5284. "rpi:%d\n", count);
  5285. rc = -EINVAL;
  5286. goto err_exit;
  5287. }
  5288. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5289. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5290. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5291. sizeof(unsigned long),
  5292. GFP_KERNEL);
  5293. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5294. rc = -ENOMEM;
  5295. goto err_exit;
  5296. }
  5297. phba->sli4_hba.rpi_ids = kzalloc(count *
  5298. sizeof(uint16_t),
  5299. GFP_KERNEL);
  5300. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5301. rc = -ENOMEM;
  5302. goto free_rpi_bmask;
  5303. }
  5304. for (i = 0; i < count; i++)
  5305. phba->sli4_hba.rpi_ids[i] = base + i;
  5306. /* VPIs. */
  5307. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5308. if (count <= 0) {
  5309. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5310. "3280 Invalid provisioning of "
  5311. "vpi:%d\n", count);
  5312. rc = -EINVAL;
  5313. goto free_rpi_ids;
  5314. }
  5315. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5316. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5317. phba->vpi_bmask = kzalloc(longs *
  5318. sizeof(unsigned long),
  5319. GFP_KERNEL);
  5320. if (unlikely(!phba->vpi_bmask)) {
  5321. rc = -ENOMEM;
  5322. goto free_rpi_ids;
  5323. }
  5324. phba->vpi_ids = kzalloc(count *
  5325. sizeof(uint16_t),
  5326. GFP_KERNEL);
  5327. if (unlikely(!phba->vpi_ids)) {
  5328. rc = -ENOMEM;
  5329. goto free_vpi_bmask;
  5330. }
  5331. for (i = 0; i < count; i++)
  5332. phba->vpi_ids[i] = base + i;
  5333. /* XRIs. */
  5334. count = phba->sli4_hba.max_cfg_param.max_xri;
  5335. if (count <= 0) {
  5336. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5337. "3281 Invalid provisioning of "
  5338. "xri:%d\n", count);
  5339. rc = -EINVAL;
  5340. goto free_vpi_ids;
  5341. }
  5342. base = phba->sli4_hba.max_cfg_param.xri_base;
  5343. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5344. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5345. sizeof(unsigned long),
  5346. GFP_KERNEL);
  5347. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5348. rc = -ENOMEM;
  5349. goto free_vpi_ids;
  5350. }
  5351. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5352. phba->sli4_hba.xri_ids = kzalloc(count *
  5353. sizeof(uint16_t),
  5354. GFP_KERNEL);
  5355. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5356. rc = -ENOMEM;
  5357. goto free_xri_bmask;
  5358. }
  5359. for (i = 0; i < count; i++)
  5360. phba->sli4_hba.xri_ids[i] = base + i;
  5361. /* VFIs. */
  5362. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5363. if (count <= 0) {
  5364. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5365. "3282 Invalid provisioning of "
  5366. "vfi:%d\n", count);
  5367. rc = -EINVAL;
  5368. goto free_xri_ids;
  5369. }
  5370. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5371. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5372. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5373. sizeof(unsigned long),
  5374. GFP_KERNEL);
  5375. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5376. rc = -ENOMEM;
  5377. goto free_xri_ids;
  5378. }
  5379. phba->sli4_hba.vfi_ids = kzalloc(count *
  5380. sizeof(uint16_t),
  5381. GFP_KERNEL);
  5382. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5383. rc = -ENOMEM;
  5384. goto free_vfi_bmask;
  5385. }
  5386. for (i = 0; i < count; i++)
  5387. phba->sli4_hba.vfi_ids[i] = base + i;
  5388. /*
  5389. * Mark all resources ready. An HBA reset doesn't need
  5390. * to reset the initialization.
  5391. */
  5392. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5393. LPFC_IDX_RSRC_RDY);
  5394. return 0;
  5395. }
  5396. free_vfi_bmask:
  5397. kfree(phba->sli4_hba.vfi_bmask);
  5398. phba->sli4_hba.vfi_bmask = NULL;
  5399. free_xri_ids:
  5400. kfree(phba->sli4_hba.xri_ids);
  5401. phba->sli4_hba.xri_ids = NULL;
  5402. free_xri_bmask:
  5403. kfree(phba->sli4_hba.xri_bmask);
  5404. phba->sli4_hba.xri_bmask = NULL;
  5405. free_vpi_ids:
  5406. kfree(phba->vpi_ids);
  5407. phba->vpi_ids = NULL;
  5408. free_vpi_bmask:
  5409. kfree(phba->vpi_bmask);
  5410. phba->vpi_bmask = NULL;
  5411. free_rpi_ids:
  5412. kfree(phba->sli4_hba.rpi_ids);
  5413. phba->sli4_hba.rpi_ids = NULL;
  5414. free_rpi_bmask:
  5415. kfree(phba->sli4_hba.rpi_bmask);
  5416. phba->sli4_hba.rpi_bmask = NULL;
  5417. err_exit:
  5418. return rc;
  5419. }
  5420. /**
  5421. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5422. * @phba: Pointer to HBA context object.
  5423. *
  5424. * This function allocates the number of elements for the specified
  5425. * resource type.
  5426. **/
  5427. int
  5428. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5429. {
  5430. if (phba->sli4_hba.extents_in_use) {
  5431. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5432. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5433. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5434. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5435. } else {
  5436. kfree(phba->vpi_bmask);
  5437. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5438. kfree(phba->vpi_ids);
  5439. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5440. kfree(phba->sli4_hba.xri_bmask);
  5441. kfree(phba->sli4_hba.xri_ids);
  5442. kfree(phba->sli4_hba.vfi_bmask);
  5443. kfree(phba->sli4_hba.vfi_ids);
  5444. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5445. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5446. }
  5447. return 0;
  5448. }
  5449. /**
  5450. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5451. * @phba: Pointer to HBA context object.
  5452. * @type: The resource extent type.
  5453. * @extnt_count: buffer to hold port extent count response
  5454. * @extnt_size: buffer to hold port extent size response.
  5455. *
  5456. * This function calls the port to read the host allocated extents
  5457. * for a particular type.
  5458. **/
  5459. int
  5460. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5461. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5462. {
  5463. bool emb;
  5464. int rc = 0;
  5465. uint16_t curr_blks = 0;
  5466. uint32_t req_len, emb_len;
  5467. uint32_t alloc_len, mbox_tmo;
  5468. struct list_head *blk_list_head;
  5469. struct lpfc_rsrc_blks *rsrc_blk;
  5470. LPFC_MBOXQ_t *mbox;
  5471. void *virtaddr = NULL;
  5472. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5473. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5474. union lpfc_sli4_cfg_shdr *shdr;
  5475. switch (type) {
  5476. case LPFC_RSC_TYPE_FCOE_VPI:
  5477. blk_list_head = &phba->lpfc_vpi_blk_list;
  5478. break;
  5479. case LPFC_RSC_TYPE_FCOE_XRI:
  5480. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5481. break;
  5482. case LPFC_RSC_TYPE_FCOE_VFI:
  5483. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5484. break;
  5485. case LPFC_RSC_TYPE_FCOE_RPI:
  5486. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5487. break;
  5488. default:
  5489. return -EIO;
  5490. }
  5491. /* Count the number of extents currently allocatd for this type. */
  5492. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5493. if (curr_blks == 0) {
  5494. /*
  5495. * The GET_ALLOCATED mailbox does not return the size,
  5496. * just the count. The size should be just the size
  5497. * stored in the current allocated block and all sizes
  5498. * for an extent type are the same so set the return
  5499. * value now.
  5500. */
  5501. *extnt_size = rsrc_blk->rsrc_size;
  5502. }
  5503. curr_blks++;
  5504. }
  5505. /*
  5506. * Calculate the size of an embedded mailbox. The uint32_t
  5507. * accounts for extents-specific word.
  5508. */
  5509. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5510. sizeof(uint32_t);
  5511. /*
  5512. * Presume the allocation and response will fit into an embedded
  5513. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5514. */
  5515. emb = LPFC_SLI4_MBX_EMBED;
  5516. req_len = emb_len;
  5517. if (req_len > emb_len) {
  5518. req_len = curr_blks * sizeof(uint16_t) +
  5519. sizeof(union lpfc_sli4_cfg_shdr) +
  5520. sizeof(uint32_t);
  5521. emb = LPFC_SLI4_MBX_NEMBED;
  5522. }
  5523. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5524. if (!mbox)
  5525. return -ENOMEM;
  5526. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5527. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5528. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5529. req_len, emb);
  5530. if (alloc_len < req_len) {
  5531. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5532. "2983 Allocated DMA memory size (x%x) is "
  5533. "less than the requested DMA memory "
  5534. "size (x%x)\n", alloc_len, req_len);
  5535. rc = -ENOMEM;
  5536. goto err_exit;
  5537. }
  5538. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5539. if (unlikely(rc)) {
  5540. rc = -EIO;
  5541. goto err_exit;
  5542. }
  5543. if (!phba->sli4_hba.intr_enable)
  5544. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5545. else {
  5546. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5547. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5548. }
  5549. if (unlikely(rc)) {
  5550. rc = -EIO;
  5551. goto err_exit;
  5552. }
  5553. /*
  5554. * Figure out where the response is located. Then get local pointers
  5555. * to the response data. The port does not guarantee to respond to
  5556. * all extents counts request so update the local variable with the
  5557. * allocated count from the port.
  5558. */
  5559. if (emb == LPFC_SLI4_MBX_EMBED) {
  5560. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5561. shdr = &rsrc_ext->header.cfg_shdr;
  5562. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5563. } else {
  5564. virtaddr = mbox->sge_array->addr[0];
  5565. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5566. shdr = &n_rsrc->cfg_shdr;
  5567. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5568. }
  5569. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5570. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5571. "2984 Failed to read allocated resources "
  5572. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5573. type,
  5574. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5575. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5576. rc = -EIO;
  5577. goto err_exit;
  5578. }
  5579. err_exit:
  5580. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5581. return rc;
  5582. }
  5583. /**
  5584. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5585. * @phba: pointer to lpfc hba data structure.
  5586. *
  5587. * This routine walks the list of els buffers that have been allocated and
  5588. * repost them to the port by using SGL block post. This is needed after a
  5589. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5590. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5591. * SGL block post mailbox commands to post them to the port. For single els
  5592. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5593. * mailbox command for posting.
  5594. *
  5595. * Returns: 0 = success, non-zero failure.
  5596. **/
  5597. static int
  5598. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5599. {
  5600. struct lpfc_sglq *sglq_entry = NULL;
  5601. struct lpfc_sglq *sglq_entry_next = NULL;
  5602. struct lpfc_sglq *sglq_entry_first = NULL;
  5603. int status, total_cnt, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5604. int last_xritag = NO_XRI;
  5605. struct lpfc_sli_ring *pring;
  5606. LIST_HEAD(prep_sgl_list);
  5607. LIST_HEAD(blck_sgl_list);
  5608. LIST_HEAD(allc_sgl_list);
  5609. LIST_HEAD(post_sgl_list);
  5610. LIST_HEAD(free_sgl_list);
  5611. pring = &phba->sli.ring[LPFC_ELS_RING];
  5612. spin_lock_irq(&phba->hbalock);
  5613. spin_lock(&pring->ring_lock);
  5614. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5615. spin_unlock(&pring->ring_lock);
  5616. spin_unlock_irq(&phba->hbalock);
  5617. total_cnt = phba->sli4_hba.els_xri_cnt;
  5618. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5619. &allc_sgl_list, list) {
  5620. list_del_init(&sglq_entry->list);
  5621. block_cnt++;
  5622. if ((last_xritag != NO_XRI) &&
  5623. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5624. /* a hole in xri block, form a sgl posting block */
  5625. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5626. post_cnt = block_cnt - 1;
  5627. /* prepare list for next posting block */
  5628. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5629. block_cnt = 1;
  5630. } else {
  5631. /* prepare list for next posting block */
  5632. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5633. /* enough sgls for non-embed sgl mbox command */
  5634. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5635. list_splice_init(&prep_sgl_list,
  5636. &blck_sgl_list);
  5637. post_cnt = block_cnt;
  5638. block_cnt = 0;
  5639. }
  5640. }
  5641. num_posted++;
  5642. /* keep track of last sgl's xritag */
  5643. last_xritag = sglq_entry->sli4_xritag;
  5644. /* end of repost sgl list condition for els buffers */
  5645. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5646. if (post_cnt == 0) {
  5647. list_splice_init(&prep_sgl_list,
  5648. &blck_sgl_list);
  5649. post_cnt = block_cnt;
  5650. } else if (block_cnt == 1) {
  5651. status = lpfc_sli4_post_sgl(phba,
  5652. sglq_entry->phys, 0,
  5653. sglq_entry->sli4_xritag);
  5654. if (!status) {
  5655. /* successful, put sgl to posted list */
  5656. list_add_tail(&sglq_entry->list,
  5657. &post_sgl_list);
  5658. } else {
  5659. /* Failure, put sgl to free list */
  5660. lpfc_printf_log(phba, KERN_WARNING,
  5661. LOG_SLI,
  5662. "3159 Failed to post els "
  5663. "sgl, xritag:x%x\n",
  5664. sglq_entry->sli4_xritag);
  5665. list_add_tail(&sglq_entry->list,
  5666. &free_sgl_list);
  5667. total_cnt--;
  5668. }
  5669. }
  5670. }
  5671. /* continue until a nembed page worth of sgls */
  5672. if (post_cnt == 0)
  5673. continue;
  5674. /* post the els buffer list sgls as a block */
  5675. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5676. post_cnt);
  5677. if (!status) {
  5678. /* success, put sgl list to posted sgl list */
  5679. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5680. } else {
  5681. /* Failure, put sgl list to free sgl list */
  5682. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5683. struct lpfc_sglq,
  5684. list);
  5685. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5686. "3160 Failed to post els sgl-list, "
  5687. "xritag:x%x-x%x\n",
  5688. sglq_entry_first->sli4_xritag,
  5689. (sglq_entry_first->sli4_xritag +
  5690. post_cnt - 1));
  5691. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5692. total_cnt -= post_cnt;
  5693. }
  5694. /* don't reset xirtag due to hole in xri block */
  5695. if (block_cnt == 0)
  5696. last_xritag = NO_XRI;
  5697. /* reset els sgl post count for next round of posting */
  5698. post_cnt = 0;
  5699. }
  5700. /* update the number of XRIs posted for ELS */
  5701. phba->sli4_hba.els_xri_cnt = total_cnt;
  5702. /* free the els sgls failed to post */
  5703. lpfc_free_sgl_list(phba, &free_sgl_list);
  5704. /* push els sgls posted to the availble list */
  5705. if (!list_empty(&post_sgl_list)) {
  5706. spin_lock_irq(&phba->hbalock);
  5707. spin_lock(&pring->ring_lock);
  5708. list_splice_init(&post_sgl_list,
  5709. &phba->sli4_hba.lpfc_sgl_list);
  5710. spin_unlock(&pring->ring_lock);
  5711. spin_unlock_irq(&phba->hbalock);
  5712. } else {
  5713. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5714. "3161 Failure to post els sgl to port.\n");
  5715. return -EIO;
  5716. }
  5717. return 0;
  5718. }
  5719. /**
  5720. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5721. * @phba: Pointer to HBA context object.
  5722. *
  5723. * This function is the main SLI4 device intialization PCI function. This
  5724. * function is called by the HBA intialization code, HBA reset code and
  5725. * HBA error attention handler code. Caller is not required to hold any
  5726. * locks.
  5727. **/
  5728. int
  5729. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5730. {
  5731. int rc;
  5732. LPFC_MBOXQ_t *mboxq;
  5733. struct lpfc_mqe *mqe;
  5734. uint8_t *vpd;
  5735. uint32_t vpd_size;
  5736. uint32_t ftr_rsp = 0;
  5737. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5738. struct lpfc_vport *vport = phba->pport;
  5739. struct lpfc_dmabuf *mp;
  5740. /* Perform a PCI function reset to start from clean */
  5741. rc = lpfc_pci_function_reset(phba);
  5742. if (unlikely(rc))
  5743. return -ENODEV;
  5744. /* Check the HBA Host Status Register for readyness */
  5745. rc = lpfc_sli4_post_status_check(phba);
  5746. if (unlikely(rc))
  5747. return -ENODEV;
  5748. else {
  5749. spin_lock_irq(&phba->hbalock);
  5750. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5751. spin_unlock_irq(&phba->hbalock);
  5752. }
  5753. /*
  5754. * Allocate a single mailbox container for initializing the
  5755. * port.
  5756. */
  5757. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5758. if (!mboxq)
  5759. return -ENOMEM;
  5760. /* Issue READ_REV to collect vpd and FW information. */
  5761. vpd_size = SLI4_PAGE_SIZE;
  5762. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5763. if (!vpd) {
  5764. rc = -ENOMEM;
  5765. goto out_free_mbox;
  5766. }
  5767. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5768. if (unlikely(rc)) {
  5769. kfree(vpd);
  5770. goto out_free_mbox;
  5771. }
  5772. mqe = &mboxq->u.mqe;
  5773. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5774. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
  5775. phba->hba_flag |= HBA_FCOE_MODE;
  5776. phba->fcp_embed_io = 0; /* SLI4 FC support only */
  5777. } else {
  5778. phba->hba_flag &= ~HBA_FCOE_MODE;
  5779. }
  5780. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5781. LPFC_DCBX_CEE_MODE)
  5782. phba->hba_flag |= HBA_FIP_SUPPORT;
  5783. else
  5784. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5785. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5786. if (phba->sli_rev != LPFC_SLI_REV4) {
  5787. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5788. "0376 READ_REV Error. SLI Level %d "
  5789. "FCoE enabled %d\n",
  5790. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5791. rc = -EIO;
  5792. kfree(vpd);
  5793. goto out_free_mbox;
  5794. }
  5795. /*
  5796. * Continue initialization with default values even if driver failed
  5797. * to read FCoE param config regions, only read parameters if the
  5798. * board is FCoE
  5799. */
  5800. if (phba->hba_flag & HBA_FCOE_MODE &&
  5801. lpfc_sli4_read_fcoe_params(phba))
  5802. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5803. "2570 Failed to read FCoE parameters\n");
  5804. /*
  5805. * Retrieve sli4 device physical port name, failure of doing it
  5806. * is considered as non-fatal.
  5807. */
  5808. rc = lpfc_sli4_retrieve_pport_name(phba);
  5809. if (!rc)
  5810. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5811. "3080 Successful retrieving SLI4 device "
  5812. "physical port name: %s.\n", phba->Port);
  5813. /*
  5814. * Evaluate the read rev and vpd data. Populate the driver
  5815. * state with the results. If this routine fails, the failure
  5816. * is not fatal as the driver will use generic values.
  5817. */
  5818. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5819. if (unlikely(!rc)) {
  5820. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5821. "0377 Error %d parsing vpd. "
  5822. "Using defaults.\n", rc);
  5823. rc = 0;
  5824. }
  5825. kfree(vpd);
  5826. /* Save information as VPD data */
  5827. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5828. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5829. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5830. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5831. &mqe->un.read_rev);
  5832. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5833. &mqe->un.read_rev);
  5834. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5835. &mqe->un.read_rev);
  5836. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5837. &mqe->un.read_rev);
  5838. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5839. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5840. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5841. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5842. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5843. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5844. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5845. "(%d):0380 READ_REV Status x%x "
  5846. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5847. mboxq->vport ? mboxq->vport->vpi : 0,
  5848. bf_get(lpfc_mqe_status, mqe),
  5849. phba->vpd.rev.opFwName,
  5850. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5851. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5852. /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
  5853. rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3);
  5854. if (phba->pport->cfg_lun_queue_depth > rc) {
  5855. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5856. "3362 LUN queue depth changed from %d to %d\n",
  5857. phba->pport->cfg_lun_queue_depth, rc);
  5858. phba->pport->cfg_lun_queue_depth = rc;
  5859. }
  5860. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  5861. LPFC_SLI_INTF_IF_TYPE_0) {
  5862. lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
  5863. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5864. if (rc == MBX_SUCCESS) {
  5865. phba->hba_flag |= HBA_RECOVERABLE_UE;
  5866. /* Set 1Sec interval to detect UE */
  5867. phba->eratt_poll_interval = 1;
  5868. phba->sli4_hba.ue_to_sr = bf_get(
  5869. lpfc_mbx_set_feature_UESR,
  5870. &mboxq->u.mqe.un.set_feature);
  5871. phba->sli4_hba.ue_to_rp = bf_get(
  5872. lpfc_mbx_set_feature_UERP,
  5873. &mboxq->u.mqe.un.set_feature);
  5874. }
  5875. }
  5876. if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
  5877. /* Enable MDS Diagnostics only if the SLI Port supports it */
  5878. lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
  5879. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5880. if (rc != MBX_SUCCESS)
  5881. phba->mds_diags_support = 0;
  5882. }
  5883. /*
  5884. * Discover the port's supported feature set and match it against the
  5885. * hosts requests.
  5886. */
  5887. lpfc_request_features(phba, mboxq);
  5888. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5889. if (unlikely(rc)) {
  5890. rc = -EIO;
  5891. goto out_free_mbox;
  5892. }
  5893. /*
  5894. * The port must support FCP initiator mode as this is the
  5895. * only mode running in the host.
  5896. */
  5897. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5898. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5899. "0378 No support for fcpi mode.\n");
  5900. ftr_rsp++;
  5901. }
  5902. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5903. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5904. else
  5905. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5906. /*
  5907. * If the port cannot support the host's requested features
  5908. * then turn off the global config parameters to disable the
  5909. * feature in the driver. This is not a fatal error.
  5910. */
  5911. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5912. if (phba->cfg_enable_bg) {
  5913. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5914. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5915. else
  5916. ftr_rsp++;
  5917. }
  5918. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5919. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5920. ftr_rsp++;
  5921. if (ftr_rsp) {
  5922. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5923. "0379 Feature Mismatch Data: x%08x %08x "
  5924. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5925. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5926. phba->cfg_enable_npiv, phba->max_vpi);
  5927. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5928. phba->cfg_enable_bg = 0;
  5929. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5930. phba->cfg_enable_npiv = 0;
  5931. }
  5932. /* These SLI3 features are assumed in SLI4 */
  5933. spin_lock_irq(&phba->hbalock);
  5934. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5935. spin_unlock_irq(&phba->hbalock);
  5936. /*
  5937. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5938. * calls depends on these resources to complete port setup.
  5939. */
  5940. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5941. if (rc) {
  5942. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5943. "2920 Failed to alloc Resource IDs "
  5944. "rc = x%x\n", rc);
  5945. goto out_free_mbox;
  5946. }
  5947. /* Read the port's service parameters. */
  5948. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5949. if (rc) {
  5950. phba->link_state = LPFC_HBA_ERROR;
  5951. rc = -ENOMEM;
  5952. goto out_free_mbox;
  5953. }
  5954. mboxq->vport = vport;
  5955. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5956. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5957. if (rc == MBX_SUCCESS) {
  5958. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5959. rc = 0;
  5960. }
  5961. /*
  5962. * This memory was allocated by the lpfc_read_sparam routine. Release
  5963. * it to the mbuf pool.
  5964. */
  5965. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5966. kfree(mp);
  5967. mboxq->context1 = NULL;
  5968. if (unlikely(rc)) {
  5969. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5970. "0382 READ_SPARAM command failed "
  5971. "status %d, mbxStatus x%x\n",
  5972. rc, bf_get(lpfc_mqe_status, mqe));
  5973. phba->link_state = LPFC_HBA_ERROR;
  5974. rc = -EIO;
  5975. goto out_free_mbox;
  5976. }
  5977. lpfc_update_vport_wwn(vport);
  5978. /* Update the fc_host data structures with new wwn. */
  5979. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5980. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5981. /* update host els and scsi xri-sgl sizes and mappings */
  5982. rc = lpfc_sli4_xri_sgl_update(phba);
  5983. if (unlikely(rc)) {
  5984. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5985. "1400 Failed to update xri-sgl size and "
  5986. "mapping: %d\n", rc);
  5987. goto out_free_mbox;
  5988. }
  5989. /* register the els sgl pool to the port */
  5990. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5991. if (unlikely(rc)) {
  5992. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5993. "0582 Error %d during els sgl post "
  5994. "operation\n", rc);
  5995. rc = -ENODEV;
  5996. goto out_free_mbox;
  5997. }
  5998. /* register the allocated scsi sgl pool to the port */
  5999. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  6000. if (unlikely(rc)) {
  6001. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6002. "0383 Error %d during scsi sgl post "
  6003. "operation\n", rc);
  6004. /* Some Scsi buffers were moved to the abort scsi list */
  6005. /* A pci function reset will repost them */
  6006. rc = -ENODEV;
  6007. goto out_free_mbox;
  6008. }
  6009. /* Post the rpi header region to the device. */
  6010. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  6011. if (unlikely(rc)) {
  6012. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6013. "0393 Error %d during rpi post operation\n",
  6014. rc);
  6015. rc = -ENODEV;
  6016. goto out_free_mbox;
  6017. }
  6018. lpfc_sli4_node_prep(phba);
  6019. /* Create all the SLI4 queues */
  6020. rc = lpfc_sli4_queue_create(phba);
  6021. if (rc) {
  6022. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6023. "3089 Failed to allocate queues\n");
  6024. rc = -ENODEV;
  6025. goto out_stop_timers;
  6026. }
  6027. /* Set up all the queues to the device */
  6028. rc = lpfc_sli4_queue_setup(phba);
  6029. if (unlikely(rc)) {
  6030. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6031. "0381 Error %d during queue setup.\n ", rc);
  6032. goto out_destroy_queue;
  6033. }
  6034. /* Arm the CQs and then EQs on device */
  6035. lpfc_sli4_arm_cqeq_intr(phba);
  6036. /* Indicate device interrupt mode */
  6037. phba->sli4_hba.intr_enable = 1;
  6038. /* Allow asynchronous mailbox command to go through */
  6039. spin_lock_irq(&phba->hbalock);
  6040. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6041. spin_unlock_irq(&phba->hbalock);
  6042. /* Post receive buffers to the device */
  6043. lpfc_sli4_rb_setup(phba);
  6044. /* Reset HBA FCF states after HBA reset */
  6045. phba->fcf.fcf_flag = 0;
  6046. phba->fcf.current_rec.flag = 0;
  6047. /* Start the ELS watchdog timer */
  6048. mod_timer(&vport->els_tmofunc,
  6049. jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
  6050. /* Start heart beat timer */
  6051. mod_timer(&phba->hb_tmofunc,
  6052. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  6053. phba->hb_outstanding = 0;
  6054. phba->last_completion_time = jiffies;
  6055. /* Start error attention (ERATT) polling timer */
  6056. mod_timer(&phba->eratt_poll,
  6057. jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
  6058. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  6059. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  6060. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  6061. if (!rc) {
  6062. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6063. "2829 This device supports "
  6064. "Advanced Error Reporting (AER)\n");
  6065. spin_lock_irq(&phba->hbalock);
  6066. phba->hba_flag |= HBA_AER_ENABLED;
  6067. spin_unlock_irq(&phba->hbalock);
  6068. } else {
  6069. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6070. "2830 This device does not support "
  6071. "Advanced Error Reporting (AER)\n");
  6072. phba->cfg_aer_support = 0;
  6073. }
  6074. rc = 0;
  6075. }
  6076. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  6077. /*
  6078. * The FC Port needs to register FCFI (index 0)
  6079. */
  6080. lpfc_reg_fcfi(phba, mboxq);
  6081. mboxq->vport = phba->pport;
  6082. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6083. if (rc != MBX_SUCCESS)
  6084. goto out_unset_queue;
  6085. rc = 0;
  6086. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  6087. &mboxq->u.mqe.un.reg_fcfi);
  6088. /* Check if the port is configured to be disabled */
  6089. lpfc_sli_read_link_ste(phba);
  6090. }
  6091. /*
  6092. * The port is ready, set the host's link state to LINK_DOWN
  6093. * in preparation for link interrupts.
  6094. */
  6095. spin_lock_irq(&phba->hbalock);
  6096. phba->link_state = LPFC_LINK_DOWN;
  6097. spin_unlock_irq(&phba->hbalock);
  6098. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  6099. (phba->hba_flag & LINK_DISABLED)) {
  6100. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  6101. "3103 Adapter Link is disabled.\n");
  6102. lpfc_down_link(phba, mboxq);
  6103. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6104. if (rc != MBX_SUCCESS) {
  6105. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  6106. "3104 Adapter failed to issue "
  6107. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  6108. goto out_unset_queue;
  6109. }
  6110. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  6111. /* don't perform init_link on SLI4 FC port loopback test */
  6112. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  6113. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  6114. if (rc)
  6115. goto out_unset_queue;
  6116. }
  6117. }
  6118. mempool_free(mboxq, phba->mbox_mem_pool);
  6119. return rc;
  6120. out_unset_queue:
  6121. /* Unset all the queues set up in this routine when error out */
  6122. lpfc_sli4_queue_unset(phba);
  6123. out_destroy_queue:
  6124. lpfc_sli4_queue_destroy(phba);
  6125. out_stop_timers:
  6126. lpfc_stop_hba_timers(phba);
  6127. out_free_mbox:
  6128. mempool_free(mboxq, phba->mbox_mem_pool);
  6129. return rc;
  6130. }
  6131. /**
  6132. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  6133. * @ptr: context object - pointer to hba structure.
  6134. *
  6135. * This is the callback function for mailbox timer. The mailbox
  6136. * timer is armed when a new mailbox command is issued and the timer
  6137. * is deleted when the mailbox complete. The function is called by
  6138. * the kernel timer code when a mailbox does not complete within
  6139. * expected time. This function wakes up the worker thread to
  6140. * process the mailbox timeout and returns. All the processing is
  6141. * done by the worker thread function lpfc_mbox_timeout_handler.
  6142. **/
  6143. void
  6144. lpfc_mbox_timeout(unsigned long ptr)
  6145. {
  6146. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  6147. unsigned long iflag;
  6148. uint32_t tmo_posted;
  6149. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  6150. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  6151. if (!tmo_posted)
  6152. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  6153. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  6154. if (!tmo_posted)
  6155. lpfc_worker_wake_up(phba);
  6156. return;
  6157. }
  6158. /**
  6159. * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
  6160. * are pending
  6161. * @phba: Pointer to HBA context object.
  6162. *
  6163. * This function checks if any mailbox completions are present on the mailbox
  6164. * completion queue.
  6165. **/
  6166. static bool
  6167. lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
  6168. {
  6169. uint32_t idx;
  6170. struct lpfc_queue *mcq;
  6171. struct lpfc_mcqe *mcqe;
  6172. bool pending_completions = false;
  6173. if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
  6174. return false;
  6175. /* Check for completions on mailbox completion queue */
  6176. mcq = phba->sli4_hba.mbx_cq;
  6177. idx = mcq->hba_index;
  6178. while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) {
  6179. mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe;
  6180. if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
  6181. (!bf_get_le32(lpfc_trailer_async, mcqe))) {
  6182. pending_completions = true;
  6183. break;
  6184. }
  6185. idx = (idx + 1) % mcq->entry_count;
  6186. if (mcq->hba_index == idx)
  6187. break;
  6188. }
  6189. return pending_completions;
  6190. }
  6191. /**
  6192. * lpfc_sli4_process_missed_mbox_completions - process mbox completions
  6193. * that were missed.
  6194. * @phba: Pointer to HBA context object.
  6195. *
  6196. * For sli4, it is possible to miss an interrupt. As such mbox completions
  6197. * maybe missed causing erroneous mailbox timeouts to occur. This function
  6198. * checks to see if mbox completions are on the mailbox completion queue
  6199. * and will process all the completions associated with the eq for the
  6200. * mailbox completion queue.
  6201. **/
  6202. bool
  6203. lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
  6204. {
  6205. uint32_t eqidx;
  6206. struct lpfc_queue *fpeq = NULL;
  6207. struct lpfc_eqe *eqe;
  6208. bool mbox_pending;
  6209. if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
  6210. return false;
  6211. /* Find the eq associated with the mcq */
  6212. if (phba->sli4_hba.hba_eq)
  6213. for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++)
  6214. if (phba->sli4_hba.hba_eq[eqidx]->queue_id ==
  6215. phba->sli4_hba.mbx_cq->assoc_qid) {
  6216. fpeq = phba->sli4_hba.hba_eq[eqidx];
  6217. break;
  6218. }
  6219. if (!fpeq)
  6220. return false;
  6221. /* Turn off interrupts from this EQ */
  6222. lpfc_sli4_eq_clr_intr(fpeq);
  6223. /* Check to see if a mbox completion is pending */
  6224. mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
  6225. /*
  6226. * If a mbox completion is pending, process all the events on EQ
  6227. * associated with the mbox completion queue (this could include
  6228. * mailbox commands, async events, els commands, receive queue data
  6229. * and fcp commands)
  6230. */
  6231. if (mbox_pending)
  6232. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  6233. lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx);
  6234. fpeq->EQ_processed++;
  6235. }
  6236. /* Always clear and re-arm the EQ */
  6237. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  6238. return mbox_pending;
  6239. }
  6240. /**
  6241. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  6242. * @phba: Pointer to HBA context object.
  6243. *
  6244. * This function is called from worker thread when a mailbox command times out.
  6245. * The caller is not required to hold any locks. This function will reset the
  6246. * HBA and recover all the pending commands.
  6247. **/
  6248. void
  6249. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  6250. {
  6251. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  6252. MAILBOX_t *mb = NULL;
  6253. struct lpfc_sli *psli = &phba->sli;
  6254. /* If the mailbox completed, process the completion and return */
  6255. if (lpfc_sli4_process_missed_mbox_completions(phba))
  6256. return;
  6257. if (pmbox != NULL)
  6258. mb = &pmbox->u.mb;
  6259. /* Check the pmbox pointer first. There is a race condition
  6260. * between the mbox timeout handler getting executed in the
  6261. * worklist and the mailbox actually completing. When this
  6262. * race condition occurs, the mbox_active will be NULL.
  6263. */
  6264. spin_lock_irq(&phba->hbalock);
  6265. if (pmbox == NULL) {
  6266. lpfc_printf_log(phba, KERN_WARNING,
  6267. LOG_MBOX | LOG_SLI,
  6268. "0353 Active Mailbox cleared - mailbox timeout "
  6269. "exiting\n");
  6270. spin_unlock_irq(&phba->hbalock);
  6271. return;
  6272. }
  6273. /* Mbox cmd <mbxCommand> timeout */
  6274. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6275. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  6276. mb->mbxCommand,
  6277. phba->pport->port_state,
  6278. phba->sli.sli_flag,
  6279. phba->sli.mbox_active);
  6280. spin_unlock_irq(&phba->hbalock);
  6281. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  6282. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  6283. * it to fail all outstanding SCSI IO.
  6284. */
  6285. spin_lock_irq(&phba->pport->work_port_lock);
  6286. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6287. spin_unlock_irq(&phba->pport->work_port_lock);
  6288. spin_lock_irq(&phba->hbalock);
  6289. phba->link_state = LPFC_LINK_UNKNOWN;
  6290. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6291. spin_unlock_irq(&phba->hbalock);
  6292. lpfc_sli_abort_fcp_rings(phba);
  6293. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6294. "0345 Resetting board due to mailbox timeout\n");
  6295. /* Reset the HBA device */
  6296. lpfc_reset_hba(phba);
  6297. }
  6298. /**
  6299. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  6300. * @phba: Pointer to HBA context object.
  6301. * @pmbox: Pointer to mailbox object.
  6302. * @flag: Flag indicating how the mailbox need to be processed.
  6303. *
  6304. * This function is called by discovery code and HBA management code
  6305. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  6306. * function gets the hbalock to protect the data structures.
  6307. * The mailbox command can be submitted in polling mode, in which case
  6308. * this function will wait in a polling loop for the completion of the
  6309. * mailbox.
  6310. * If the mailbox is submitted in no_wait mode (not polling) the
  6311. * function will submit the command and returns immediately without waiting
  6312. * for the mailbox completion. The no_wait is supported only when HBA
  6313. * is in SLI2/SLI3 mode - interrupts are enabled.
  6314. * The SLI interface allows only one mailbox pending at a time. If the
  6315. * mailbox is issued in polling mode and there is already a mailbox
  6316. * pending, then the function will return an error. If the mailbox is issued
  6317. * in NO_WAIT mode and there is a mailbox pending already, the function
  6318. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  6319. * The sli layer owns the mailbox object until the completion of mailbox
  6320. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  6321. * return codes the caller owns the mailbox command after the return of
  6322. * the function.
  6323. **/
  6324. static int
  6325. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  6326. uint32_t flag)
  6327. {
  6328. MAILBOX_t *mbx;
  6329. struct lpfc_sli *psli = &phba->sli;
  6330. uint32_t status, evtctr;
  6331. uint32_t ha_copy, hc_copy;
  6332. int i;
  6333. unsigned long timeout;
  6334. unsigned long drvr_flag = 0;
  6335. uint32_t word0, ldata;
  6336. void __iomem *to_slim;
  6337. int processing_queue = 0;
  6338. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6339. if (!pmbox) {
  6340. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6341. /* processing mbox queue from intr_handler */
  6342. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6343. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6344. return MBX_SUCCESS;
  6345. }
  6346. processing_queue = 1;
  6347. pmbox = lpfc_mbox_get(phba);
  6348. if (!pmbox) {
  6349. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6350. return MBX_SUCCESS;
  6351. }
  6352. }
  6353. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  6354. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  6355. if(!pmbox->vport) {
  6356. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6357. lpfc_printf_log(phba, KERN_ERR,
  6358. LOG_MBOX | LOG_VPORT,
  6359. "1806 Mbox x%x failed. No vport\n",
  6360. pmbox->u.mb.mbxCommand);
  6361. dump_stack();
  6362. goto out_not_finished;
  6363. }
  6364. }
  6365. /* If the PCI channel is in offline state, do not post mbox. */
  6366. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6367. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6368. goto out_not_finished;
  6369. }
  6370. /* If HBA has a deferred error attention, fail the iocb. */
  6371. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6372. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6373. goto out_not_finished;
  6374. }
  6375. psli = &phba->sli;
  6376. mbx = &pmbox->u.mb;
  6377. status = MBX_SUCCESS;
  6378. if (phba->link_state == LPFC_HBA_ERROR) {
  6379. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6380. /* Mbox command <mbxCommand> cannot issue */
  6381. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6382. "(%d):0311 Mailbox command x%x cannot "
  6383. "issue Data: x%x x%x\n",
  6384. pmbox->vport ? pmbox->vport->vpi : 0,
  6385. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6386. goto out_not_finished;
  6387. }
  6388. if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6389. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6390. !(hc_copy & HC_MBINT_ENA)) {
  6391. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6392. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6393. "(%d):2528 Mailbox command x%x cannot "
  6394. "issue Data: x%x x%x\n",
  6395. pmbox->vport ? pmbox->vport->vpi : 0,
  6396. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6397. goto out_not_finished;
  6398. }
  6399. }
  6400. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6401. /* Polling for a mbox command when another one is already active
  6402. * is not allowed in SLI. Also, the driver must have established
  6403. * SLI2 mode to queue and process multiple mbox commands.
  6404. */
  6405. if (flag & MBX_POLL) {
  6406. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6407. /* Mbox command <mbxCommand> cannot issue */
  6408. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6409. "(%d):2529 Mailbox command x%x "
  6410. "cannot issue Data: x%x x%x\n",
  6411. pmbox->vport ? pmbox->vport->vpi : 0,
  6412. pmbox->u.mb.mbxCommand,
  6413. psli->sli_flag, flag);
  6414. goto out_not_finished;
  6415. }
  6416. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6417. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6418. /* Mbox command <mbxCommand> cannot issue */
  6419. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6420. "(%d):2530 Mailbox command x%x "
  6421. "cannot issue Data: x%x x%x\n",
  6422. pmbox->vport ? pmbox->vport->vpi : 0,
  6423. pmbox->u.mb.mbxCommand,
  6424. psli->sli_flag, flag);
  6425. goto out_not_finished;
  6426. }
  6427. /* Another mailbox command is still being processed, queue this
  6428. * command to be processed later.
  6429. */
  6430. lpfc_mbox_put(phba, pmbox);
  6431. /* Mbox cmd issue - BUSY */
  6432. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6433. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6434. "x%x x%x x%x x%x\n",
  6435. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6436. mbx->mbxCommand, phba->pport->port_state,
  6437. psli->sli_flag, flag);
  6438. psli->slistat.mbox_busy++;
  6439. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6440. if (pmbox->vport) {
  6441. lpfc_debugfs_disc_trc(pmbox->vport,
  6442. LPFC_DISC_TRC_MBOX_VPORT,
  6443. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6444. (uint32_t)mbx->mbxCommand,
  6445. mbx->un.varWords[0], mbx->un.varWords[1]);
  6446. }
  6447. else {
  6448. lpfc_debugfs_disc_trc(phba->pport,
  6449. LPFC_DISC_TRC_MBOX,
  6450. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6451. (uint32_t)mbx->mbxCommand,
  6452. mbx->un.varWords[0], mbx->un.varWords[1]);
  6453. }
  6454. return MBX_BUSY;
  6455. }
  6456. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6457. /* If we are not polling, we MUST be in SLI2 mode */
  6458. if (flag != MBX_POLL) {
  6459. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6460. (mbx->mbxCommand != MBX_KILL_BOARD)) {
  6461. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6462. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6463. /* Mbox command <mbxCommand> cannot issue */
  6464. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6465. "(%d):2531 Mailbox command x%x "
  6466. "cannot issue Data: x%x x%x\n",
  6467. pmbox->vport ? pmbox->vport->vpi : 0,
  6468. pmbox->u.mb.mbxCommand,
  6469. psli->sli_flag, flag);
  6470. goto out_not_finished;
  6471. }
  6472. /* timeout active mbox command */
  6473. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6474. 1000);
  6475. mod_timer(&psli->mbox_tmo, jiffies + timeout);
  6476. }
  6477. /* Mailbox cmd <cmd> issue */
  6478. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6479. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6480. "x%x\n",
  6481. pmbox->vport ? pmbox->vport->vpi : 0,
  6482. mbx->mbxCommand, phba->pport->port_state,
  6483. psli->sli_flag, flag);
  6484. if (mbx->mbxCommand != MBX_HEARTBEAT) {
  6485. if (pmbox->vport) {
  6486. lpfc_debugfs_disc_trc(pmbox->vport,
  6487. LPFC_DISC_TRC_MBOX_VPORT,
  6488. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6489. (uint32_t)mbx->mbxCommand,
  6490. mbx->un.varWords[0], mbx->un.varWords[1]);
  6491. }
  6492. else {
  6493. lpfc_debugfs_disc_trc(phba->pport,
  6494. LPFC_DISC_TRC_MBOX,
  6495. "MBOX Send: cmd:x%x mb:x%x x%x",
  6496. (uint32_t)mbx->mbxCommand,
  6497. mbx->un.varWords[0], mbx->un.varWords[1]);
  6498. }
  6499. }
  6500. psli->slistat.mbox_cmd++;
  6501. evtctr = psli->slistat.mbox_event;
  6502. /* next set own bit for the adapter and copy over command word */
  6503. mbx->mbxOwner = OWN_CHIP;
  6504. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6505. /* Populate mbox extension offset word. */
  6506. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6507. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6508. = (uint8_t *)phba->mbox_ext
  6509. - (uint8_t *)phba->mbox;
  6510. }
  6511. /* Copy the mailbox extension data */
  6512. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6513. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6514. (uint8_t *)phba->mbox_ext,
  6515. pmbox->in_ext_byte_len);
  6516. }
  6517. /* Copy command data to host SLIM area */
  6518. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6519. } else {
  6520. /* Populate mbox extension offset word. */
  6521. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6522. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6523. = MAILBOX_HBA_EXT_OFFSET;
  6524. /* Copy the mailbox extension data */
  6525. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6526. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6527. MAILBOX_HBA_EXT_OFFSET,
  6528. pmbox->context2, pmbox->in_ext_byte_len);
  6529. }
  6530. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6531. /* copy command data into host mbox for cmpl */
  6532. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6533. }
  6534. /* First copy mbox command data to HBA SLIM, skip past first
  6535. word */
  6536. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6537. lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
  6538. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6539. /* Next copy over first word, with mbxOwner set */
  6540. ldata = *((uint32_t *)mbx);
  6541. to_slim = phba->MBslimaddr;
  6542. writel(ldata, to_slim);
  6543. readl(to_slim); /* flush */
  6544. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6545. /* switch over to host mailbox */
  6546. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6547. }
  6548. }
  6549. wmb();
  6550. switch (flag) {
  6551. case MBX_NOWAIT:
  6552. /* Set up reference to mailbox command */
  6553. psli->mbox_active = pmbox;
  6554. /* Interrupt board to do it */
  6555. writel(CA_MBATT, phba->CAregaddr);
  6556. readl(phba->CAregaddr); /* flush */
  6557. /* Don't wait for it to finish, just return */
  6558. break;
  6559. case MBX_POLL:
  6560. /* Set up null reference to mailbox command */
  6561. psli->mbox_active = NULL;
  6562. /* Interrupt board to do it */
  6563. writel(CA_MBATT, phba->CAregaddr);
  6564. readl(phba->CAregaddr); /* flush */
  6565. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6566. /* First read mbox status word */
  6567. word0 = *((uint32_t *)phba->mbox);
  6568. word0 = le32_to_cpu(word0);
  6569. } else {
  6570. /* First read mbox status word */
  6571. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6572. spin_unlock_irqrestore(&phba->hbalock,
  6573. drvr_flag);
  6574. goto out_not_finished;
  6575. }
  6576. }
  6577. /* Read the HBA Host Attention Register */
  6578. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6579. spin_unlock_irqrestore(&phba->hbalock,
  6580. drvr_flag);
  6581. goto out_not_finished;
  6582. }
  6583. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6584. 1000) + jiffies;
  6585. i = 0;
  6586. /* Wait for command to complete */
  6587. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6588. (!(ha_copy & HA_MBATT) &&
  6589. (phba->link_state > LPFC_WARM_START))) {
  6590. if (time_after(jiffies, timeout)) {
  6591. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6592. spin_unlock_irqrestore(&phba->hbalock,
  6593. drvr_flag);
  6594. goto out_not_finished;
  6595. }
  6596. /* Check if we took a mbox interrupt while we were
  6597. polling */
  6598. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6599. && (evtctr != psli->slistat.mbox_event))
  6600. break;
  6601. if (i++ > 10) {
  6602. spin_unlock_irqrestore(&phba->hbalock,
  6603. drvr_flag);
  6604. msleep(1);
  6605. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6606. }
  6607. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6608. /* First copy command data */
  6609. word0 = *((uint32_t *)phba->mbox);
  6610. word0 = le32_to_cpu(word0);
  6611. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6612. MAILBOX_t *slimmb;
  6613. uint32_t slimword0;
  6614. /* Check real SLIM for any errors */
  6615. slimword0 = readl(phba->MBslimaddr);
  6616. slimmb = (MAILBOX_t *) & slimword0;
  6617. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6618. && slimmb->mbxStatus) {
  6619. psli->sli_flag &=
  6620. ~LPFC_SLI_ACTIVE;
  6621. word0 = slimword0;
  6622. }
  6623. }
  6624. } else {
  6625. /* First copy command data */
  6626. word0 = readl(phba->MBslimaddr);
  6627. }
  6628. /* Read the HBA Host Attention Register */
  6629. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6630. spin_unlock_irqrestore(&phba->hbalock,
  6631. drvr_flag);
  6632. goto out_not_finished;
  6633. }
  6634. }
  6635. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6636. /* copy results back to user */
  6637. lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE);
  6638. /* Copy the mailbox extension data */
  6639. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6640. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6641. pmbox->context2,
  6642. pmbox->out_ext_byte_len);
  6643. }
  6644. } else {
  6645. /* First copy command data */
  6646. lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
  6647. MAILBOX_CMD_SIZE);
  6648. /* Copy the mailbox extension data */
  6649. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6650. lpfc_memcpy_from_slim(pmbox->context2,
  6651. phba->MBslimaddr +
  6652. MAILBOX_HBA_EXT_OFFSET,
  6653. pmbox->out_ext_byte_len);
  6654. }
  6655. }
  6656. writel(HA_MBATT, phba->HAregaddr);
  6657. readl(phba->HAregaddr); /* flush */
  6658. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6659. status = mbx->mbxStatus;
  6660. }
  6661. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6662. return status;
  6663. out_not_finished:
  6664. if (processing_queue) {
  6665. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6666. lpfc_mbox_cmpl_put(phba, pmbox);
  6667. }
  6668. return MBX_NOT_FINISHED;
  6669. }
  6670. /**
  6671. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6672. * @phba: Pointer to HBA context object.
  6673. *
  6674. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6675. * the driver internal pending mailbox queue. It will then try to wait out the
  6676. * possible outstanding mailbox command before return.
  6677. *
  6678. * Returns:
  6679. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6680. * the outstanding mailbox command timed out.
  6681. **/
  6682. static int
  6683. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6684. {
  6685. struct lpfc_sli *psli = &phba->sli;
  6686. int rc = 0;
  6687. unsigned long timeout = 0;
  6688. /* Mark the asynchronous mailbox command posting as blocked */
  6689. spin_lock_irq(&phba->hbalock);
  6690. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6691. /* Determine how long we might wait for the active mailbox
  6692. * command to be gracefully completed by firmware.
  6693. */
  6694. if (phba->sli.mbox_active)
  6695. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6696. phba->sli.mbox_active) *
  6697. 1000) + jiffies;
  6698. spin_unlock_irq(&phba->hbalock);
  6699. /* Make sure the mailbox is really active */
  6700. if (timeout)
  6701. lpfc_sli4_process_missed_mbox_completions(phba);
  6702. /* Wait for the outstnading mailbox command to complete */
  6703. while (phba->sli.mbox_active) {
  6704. /* Check active mailbox complete status every 2ms */
  6705. msleep(2);
  6706. if (time_after(jiffies, timeout)) {
  6707. /* Timeout, marked the outstanding cmd not complete */
  6708. rc = 1;
  6709. break;
  6710. }
  6711. }
  6712. /* Can not cleanly block async mailbox command, fails it */
  6713. if (rc) {
  6714. spin_lock_irq(&phba->hbalock);
  6715. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6716. spin_unlock_irq(&phba->hbalock);
  6717. }
  6718. return rc;
  6719. }
  6720. /**
  6721. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6722. * @phba: Pointer to HBA context object.
  6723. *
  6724. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6725. * commands from the driver internal pending mailbox queue. It makes sure
  6726. * that there is no outstanding mailbox command before resuming posting
  6727. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6728. * mailbox command, it will try to wait it out before resuming asynchronous
  6729. * mailbox command posting.
  6730. **/
  6731. static void
  6732. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6733. {
  6734. struct lpfc_sli *psli = &phba->sli;
  6735. spin_lock_irq(&phba->hbalock);
  6736. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6737. /* Asynchronous mailbox posting is not blocked, do nothing */
  6738. spin_unlock_irq(&phba->hbalock);
  6739. return;
  6740. }
  6741. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6742. * successful or timeout, after timing-out the outstanding mailbox
  6743. * command shall always be removed, so just unblock posting async
  6744. * mailbox command and resume
  6745. */
  6746. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6747. spin_unlock_irq(&phba->hbalock);
  6748. /* wake up worker thread to post asynchronlous mailbox command */
  6749. lpfc_worker_wake_up(phba);
  6750. }
  6751. /**
  6752. * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
  6753. * @phba: Pointer to HBA context object.
  6754. * @mboxq: Pointer to mailbox object.
  6755. *
  6756. * The function waits for the bootstrap mailbox register ready bit from
  6757. * port for twice the regular mailbox command timeout value.
  6758. *
  6759. * 0 - no timeout on waiting for bootstrap mailbox register ready.
  6760. * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
  6761. **/
  6762. static int
  6763. lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6764. {
  6765. uint32_t db_ready;
  6766. unsigned long timeout;
  6767. struct lpfc_register bmbx_reg;
  6768. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6769. * 1000) + jiffies;
  6770. do {
  6771. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6772. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6773. if (!db_ready)
  6774. msleep(2);
  6775. if (time_after(jiffies, timeout))
  6776. return MBXERR_ERROR;
  6777. } while (!db_ready);
  6778. return 0;
  6779. }
  6780. /**
  6781. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6782. * @phba: Pointer to HBA context object.
  6783. * @mboxq: Pointer to mailbox object.
  6784. *
  6785. * The function posts a mailbox to the port. The mailbox is expected
  6786. * to be comletely filled in and ready for the port to operate on it.
  6787. * This routine executes a synchronous completion operation on the
  6788. * mailbox by polling for its completion.
  6789. *
  6790. * The caller must not be holding any locks when calling this routine.
  6791. *
  6792. * Returns:
  6793. * MBX_SUCCESS - mailbox posted successfully
  6794. * Any of the MBX error values.
  6795. **/
  6796. static int
  6797. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6798. {
  6799. int rc = MBX_SUCCESS;
  6800. unsigned long iflag;
  6801. uint32_t mcqe_status;
  6802. uint32_t mbx_cmnd;
  6803. struct lpfc_sli *psli = &phba->sli;
  6804. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6805. struct lpfc_bmbx_create *mbox_rgn;
  6806. struct dma_address *dma_address;
  6807. /*
  6808. * Only one mailbox can be active to the bootstrap mailbox region
  6809. * at a time and there is no queueing provided.
  6810. */
  6811. spin_lock_irqsave(&phba->hbalock, iflag);
  6812. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6813. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6814. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6815. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6816. "cannot issue Data: x%x x%x\n",
  6817. mboxq->vport ? mboxq->vport->vpi : 0,
  6818. mboxq->u.mb.mbxCommand,
  6819. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6820. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6821. psli->sli_flag, MBX_POLL);
  6822. return MBXERR_ERROR;
  6823. }
  6824. /* The server grabs the token and owns it until release */
  6825. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6826. phba->sli.mbox_active = mboxq;
  6827. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6828. /* wait for bootstrap mbox register for readyness */
  6829. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6830. if (rc)
  6831. goto exit;
  6832. /*
  6833. * Initialize the bootstrap memory region to avoid stale data areas
  6834. * in the mailbox post. Then copy the caller's mailbox contents to
  6835. * the bmbx mailbox region.
  6836. */
  6837. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6838. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6839. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6840. sizeof(struct lpfc_mqe));
  6841. /* Post the high mailbox dma address to the port and wait for ready. */
  6842. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6843. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6844. /* wait for bootstrap mbox register for hi-address write done */
  6845. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6846. if (rc)
  6847. goto exit;
  6848. /* Post the low mailbox dma address to the port. */
  6849. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6850. /* wait for bootstrap mbox register for low address write done */
  6851. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6852. if (rc)
  6853. goto exit;
  6854. /*
  6855. * Read the CQ to ensure the mailbox has completed.
  6856. * If so, update the mailbox status so that the upper layers
  6857. * can complete the request normally.
  6858. */
  6859. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6860. sizeof(struct lpfc_mqe));
  6861. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6862. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6863. sizeof(struct lpfc_mcqe));
  6864. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6865. /*
  6866. * When the CQE status indicates a failure and the mailbox status
  6867. * indicates success then copy the CQE status into the mailbox status
  6868. * (and prefix it with x4000).
  6869. */
  6870. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6871. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6872. bf_set(lpfc_mqe_status, mb,
  6873. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6874. rc = MBXERR_ERROR;
  6875. } else
  6876. lpfc_sli4_swap_str(phba, mboxq);
  6877. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6878. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6879. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6880. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6881. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6882. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6883. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6884. bf_get(lpfc_mqe_status, mb),
  6885. mb->un.mb_words[0], mb->un.mb_words[1],
  6886. mb->un.mb_words[2], mb->un.mb_words[3],
  6887. mb->un.mb_words[4], mb->un.mb_words[5],
  6888. mb->un.mb_words[6], mb->un.mb_words[7],
  6889. mb->un.mb_words[8], mb->un.mb_words[9],
  6890. mb->un.mb_words[10], mb->un.mb_words[11],
  6891. mb->un.mb_words[12], mboxq->mcqe.word0,
  6892. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6893. mboxq->mcqe.trailer);
  6894. exit:
  6895. /* We are holding the token, no needed for lock when release */
  6896. spin_lock_irqsave(&phba->hbalock, iflag);
  6897. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6898. phba->sli.mbox_active = NULL;
  6899. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6900. return rc;
  6901. }
  6902. /**
  6903. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6904. * @phba: Pointer to HBA context object.
  6905. * @pmbox: Pointer to mailbox object.
  6906. * @flag: Flag indicating how the mailbox need to be processed.
  6907. *
  6908. * This function is called by discovery code and HBA management code to submit
  6909. * a mailbox command to firmware with SLI-4 interface spec.
  6910. *
  6911. * Return codes the caller owns the mailbox command after the return of the
  6912. * function.
  6913. **/
  6914. static int
  6915. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6916. uint32_t flag)
  6917. {
  6918. struct lpfc_sli *psli = &phba->sli;
  6919. unsigned long iflags;
  6920. int rc;
  6921. /* dump from issue mailbox command if setup */
  6922. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6923. rc = lpfc_mbox_dev_check(phba);
  6924. if (unlikely(rc)) {
  6925. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6926. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6927. "cannot issue Data: x%x x%x\n",
  6928. mboxq->vport ? mboxq->vport->vpi : 0,
  6929. mboxq->u.mb.mbxCommand,
  6930. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6931. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6932. psli->sli_flag, flag);
  6933. goto out_not_finished;
  6934. }
  6935. /* Detect polling mode and jump to a handler */
  6936. if (!phba->sli4_hba.intr_enable) {
  6937. if (flag == MBX_POLL)
  6938. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6939. else
  6940. rc = -EIO;
  6941. if (rc != MBX_SUCCESS)
  6942. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6943. "(%d):2541 Mailbox command x%x "
  6944. "(x%x/x%x) failure: "
  6945. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6946. "Data: x%x x%x\n,",
  6947. mboxq->vport ? mboxq->vport->vpi : 0,
  6948. mboxq->u.mb.mbxCommand,
  6949. lpfc_sli_config_mbox_subsys_get(phba,
  6950. mboxq),
  6951. lpfc_sli_config_mbox_opcode_get(phba,
  6952. mboxq),
  6953. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6954. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6955. bf_get(lpfc_mcqe_ext_status,
  6956. &mboxq->mcqe),
  6957. psli->sli_flag, flag);
  6958. return rc;
  6959. } else if (flag == MBX_POLL) {
  6960. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6961. "(%d):2542 Try to issue mailbox command "
  6962. "x%x (x%x/x%x) synchronously ahead of async"
  6963. "mailbox command queue: x%x x%x\n",
  6964. mboxq->vport ? mboxq->vport->vpi : 0,
  6965. mboxq->u.mb.mbxCommand,
  6966. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6967. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6968. psli->sli_flag, flag);
  6969. /* Try to block the asynchronous mailbox posting */
  6970. rc = lpfc_sli4_async_mbox_block(phba);
  6971. if (!rc) {
  6972. /* Successfully blocked, now issue sync mbox cmd */
  6973. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6974. if (rc != MBX_SUCCESS)
  6975. lpfc_printf_log(phba, KERN_WARNING,
  6976. LOG_MBOX | LOG_SLI,
  6977. "(%d):2597 Sync Mailbox command "
  6978. "x%x (x%x/x%x) failure: "
  6979. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6980. "Data: x%x x%x\n,",
  6981. mboxq->vport ? mboxq->vport->vpi : 0,
  6982. mboxq->u.mb.mbxCommand,
  6983. lpfc_sli_config_mbox_subsys_get(phba,
  6984. mboxq),
  6985. lpfc_sli_config_mbox_opcode_get(phba,
  6986. mboxq),
  6987. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6988. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6989. bf_get(lpfc_mcqe_ext_status,
  6990. &mboxq->mcqe),
  6991. psli->sli_flag, flag);
  6992. /* Unblock the async mailbox posting afterward */
  6993. lpfc_sli4_async_mbox_unblock(phba);
  6994. }
  6995. return rc;
  6996. }
  6997. /* Now, interrupt mode asynchrous mailbox command */
  6998. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6999. if (rc) {
  7000. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  7001. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  7002. "cannot issue Data: x%x x%x\n",
  7003. mboxq->vport ? mboxq->vport->vpi : 0,
  7004. mboxq->u.mb.mbxCommand,
  7005. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7006. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7007. psli->sli_flag, flag);
  7008. goto out_not_finished;
  7009. }
  7010. /* Put the mailbox command to the driver internal FIFO */
  7011. psli->slistat.mbox_busy++;
  7012. spin_lock_irqsave(&phba->hbalock, iflags);
  7013. lpfc_mbox_put(phba, mboxq);
  7014. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7015. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  7016. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  7017. "x%x (x%x/x%x) x%x x%x x%x\n",
  7018. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  7019. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  7020. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7021. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7022. phba->pport->port_state,
  7023. psli->sli_flag, MBX_NOWAIT);
  7024. /* Wake up worker thread to transport mailbox command from head */
  7025. lpfc_worker_wake_up(phba);
  7026. return MBX_BUSY;
  7027. out_not_finished:
  7028. return MBX_NOT_FINISHED;
  7029. }
  7030. /**
  7031. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  7032. * @phba: Pointer to HBA context object.
  7033. *
  7034. * This function is called by worker thread to send a mailbox command to
  7035. * SLI4 HBA firmware.
  7036. *
  7037. **/
  7038. int
  7039. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  7040. {
  7041. struct lpfc_sli *psli = &phba->sli;
  7042. LPFC_MBOXQ_t *mboxq;
  7043. int rc = MBX_SUCCESS;
  7044. unsigned long iflags;
  7045. struct lpfc_mqe *mqe;
  7046. uint32_t mbx_cmnd;
  7047. /* Check interrupt mode before post async mailbox command */
  7048. if (unlikely(!phba->sli4_hba.intr_enable))
  7049. return MBX_NOT_FINISHED;
  7050. /* Check for mailbox command service token */
  7051. spin_lock_irqsave(&phba->hbalock, iflags);
  7052. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  7053. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7054. return MBX_NOT_FINISHED;
  7055. }
  7056. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  7057. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7058. return MBX_NOT_FINISHED;
  7059. }
  7060. if (unlikely(phba->sli.mbox_active)) {
  7061. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7062. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  7063. "0384 There is pending active mailbox cmd\n");
  7064. return MBX_NOT_FINISHED;
  7065. }
  7066. /* Take the mailbox command service token */
  7067. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  7068. /* Get the next mailbox command from head of queue */
  7069. mboxq = lpfc_mbox_get(phba);
  7070. /* If no more mailbox command waiting for post, we're done */
  7071. if (!mboxq) {
  7072. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7073. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7074. return MBX_SUCCESS;
  7075. }
  7076. phba->sli.mbox_active = mboxq;
  7077. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7078. /* Check device readiness for posting mailbox command */
  7079. rc = lpfc_mbox_dev_check(phba);
  7080. if (unlikely(rc))
  7081. /* Driver clean routine will clean up pending mailbox */
  7082. goto out_not_finished;
  7083. /* Prepare the mbox command to be posted */
  7084. mqe = &mboxq->u.mqe;
  7085. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  7086. /* Start timer for the mbox_tmo and log some mailbox post messages */
  7087. mod_timer(&psli->mbox_tmo, (jiffies +
  7088. msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
  7089. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  7090. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  7091. "x%x x%x\n",
  7092. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  7093. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7094. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7095. phba->pport->port_state, psli->sli_flag);
  7096. if (mbx_cmnd != MBX_HEARTBEAT) {
  7097. if (mboxq->vport) {
  7098. lpfc_debugfs_disc_trc(mboxq->vport,
  7099. LPFC_DISC_TRC_MBOX_VPORT,
  7100. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  7101. mbx_cmnd, mqe->un.mb_words[0],
  7102. mqe->un.mb_words[1]);
  7103. } else {
  7104. lpfc_debugfs_disc_trc(phba->pport,
  7105. LPFC_DISC_TRC_MBOX,
  7106. "MBOX Send: cmd:x%x mb:x%x x%x",
  7107. mbx_cmnd, mqe->un.mb_words[0],
  7108. mqe->un.mb_words[1]);
  7109. }
  7110. }
  7111. psli->slistat.mbox_cmd++;
  7112. /* Post the mailbox command to the port */
  7113. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  7114. if (rc != MBX_SUCCESS) {
  7115. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  7116. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  7117. "cannot issue Data: x%x x%x\n",
  7118. mboxq->vport ? mboxq->vport->vpi : 0,
  7119. mboxq->u.mb.mbxCommand,
  7120. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7121. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7122. psli->sli_flag, MBX_NOWAIT);
  7123. goto out_not_finished;
  7124. }
  7125. return rc;
  7126. out_not_finished:
  7127. spin_lock_irqsave(&phba->hbalock, iflags);
  7128. if (phba->sli.mbox_active) {
  7129. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  7130. __lpfc_mbox_cmpl_put(phba, mboxq);
  7131. /* Release the token */
  7132. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7133. phba->sli.mbox_active = NULL;
  7134. }
  7135. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7136. return MBX_NOT_FINISHED;
  7137. }
  7138. /**
  7139. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  7140. * @phba: Pointer to HBA context object.
  7141. * @pmbox: Pointer to mailbox object.
  7142. * @flag: Flag indicating how the mailbox need to be processed.
  7143. *
  7144. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  7145. * the API jump table function pointer from the lpfc_hba struct.
  7146. *
  7147. * Return codes the caller owns the mailbox command after the return of the
  7148. * function.
  7149. **/
  7150. int
  7151. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  7152. {
  7153. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  7154. }
  7155. /**
  7156. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  7157. * @phba: The hba struct for which this call is being executed.
  7158. * @dev_grp: The HBA PCI-Device group number.
  7159. *
  7160. * This routine sets up the mbox interface API function jump table in @phba
  7161. * struct.
  7162. * Returns: 0 - success, -ENODEV - failure.
  7163. **/
  7164. int
  7165. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7166. {
  7167. switch (dev_grp) {
  7168. case LPFC_PCI_DEV_LP:
  7169. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  7170. phba->lpfc_sli_handle_slow_ring_event =
  7171. lpfc_sli_handle_slow_ring_event_s3;
  7172. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  7173. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  7174. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  7175. break;
  7176. case LPFC_PCI_DEV_OC:
  7177. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  7178. phba->lpfc_sli_handle_slow_ring_event =
  7179. lpfc_sli_handle_slow_ring_event_s4;
  7180. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  7181. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  7182. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  7183. break;
  7184. default:
  7185. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7186. "1420 Invalid HBA PCI-device group: 0x%x\n",
  7187. dev_grp);
  7188. return -ENODEV;
  7189. break;
  7190. }
  7191. return 0;
  7192. }
  7193. /**
  7194. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  7195. * @phba: Pointer to HBA context object.
  7196. * @pring: Pointer to driver SLI ring object.
  7197. * @piocb: Pointer to address of newly added command iocb.
  7198. *
  7199. * This function is called with hbalock held to add a command
  7200. * iocb to the txq when SLI layer cannot submit the command iocb
  7201. * to the ring.
  7202. **/
  7203. void
  7204. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7205. struct lpfc_iocbq *piocb)
  7206. {
  7207. lockdep_assert_held(&phba->hbalock);
  7208. /* Insert the caller's iocb in the txq tail for later processing. */
  7209. list_add_tail(&piocb->list, &pring->txq);
  7210. }
  7211. /**
  7212. * lpfc_sli_next_iocb - Get the next iocb in the txq
  7213. * @phba: Pointer to HBA context object.
  7214. * @pring: Pointer to driver SLI ring object.
  7215. * @piocb: Pointer to address of newly added command iocb.
  7216. *
  7217. * This function is called with hbalock held before a new
  7218. * iocb is submitted to the firmware. This function checks
  7219. * txq to flush the iocbs in txq to Firmware before
  7220. * submitting new iocbs to the Firmware.
  7221. * If there are iocbs in the txq which need to be submitted
  7222. * to firmware, lpfc_sli_next_iocb returns the first element
  7223. * of the txq after dequeuing it from txq.
  7224. * If there is no iocb in the txq then the function will return
  7225. * *piocb and *piocb is set to NULL. Caller needs to check
  7226. * *piocb to find if there are more commands in the txq.
  7227. **/
  7228. static struct lpfc_iocbq *
  7229. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7230. struct lpfc_iocbq **piocb)
  7231. {
  7232. struct lpfc_iocbq * nextiocb;
  7233. lockdep_assert_held(&phba->hbalock);
  7234. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  7235. if (!nextiocb) {
  7236. nextiocb = *piocb;
  7237. *piocb = NULL;
  7238. }
  7239. return nextiocb;
  7240. }
  7241. /**
  7242. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  7243. * @phba: Pointer to HBA context object.
  7244. * @ring_number: SLI ring number to issue iocb on.
  7245. * @piocb: Pointer to command iocb.
  7246. * @flag: Flag indicating if this command can be put into txq.
  7247. *
  7248. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  7249. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  7250. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  7251. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  7252. * this function allows only iocbs for posting buffers. This function finds
  7253. * next available slot in the command ring and posts the command to the
  7254. * available slot and writes the port attention register to request HBA start
  7255. * processing new iocb. If there is no slot available in the ring and
  7256. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  7257. * the function returns IOCB_BUSY.
  7258. *
  7259. * This function is called with hbalock held. The function will return success
  7260. * after it successfully submit the iocb to firmware or after adding to the
  7261. * txq.
  7262. **/
  7263. static int
  7264. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  7265. struct lpfc_iocbq *piocb, uint32_t flag)
  7266. {
  7267. struct lpfc_iocbq *nextiocb;
  7268. IOCB_t *iocb;
  7269. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7270. lockdep_assert_held(&phba->hbalock);
  7271. if (piocb->iocb_cmpl && (!piocb->vport) &&
  7272. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  7273. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  7274. lpfc_printf_log(phba, KERN_ERR,
  7275. LOG_SLI | LOG_VPORT,
  7276. "1807 IOCB x%x failed. No vport\n",
  7277. piocb->iocb.ulpCommand);
  7278. dump_stack();
  7279. return IOCB_ERROR;
  7280. }
  7281. /* If the PCI channel is in offline state, do not post iocbs. */
  7282. if (unlikely(pci_channel_offline(phba->pcidev)))
  7283. return IOCB_ERROR;
  7284. /* If HBA has a deferred error attention, fail the iocb. */
  7285. if (unlikely(phba->hba_flag & DEFER_ERATT))
  7286. return IOCB_ERROR;
  7287. /*
  7288. * We should never get an IOCB if we are in a < LINK_DOWN state
  7289. */
  7290. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7291. return IOCB_ERROR;
  7292. /*
  7293. * Check to see if we are blocking IOCB processing because of a
  7294. * outstanding event.
  7295. */
  7296. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  7297. goto iocb_busy;
  7298. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  7299. /*
  7300. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  7301. * can be issued if the link is not up.
  7302. */
  7303. switch (piocb->iocb.ulpCommand) {
  7304. case CMD_GEN_REQUEST64_CR:
  7305. case CMD_GEN_REQUEST64_CX:
  7306. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  7307. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  7308. FC_RCTL_DD_UNSOL_CMD) ||
  7309. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  7310. MENLO_TRANSPORT_TYPE))
  7311. goto iocb_busy;
  7312. break;
  7313. case CMD_QUE_RING_BUF_CN:
  7314. case CMD_QUE_RING_BUF64_CN:
  7315. /*
  7316. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  7317. * completion, iocb_cmpl MUST be 0.
  7318. */
  7319. if (piocb->iocb_cmpl)
  7320. piocb->iocb_cmpl = NULL;
  7321. /*FALLTHROUGH*/
  7322. case CMD_CREATE_XRI_CR:
  7323. case CMD_CLOSE_XRI_CN:
  7324. case CMD_CLOSE_XRI_CX:
  7325. break;
  7326. default:
  7327. goto iocb_busy;
  7328. }
  7329. /*
  7330. * For FCP commands, we must be in a state where we can process link
  7331. * attention events.
  7332. */
  7333. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  7334. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  7335. goto iocb_busy;
  7336. }
  7337. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  7338. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  7339. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  7340. if (iocb)
  7341. lpfc_sli_update_ring(phba, pring);
  7342. else
  7343. lpfc_sli_update_full_ring(phba, pring);
  7344. if (!piocb)
  7345. return IOCB_SUCCESS;
  7346. goto out_busy;
  7347. iocb_busy:
  7348. pring->stats.iocb_cmd_delay++;
  7349. out_busy:
  7350. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7351. __lpfc_sli_ringtx_put(phba, pring, piocb);
  7352. return IOCB_SUCCESS;
  7353. }
  7354. return IOCB_BUSY;
  7355. }
  7356. /**
  7357. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  7358. * @phba: Pointer to HBA context object.
  7359. * @piocb: Pointer to command iocb.
  7360. * @sglq: Pointer to the scatter gather queue object.
  7361. *
  7362. * This routine converts the bpl or bde that is in the IOCB
  7363. * to a sgl list for the sli4 hardware. The physical address
  7364. * of the bpl/bde is converted back to a virtual address.
  7365. * If the IOCB contains a BPL then the list of BDE's is
  7366. * converted to sli4_sge's. If the IOCB contains a single
  7367. * BDE then it is converted to a single sli_sge.
  7368. * The IOCB is still in cpu endianess so the contents of
  7369. * the bpl can be used without byte swapping.
  7370. *
  7371. * Returns valid XRI = Success, NO_XRI = Failure.
  7372. **/
  7373. static uint16_t
  7374. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  7375. struct lpfc_sglq *sglq)
  7376. {
  7377. uint16_t xritag = NO_XRI;
  7378. struct ulp_bde64 *bpl = NULL;
  7379. struct ulp_bde64 bde;
  7380. struct sli4_sge *sgl = NULL;
  7381. struct lpfc_dmabuf *dmabuf;
  7382. IOCB_t *icmd;
  7383. int numBdes = 0;
  7384. int i = 0;
  7385. uint32_t offset = 0; /* accumulated offset in the sg request list */
  7386. int inbound = 0; /* number of sg reply entries inbound from firmware */
  7387. if (!piocbq || !sglq)
  7388. return xritag;
  7389. sgl = (struct sli4_sge *)sglq->sgl;
  7390. icmd = &piocbq->iocb;
  7391. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  7392. return sglq->sli4_xritag;
  7393. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7394. numBdes = icmd->un.genreq64.bdl.bdeSize /
  7395. sizeof(struct ulp_bde64);
  7396. /* The addrHigh and addrLow fields within the IOCB
  7397. * have not been byteswapped yet so there is no
  7398. * need to swap them back.
  7399. */
  7400. if (piocbq->context3)
  7401. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7402. else
  7403. return xritag;
  7404. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7405. if (!bpl)
  7406. return xritag;
  7407. for (i = 0; i < numBdes; i++) {
  7408. /* Should already be byte swapped. */
  7409. sgl->addr_hi = bpl->addrHigh;
  7410. sgl->addr_lo = bpl->addrLow;
  7411. sgl->word2 = le32_to_cpu(sgl->word2);
  7412. if ((i+1) == numBdes)
  7413. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7414. else
  7415. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7416. /* swap the size field back to the cpu so we
  7417. * can assign it to the sgl.
  7418. */
  7419. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7420. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7421. /* The offsets in the sgl need to be accumulated
  7422. * separately for the request and reply lists.
  7423. * The request is always first, the reply follows.
  7424. */
  7425. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7426. /* add up the reply sg entries */
  7427. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7428. inbound++;
  7429. /* first inbound? reset the offset */
  7430. if (inbound == 1)
  7431. offset = 0;
  7432. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7433. bf_set(lpfc_sli4_sge_type, sgl,
  7434. LPFC_SGE_TYPE_DATA);
  7435. offset += bde.tus.f.bdeSize;
  7436. }
  7437. sgl->word2 = cpu_to_le32(sgl->word2);
  7438. bpl++;
  7439. sgl++;
  7440. }
  7441. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7442. /* The addrHigh and addrLow fields of the BDE have not
  7443. * been byteswapped yet so they need to be swapped
  7444. * before putting them in the sgl.
  7445. */
  7446. sgl->addr_hi =
  7447. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7448. sgl->addr_lo =
  7449. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7450. sgl->word2 = le32_to_cpu(sgl->word2);
  7451. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7452. sgl->word2 = cpu_to_le32(sgl->word2);
  7453. sgl->sge_len =
  7454. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7455. }
  7456. return sglq->sli4_xritag;
  7457. }
  7458. /**
  7459. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7460. * @phba: Pointer to HBA context object.
  7461. * @piocb: Pointer to command iocb.
  7462. * @wqe: Pointer to the work queue entry.
  7463. *
  7464. * This routine converts the iocb command to its Work Queue Entry
  7465. * equivalent. The wqe pointer should not have any fields set when
  7466. * this routine is called because it will memcpy over them.
  7467. * This routine does not set the CQ_ID or the WQEC bits in the
  7468. * wqe.
  7469. *
  7470. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7471. **/
  7472. static int
  7473. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7474. union lpfc_wqe *wqe)
  7475. {
  7476. uint32_t xmit_len = 0, total_len = 0;
  7477. uint8_t ct = 0;
  7478. uint32_t fip;
  7479. uint32_t abort_tag;
  7480. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7481. uint8_t cmnd;
  7482. uint16_t xritag;
  7483. uint16_t abrt_iotag;
  7484. struct lpfc_iocbq *abrtiocbq;
  7485. struct ulp_bde64 *bpl = NULL;
  7486. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7487. int numBdes, i;
  7488. struct ulp_bde64 bde;
  7489. struct lpfc_nodelist *ndlp;
  7490. uint32_t *pcmd;
  7491. uint32_t if_type;
  7492. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7493. /* The fcp commands will set command type */
  7494. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7495. command_type = FCP_COMMAND;
  7496. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7497. command_type = ELS_COMMAND_FIP;
  7498. else
  7499. command_type = ELS_COMMAND_NON_FIP;
  7500. if (phba->fcp_embed_io)
  7501. memset(wqe, 0, sizeof(union lpfc_wqe128));
  7502. /* Some of the fields are in the right position already */
  7503. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7504. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7505. wqe->generic.wqe_com.word10 = 0;
  7506. abort_tag = (uint32_t) iocbq->iotag;
  7507. xritag = iocbq->sli4_xritag;
  7508. /* words0-2 bpl convert bde */
  7509. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7510. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7511. sizeof(struct ulp_bde64);
  7512. bpl = (struct ulp_bde64 *)
  7513. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7514. if (!bpl)
  7515. return IOCB_ERROR;
  7516. /* Should already be byte swapped. */
  7517. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7518. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7519. /* swap the size field back to the cpu so we
  7520. * can assign it to the sgl.
  7521. */
  7522. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7523. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7524. total_len = 0;
  7525. for (i = 0; i < numBdes; i++) {
  7526. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7527. total_len += bde.tus.f.bdeSize;
  7528. }
  7529. } else
  7530. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7531. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7532. cmnd = iocbq->iocb.ulpCommand;
  7533. switch (iocbq->iocb.ulpCommand) {
  7534. case CMD_ELS_REQUEST64_CR:
  7535. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7536. ndlp = iocbq->context_un.ndlp;
  7537. else
  7538. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7539. if (!iocbq->iocb.ulpLe) {
  7540. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7541. "2007 Only Limited Edition cmd Format"
  7542. " supported 0x%x\n",
  7543. iocbq->iocb.ulpCommand);
  7544. return IOCB_ERROR;
  7545. }
  7546. wqe->els_req.payload_len = xmit_len;
  7547. /* Els_reguest64 has a TMO */
  7548. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7549. iocbq->iocb.ulpTimeout);
  7550. /* Need a VF for word 4 set the vf bit*/
  7551. bf_set(els_req64_vf, &wqe->els_req, 0);
  7552. /* And a VFID for word 12 */
  7553. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7554. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7555. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7556. iocbq->iocb.ulpContext);
  7557. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7558. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7559. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7560. if (command_type == ELS_COMMAND_FIP)
  7561. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7562. >> LPFC_FIP_ELS_ID_SHIFT);
  7563. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7564. iocbq->context2)->virt);
  7565. if_type = bf_get(lpfc_sli_intf_if_type,
  7566. &phba->sli4_hba.sli_intf);
  7567. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7568. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7569. *pcmd == ELS_CMD_SCR ||
  7570. *pcmd == ELS_CMD_FDISC ||
  7571. *pcmd == ELS_CMD_LOGO ||
  7572. *pcmd == ELS_CMD_PLOGI)) {
  7573. bf_set(els_req64_sp, &wqe->els_req, 1);
  7574. bf_set(els_req64_sid, &wqe->els_req,
  7575. iocbq->vport->fc_myDID);
  7576. if ((*pcmd == ELS_CMD_FLOGI) &&
  7577. !(phba->fc_topology ==
  7578. LPFC_TOPOLOGY_LOOP))
  7579. bf_set(els_req64_sid, &wqe->els_req, 0);
  7580. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7581. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7582. phba->vpi_ids[iocbq->vport->vpi]);
  7583. } else if (pcmd && iocbq->context1) {
  7584. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7585. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7586. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7587. }
  7588. }
  7589. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7590. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7591. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7592. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7593. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7594. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7595. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7596. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7597. wqe->els_req.max_response_payload_len = total_len - xmit_len;
  7598. break;
  7599. case CMD_XMIT_SEQUENCE64_CX:
  7600. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7601. iocbq->iocb.un.ulpWord[3]);
  7602. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7603. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7604. /* The entire sequence is transmitted for this IOCB */
  7605. xmit_len = total_len;
  7606. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7607. if (phba->link_flag & LS_LOOPBACK_MODE)
  7608. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7609. case CMD_XMIT_SEQUENCE64_CR:
  7610. /* word3 iocb=io_tag32 wqe=reserved */
  7611. wqe->xmit_sequence.rsvd3 = 0;
  7612. /* word4 relative_offset memcpy */
  7613. /* word5 r_ctl/df_ctl memcpy */
  7614. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7615. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7616. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7617. LPFC_WQE_IOD_WRITE);
  7618. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7619. LPFC_WQE_LENLOC_WORD12);
  7620. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7621. wqe->xmit_sequence.xmit_len = xmit_len;
  7622. command_type = OTHER_COMMAND;
  7623. break;
  7624. case CMD_XMIT_BCAST64_CN:
  7625. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7626. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7627. /* word4 iocb=rsvd wqe=rsvd */
  7628. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7629. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7630. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7631. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7632. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7633. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7634. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7635. LPFC_WQE_LENLOC_WORD3);
  7636. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7637. break;
  7638. case CMD_FCP_IWRITE64_CR:
  7639. command_type = FCP_COMMAND_DATA_OUT;
  7640. /* word3 iocb=iotag wqe=payload_offset_len */
  7641. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7642. bf_set(payload_offset_len, &wqe->fcp_iwrite,
  7643. xmit_len + sizeof(struct fcp_rsp));
  7644. bf_set(cmd_buff_len, &wqe->fcp_iwrite,
  7645. 0);
  7646. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7647. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7648. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7649. iocbq->iocb.ulpFCP2Rcvy);
  7650. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7651. /* Always open the exchange */
  7652. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7653. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7654. LPFC_WQE_LENLOC_WORD4);
  7655. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7656. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7657. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7658. bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
  7659. bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
  7660. if (iocbq->priority) {
  7661. bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
  7662. (iocbq->priority << 1));
  7663. } else {
  7664. bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
  7665. (phba->cfg_XLanePriority << 1));
  7666. }
  7667. }
  7668. /* Note, word 10 is already initialized to 0 */
  7669. if (phba->fcp_embed_io) {
  7670. struct lpfc_scsi_buf *lpfc_cmd;
  7671. struct sli4_sge *sgl;
  7672. union lpfc_wqe128 *wqe128;
  7673. struct fcp_cmnd *fcp_cmnd;
  7674. uint32_t *ptr;
  7675. /* 128 byte wqe support here */
  7676. wqe128 = (union lpfc_wqe128 *)wqe;
  7677. lpfc_cmd = iocbq->context1;
  7678. sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  7679. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  7680. /* Word 0-2 - FCP_CMND */
  7681. wqe128->generic.bde.tus.f.bdeFlags =
  7682. BUFF_TYPE_BDE_IMMED;
  7683. wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
  7684. wqe128->generic.bde.addrHigh = 0;
  7685. wqe128->generic.bde.addrLow = 88; /* Word 22 */
  7686. bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1);
  7687. /* Word 22-29 FCP CMND Payload */
  7688. ptr = &wqe128->words[22];
  7689. memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
  7690. }
  7691. break;
  7692. case CMD_FCP_IREAD64_CR:
  7693. /* word3 iocb=iotag wqe=payload_offset_len */
  7694. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7695. bf_set(payload_offset_len, &wqe->fcp_iread,
  7696. xmit_len + sizeof(struct fcp_rsp));
  7697. bf_set(cmd_buff_len, &wqe->fcp_iread,
  7698. 0);
  7699. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7700. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7701. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7702. iocbq->iocb.ulpFCP2Rcvy);
  7703. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7704. /* Always open the exchange */
  7705. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7706. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7707. LPFC_WQE_LENLOC_WORD4);
  7708. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7709. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7710. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7711. bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
  7712. bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
  7713. if (iocbq->priority) {
  7714. bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
  7715. (iocbq->priority << 1));
  7716. } else {
  7717. bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
  7718. (phba->cfg_XLanePriority << 1));
  7719. }
  7720. }
  7721. /* Note, word 10 is already initialized to 0 */
  7722. if (phba->fcp_embed_io) {
  7723. struct lpfc_scsi_buf *lpfc_cmd;
  7724. struct sli4_sge *sgl;
  7725. union lpfc_wqe128 *wqe128;
  7726. struct fcp_cmnd *fcp_cmnd;
  7727. uint32_t *ptr;
  7728. /* 128 byte wqe support here */
  7729. wqe128 = (union lpfc_wqe128 *)wqe;
  7730. lpfc_cmd = iocbq->context1;
  7731. sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  7732. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  7733. /* Word 0-2 - FCP_CMND */
  7734. wqe128->generic.bde.tus.f.bdeFlags =
  7735. BUFF_TYPE_BDE_IMMED;
  7736. wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
  7737. wqe128->generic.bde.addrHigh = 0;
  7738. wqe128->generic.bde.addrLow = 88; /* Word 22 */
  7739. bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1);
  7740. /* Word 22-29 FCP CMND Payload */
  7741. ptr = &wqe128->words[22];
  7742. memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
  7743. }
  7744. break;
  7745. case CMD_FCP_ICMND64_CR:
  7746. /* word3 iocb=iotag wqe=payload_offset_len */
  7747. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7748. bf_set(payload_offset_len, &wqe->fcp_icmd,
  7749. xmit_len + sizeof(struct fcp_rsp));
  7750. bf_set(cmd_buff_len, &wqe->fcp_icmd,
  7751. 0);
  7752. /* word3 iocb=IO_TAG wqe=reserved */
  7753. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7754. /* Always open the exchange */
  7755. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7756. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7757. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7758. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7759. LPFC_WQE_LENLOC_NONE);
  7760. bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
  7761. iocbq->iocb.ulpFCP2Rcvy);
  7762. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7763. bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
  7764. bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
  7765. if (iocbq->priority) {
  7766. bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
  7767. (iocbq->priority << 1));
  7768. } else {
  7769. bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
  7770. (phba->cfg_XLanePriority << 1));
  7771. }
  7772. }
  7773. /* Note, word 10 is already initialized to 0 */
  7774. if (phba->fcp_embed_io) {
  7775. struct lpfc_scsi_buf *lpfc_cmd;
  7776. struct sli4_sge *sgl;
  7777. union lpfc_wqe128 *wqe128;
  7778. struct fcp_cmnd *fcp_cmnd;
  7779. uint32_t *ptr;
  7780. /* 128 byte wqe support here */
  7781. wqe128 = (union lpfc_wqe128 *)wqe;
  7782. lpfc_cmd = iocbq->context1;
  7783. sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  7784. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  7785. /* Word 0-2 - FCP_CMND */
  7786. wqe128->generic.bde.tus.f.bdeFlags =
  7787. BUFF_TYPE_BDE_IMMED;
  7788. wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
  7789. wqe128->generic.bde.addrHigh = 0;
  7790. wqe128->generic.bde.addrLow = 88; /* Word 22 */
  7791. bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1);
  7792. /* Word 22-29 FCP CMND Payload */
  7793. ptr = &wqe128->words[22];
  7794. memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
  7795. }
  7796. break;
  7797. case CMD_GEN_REQUEST64_CR:
  7798. /* For this command calculate the xmit length of the
  7799. * request bde.
  7800. */
  7801. xmit_len = 0;
  7802. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7803. sizeof(struct ulp_bde64);
  7804. for (i = 0; i < numBdes; i++) {
  7805. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7806. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7807. break;
  7808. xmit_len += bde.tus.f.bdeSize;
  7809. }
  7810. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7811. wqe->gen_req.request_payload_len = xmit_len;
  7812. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7813. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7814. /* word6 context tag copied in memcpy */
  7815. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7816. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7817. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7818. "2015 Invalid CT %x command 0x%x\n",
  7819. ct, iocbq->iocb.ulpCommand);
  7820. return IOCB_ERROR;
  7821. }
  7822. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7823. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7824. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7825. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7826. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7827. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7828. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7829. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7830. wqe->gen_req.max_response_payload_len = total_len - xmit_len;
  7831. command_type = OTHER_COMMAND;
  7832. break;
  7833. case CMD_XMIT_ELS_RSP64_CX:
  7834. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7835. /* words0-2 BDE memcpy */
  7836. /* word3 iocb=iotag32 wqe=response_payload_len */
  7837. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7838. /* word4 */
  7839. wqe->xmit_els_rsp.word4 = 0;
  7840. /* word5 iocb=rsvd wge=did */
  7841. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7842. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7843. if_type = bf_get(lpfc_sli_intf_if_type,
  7844. &phba->sli4_hba.sli_intf);
  7845. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7846. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7847. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7848. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7849. iocbq->vport->fc_myDID);
  7850. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7851. bf_set(wqe_els_did,
  7852. &wqe->xmit_els_rsp.wqe_dest, 0);
  7853. }
  7854. }
  7855. }
  7856. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7857. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7858. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7859. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7860. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7861. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7862. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7863. phba->vpi_ids[iocbq->vport->vpi]);
  7864. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7865. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7866. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7867. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7868. LPFC_WQE_LENLOC_WORD3);
  7869. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7870. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7871. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7872. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7873. iocbq->context2)->virt);
  7874. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7875. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7876. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7877. iocbq->vport->fc_myDID);
  7878. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7879. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7880. phba->vpi_ids[phba->pport->vpi]);
  7881. }
  7882. command_type = OTHER_COMMAND;
  7883. break;
  7884. case CMD_CLOSE_XRI_CN:
  7885. case CMD_ABORT_XRI_CN:
  7886. case CMD_ABORT_XRI_CX:
  7887. /* words 0-2 memcpy should be 0 rserved */
  7888. /* port will send abts */
  7889. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7890. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7891. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7892. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7893. } else
  7894. fip = 0;
  7895. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7896. /*
  7897. * The link is down, or the command was ELS_FIP
  7898. * so the fw does not need to send abts
  7899. * on the wire.
  7900. */
  7901. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7902. else
  7903. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7904. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7905. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7906. wqe->abort_cmd.rsrvd5 = 0;
  7907. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7908. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7909. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7910. /*
  7911. * The abort handler will send us CMD_ABORT_XRI_CN or
  7912. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7913. */
  7914. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7915. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7916. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7917. LPFC_WQE_LENLOC_NONE);
  7918. cmnd = CMD_ABORT_XRI_CX;
  7919. command_type = OTHER_COMMAND;
  7920. xritag = 0;
  7921. break;
  7922. case CMD_XMIT_BLS_RSP64_CX:
  7923. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7924. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7925. * we re-construct this WQE here based on information in
  7926. * iocbq from scratch.
  7927. */
  7928. memset(wqe, 0, sizeof(union lpfc_wqe));
  7929. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7930. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7931. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7932. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7933. LPFC_ABTS_UNSOL_INT) {
  7934. /* ABTS sent by initiator to CT exchange, the
  7935. * RX_ID field will be filled with the newly
  7936. * allocated responder XRI.
  7937. */
  7938. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7939. iocbq->sli4_xritag);
  7940. } else {
  7941. /* ABTS sent by responder to CT exchange, the
  7942. * RX_ID field will be filled with the responder
  7943. * RX_ID from ABTS.
  7944. */
  7945. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7946. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7947. }
  7948. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7949. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7950. /* Use CT=VPI */
  7951. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7952. ndlp->nlp_DID);
  7953. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7954. iocbq->iocb.ulpContext);
  7955. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7956. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7957. phba->vpi_ids[phba->pport->vpi]);
  7958. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7959. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7960. LPFC_WQE_LENLOC_NONE);
  7961. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7962. command_type = OTHER_COMMAND;
  7963. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7964. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7965. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7966. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7967. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7968. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7969. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7970. }
  7971. break;
  7972. case CMD_XRI_ABORTED_CX:
  7973. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7974. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7975. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7976. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7977. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7978. default:
  7979. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7980. "2014 Invalid command 0x%x\n",
  7981. iocbq->iocb.ulpCommand);
  7982. return IOCB_ERROR;
  7983. break;
  7984. }
  7985. if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
  7986. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
  7987. else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
  7988. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
  7989. else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
  7990. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
  7991. iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
  7992. LPFC_IO_DIF_INSERT);
  7993. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7994. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7995. wqe->generic.wqe_com.abort_tag = abort_tag;
  7996. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7997. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7998. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7999. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  8000. return 0;
  8001. }
  8002. /**
  8003. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  8004. * @phba: Pointer to HBA context object.
  8005. * @ring_number: SLI ring number to issue iocb on.
  8006. * @piocb: Pointer to command iocb.
  8007. * @flag: Flag indicating if this command can be put into txq.
  8008. *
  8009. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  8010. * an iocb command to an HBA with SLI-4 interface spec.
  8011. *
  8012. * This function is called with hbalock held. The function will return success
  8013. * after it successfully submit the iocb to firmware or after adding to the
  8014. * txq.
  8015. **/
  8016. static int
  8017. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  8018. struct lpfc_iocbq *piocb, uint32_t flag)
  8019. {
  8020. struct lpfc_sglq *sglq;
  8021. union lpfc_wqe *wqe;
  8022. union lpfc_wqe128 wqe128;
  8023. struct lpfc_queue *wq;
  8024. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  8025. lockdep_assert_held(&phba->hbalock);
  8026. /*
  8027. * The WQE can be either 64 or 128 bytes,
  8028. * so allocate space on the stack assuming the largest.
  8029. */
  8030. wqe = (union lpfc_wqe *)&wqe128;
  8031. if (piocb->sli4_xritag == NO_XRI) {
  8032. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  8033. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  8034. sglq = NULL;
  8035. else {
  8036. if (!list_empty(&pring->txq)) {
  8037. if (!(flag & SLI_IOCB_RET_IOCB)) {
  8038. __lpfc_sli_ringtx_put(phba,
  8039. pring, piocb);
  8040. return IOCB_SUCCESS;
  8041. } else {
  8042. return IOCB_BUSY;
  8043. }
  8044. } else {
  8045. sglq = __lpfc_sli_get_sglq(phba, piocb);
  8046. if (!sglq) {
  8047. if (!(flag & SLI_IOCB_RET_IOCB)) {
  8048. __lpfc_sli_ringtx_put(phba,
  8049. pring,
  8050. piocb);
  8051. return IOCB_SUCCESS;
  8052. } else
  8053. return IOCB_BUSY;
  8054. }
  8055. }
  8056. }
  8057. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  8058. /* These IO's already have an XRI and a mapped sgl. */
  8059. sglq = NULL;
  8060. } else {
  8061. /*
  8062. * This is a continuation of a commandi,(CX) so this
  8063. * sglq is on the active list
  8064. */
  8065. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
  8066. if (!sglq)
  8067. return IOCB_ERROR;
  8068. }
  8069. if (sglq) {
  8070. piocb->sli4_lxritag = sglq->sli4_lxritag;
  8071. piocb->sli4_xritag = sglq->sli4_xritag;
  8072. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  8073. return IOCB_ERROR;
  8074. }
  8075. if (lpfc_sli4_iocb2wqe(phba, piocb, wqe))
  8076. return IOCB_ERROR;
  8077. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  8078. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  8079. if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) {
  8080. wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx];
  8081. } else {
  8082. wq = phba->sli4_hba.oas_wq;
  8083. }
  8084. if (lpfc_sli4_wq_put(wq, wqe))
  8085. return IOCB_ERROR;
  8086. } else {
  8087. if (unlikely(!phba->sli4_hba.els_wq))
  8088. return IOCB_ERROR;
  8089. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe))
  8090. return IOCB_ERROR;
  8091. }
  8092. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  8093. return 0;
  8094. }
  8095. /**
  8096. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  8097. *
  8098. * This routine wraps the actual lockless version for issusing IOCB function
  8099. * pointer from the lpfc_hba struct.
  8100. *
  8101. * Return codes:
  8102. * IOCB_ERROR - Error
  8103. * IOCB_SUCCESS - Success
  8104. * IOCB_BUSY - Busy
  8105. **/
  8106. int
  8107. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  8108. struct lpfc_iocbq *piocb, uint32_t flag)
  8109. {
  8110. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  8111. }
  8112. /**
  8113. * lpfc_sli_api_table_setup - Set up sli api function jump table
  8114. * @phba: The hba struct for which this call is being executed.
  8115. * @dev_grp: The HBA PCI-Device group number.
  8116. *
  8117. * This routine sets up the SLI interface API function jump table in @phba
  8118. * struct.
  8119. * Returns: 0 - success, -ENODEV - failure.
  8120. **/
  8121. int
  8122. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  8123. {
  8124. switch (dev_grp) {
  8125. case LPFC_PCI_DEV_LP:
  8126. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  8127. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  8128. break;
  8129. case LPFC_PCI_DEV_OC:
  8130. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  8131. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  8132. break;
  8133. default:
  8134. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8135. "1419 Invalid HBA PCI-device group: 0x%x\n",
  8136. dev_grp);
  8137. return -ENODEV;
  8138. break;
  8139. }
  8140. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  8141. return 0;
  8142. }
  8143. /**
  8144. * lpfc_sli_calc_ring - Calculates which ring to use
  8145. * @phba: Pointer to HBA context object.
  8146. * @ring_number: Initial ring
  8147. * @piocb: Pointer to command iocb.
  8148. *
  8149. * For SLI4, FCP IO can deferred to one fo many WQs, based on
  8150. * fcp_wqidx, thus we need to calculate the corresponding ring.
  8151. * Since ABORTS must go on the same WQ of the command they are
  8152. * aborting, we use command's fcp_wqidx.
  8153. */
  8154. static int
  8155. lpfc_sli_calc_ring(struct lpfc_hba *phba, uint32_t ring_number,
  8156. struct lpfc_iocbq *piocb)
  8157. {
  8158. if (phba->sli_rev < LPFC_SLI_REV4)
  8159. return ring_number;
  8160. if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
  8161. if (!(phba->cfg_fof) ||
  8162. (!(piocb->iocb_flag & LPFC_IO_FOF))) {
  8163. if (unlikely(!phba->sli4_hba.fcp_wq))
  8164. return LPFC_HBA_ERROR;
  8165. /*
  8166. * for abort iocb fcp_wqidx should already
  8167. * be setup based on what work queue we used.
  8168. */
  8169. if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX))
  8170. piocb->fcp_wqidx =
  8171. lpfc_sli4_scmd_to_wqidx_distr(phba,
  8172. piocb->context1);
  8173. ring_number = MAX_SLI3_CONFIGURED_RINGS +
  8174. piocb->fcp_wqidx;
  8175. } else {
  8176. if (unlikely(!phba->sli4_hba.oas_wq))
  8177. return LPFC_HBA_ERROR;
  8178. piocb->fcp_wqidx = 0;
  8179. ring_number = LPFC_FCP_OAS_RING;
  8180. }
  8181. }
  8182. return ring_number;
  8183. }
  8184. /**
  8185. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  8186. * @phba: Pointer to HBA context object.
  8187. * @pring: Pointer to driver SLI ring object.
  8188. * @piocb: Pointer to command iocb.
  8189. * @flag: Flag indicating if this command can be put into txq.
  8190. *
  8191. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  8192. * function. This function gets the hbalock and calls
  8193. * __lpfc_sli_issue_iocb function and will return the error returned
  8194. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  8195. * functions which do not hold hbalock.
  8196. **/
  8197. int
  8198. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  8199. struct lpfc_iocbq *piocb, uint32_t flag)
  8200. {
  8201. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8202. struct lpfc_sli_ring *pring;
  8203. struct lpfc_queue *fpeq;
  8204. struct lpfc_eqe *eqe;
  8205. unsigned long iflags;
  8206. int rc, idx;
  8207. if (phba->sli_rev == LPFC_SLI_REV4) {
  8208. ring_number = lpfc_sli_calc_ring(phba, ring_number, piocb);
  8209. if (unlikely(ring_number == LPFC_HBA_ERROR))
  8210. return IOCB_ERROR;
  8211. idx = piocb->fcp_wqidx;
  8212. pring = &phba->sli.ring[ring_number];
  8213. spin_lock_irqsave(&pring->ring_lock, iflags);
  8214. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  8215. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  8216. if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) {
  8217. fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
  8218. if (atomic_dec_and_test(&fcp_eq_hdl->
  8219. fcp_eq_in_use)) {
  8220. /* Get associated EQ with this index */
  8221. fpeq = phba->sli4_hba.hba_eq[idx];
  8222. /* Turn off interrupts from this EQ */
  8223. lpfc_sli4_eq_clr_intr(fpeq);
  8224. /*
  8225. * Process all the events on FCP EQ
  8226. */
  8227. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8228. lpfc_sli4_hba_handle_eqe(phba,
  8229. eqe, idx);
  8230. fpeq->EQ_processed++;
  8231. }
  8232. /* Always clear and re-arm the EQ */
  8233. lpfc_sli4_eq_release(fpeq,
  8234. LPFC_QUEUE_REARM);
  8235. }
  8236. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  8237. }
  8238. } else {
  8239. /* For now, SLI2/3 will still use hbalock */
  8240. spin_lock_irqsave(&phba->hbalock, iflags);
  8241. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  8242. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8243. }
  8244. return rc;
  8245. }
  8246. /**
  8247. * lpfc_extra_ring_setup - Extra ring setup function
  8248. * @phba: Pointer to HBA context object.
  8249. *
  8250. * This function is called while driver attaches with the
  8251. * HBA to setup the extra ring. The extra ring is used
  8252. * only when driver needs to support target mode functionality
  8253. * or IP over FC functionalities.
  8254. *
  8255. * This function is called with no lock held.
  8256. **/
  8257. static int
  8258. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  8259. {
  8260. struct lpfc_sli *psli;
  8261. struct lpfc_sli_ring *pring;
  8262. psli = &phba->sli;
  8263. /* Adjust cmd/rsp ring iocb entries more evenly */
  8264. /* Take some away from the FCP ring */
  8265. pring = &psli->ring[psli->fcp_ring];
  8266. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8267. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8268. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8269. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8270. /* and give them to the extra ring */
  8271. pring = &psli->ring[psli->extra_ring];
  8272. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8273. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8274. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8275. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8276. /* Setup default profile for this ring */
  8277. pring->iotag_max = 4096;
  8278. pring->num_mask = 1;
  8279. pring->prt[0].profile = 0; /* Mask 0 */
  8280. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  8281. pring->prt[0].type = phba->cfg_multi_ring_type;
  8282. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  8283. return 0;
  8284. }
  8285. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  8286. * @phba: Pointer to HBA context object.
  8287. * @iocbq: Pointer to iocb object.
  8288. *
  8289. * The async_event handler calls this routine when it receives
  8290. * an ASYNC_STATUS_CN event from the port. The port generates
  8291. * this event when an Abort Sequence request to an rport fails
  8292. * twice in succession. The abort could be originated by the
  8293. * driver or by the port. The ABTS could have been for an ELS
  8294. * or FCP IO. The port only generates this event when an ABTS
  8295. * fails to complete after one retry.
  8296. */
  8297. static void
  8298. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  8299. struct lpfc_iocbq *iocbq)
  8300. {
  8301. struct lpfc_nodelist *ndlp = NULL;
  8302. uint16_t rpi = 0, vpi = 0;
  8303. struct lpfc_vport *vport = NULL;
  8304. /* The rpi in the ulpContext is vport-sensitive. */
  8305. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  8306. rpi = iocbq->iocb.ulpContext;
  8307. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8308. "3092 Port generated ABTS async event "
  8309. "on vpi %d rpi %d status 0x%x\n",
  8310. vpi, rpi, iocbq->iocb.ulpStatus);
  8311. vport = lpfc_find_vport_by_vpid(phba, vpi);
  8312. if (!vport)
  8313. goto err_exit;
  8314. ndlp = lpfc_findnode_rpi(vport, rpi);
  8315. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  8316. goto err_exit;
  8317. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  8318. lpfc_sli_abts_recover_port(vport, ndlp);
  8319. return;
  8320. err_exit:
  8321. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8322. "3095 Event Context not found, no "
  8323. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  8324. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  8325. vpi, rpi);
  8326. }
  8327. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  8328. * @phba: pointer to HBA context object.
  8329. * @ndlp: nodelist pointer for the impacted rport.
  8330. * @axri: pointer to the wcqe containing the failed exchange.
  8331. *
  8332. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  8333. * port. The port generates this event when an abort exchange request to an
  8334. * rport fails twice in succession with no reply. The abort could be originated
  8335. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  8336. */
  8337. void
  8338. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  8339. struct lpfc_nodelist *ndlp,
  8340. struct sli4_wcqe_xri_aborted *axri)
  8341. {
  8342. struct lpfc_vport *vport;
  8343. uint32_t ext_status = 0;
  8344. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  8345. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8346. "3115 Node Context not found, driver "
  8347. "ignoring abts err event\n");
  8348. return;
  8349. }
  8350. vport = ndlp->vport;
  8351. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8352. "3116 Port generated FCP XRI ABORT event on "
  8353. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  8354. ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
  8355. bf_get(lpfc_wcqe_xa_xri, axri),
  8356. bf_get(lpfc_wcqe_xa_status, axri),
  8357. axri->parameter);
  8358. /*
  8359. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  8360. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  8361. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  8362. */
  8363. ext_status = axri->parameter & IOERR_PARAM_MASK;
  8364. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  8365. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  8366. lpfc_sli_abts_recover_port(vport, ndlp);
  8367. }
  8368. /**
  8369. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  8370. * @phba: Pointer to HBA context object.
  8371. * @pring: Pointer to driver SLI ring object.
  8372. * @iocbq: Pointer to iocb object.
  8373. *
  8374. * This function is called by the slow ring event handler
  8375. * function when there is an ASYNC event iocb in the ring.
  8376. * This function is called with no lock held.
  8377. * Currently this function handles only temperature related
  8378. * ASYNC events. The function decodes the temperature sensor
  8379. * event message and posts events for the management applications.
  8380. **/
  8381. static void
  8382. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  8383. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  8384. {
  8385. IOCB_t *icmd;
  8386. uint16_t evt_code;
  8387. struct temp_event temp_event_data;
  8388. struct Scsi_Host *shost;
  8389. uint32_t *iocb_w;
  8390. icmd = &iocbq->iocb;
  8391. evt_code = icmd->un.asyncstat.evt_code;
  8392. switch (evt_code) {
  8393. case ASYNC_TEMP_WARN:
  8394. case ASYNC_TEMP_SAFE:
  8395. temp_event_data.data = (uint32_t) icmd->ulpContext;
  8396. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  8397. if (evt_code == ASYNC_TEMP_WARN) {
  8398. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  8399. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  8400. "0347 Adapter is very hot, please take "
  8401. "corrective action. temperature : %d Celsius\n",
  8402. (uint32_t) icmd->ulpContext);
  8403. } else {
  8404. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  8405. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  8406. "0340 Adapter temperature is OK now. "
  8407. "temperature : %d Celsius\n",
  8408. (uint32_t) icmd->ulpContext);
  8409. }
  8410. /* Send temperature change event to applications */
  8411. shost = lpfc_shost_from_vport(phba->pport);
  8412. fc_host_post_vendor_event(shost, fc_get_event_number(),
  8413. sizeof(temp_event_data), (char *) &temp_event_data,
  8414. LPFC_NL_VENDOR_ID);
  8415. break;
  8416. case ASYNC_STATUS_CN:
  8417. lpfc_sli_abts_err_handler(phba, iocbq);
  8418. break;
  8419. default:
  8420. iocb_w = (uint32_t *) icmd;
  8421. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8422. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  8423. " evt_code 0x%x\n"
  8424. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  8425. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  8426. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  8427. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  8428. pring->ringno, icmd->un.asyncstat.evt_code,
  8429. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  8430. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  8431. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  8432. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  8433. break;
  8434. }
  8435. }
  8436. /**
  8437. * lpfc_sli_setup - SLI ring setup function
  8438. * @phba: Pointer to HBA context object.
  8439. *
  8440. * lpfc_sli_setup sets up rings of the SLI interface with
  8441. * number of iocbs per ring and iotags. This function is
  8442. * called while driver attach to the HBA and before the
  8443. * interrupts are enabled. So there is no need for locking.
  8444. *
  8445. * This function always returns 0.
  8446. **/
  8447. int
  8448. lpfc_sli_setup(struct lpfc_hba *phba)
  8449. {
  8450. int i, totiocbsize = 0;
  8451. struct lpfc_sli *psli = &phba->sli;
  8452. struct lpfc_sli_ring *pring;
  8453. psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
  8454. if (phba->sli_rev == LPFC_SLI_REV4)
  8455. psli->num_rings += phba->cfg_fcp_io_channel;
  8456. psli->sli_flag = 0;
  8457. psli->fcp_ring = LPFC_FCP_RING;
  8458. psli->next_ring = LPFC_FCP_NEXT_RING;
  8459. psli->extra_ring = LPFC_EXTRA_RING;
  8460. psli->iocbq_lookup = NULL;
  8461. psli->iocbq_lookup_len = 0;
  8462. psli->last_iotag = 0;
  8463. for (i = 0; i < psli->num_rings; i++) {
  8464. pring = &psli->ring[i];
  8465. switch (i) {
  8466. case LPFC_FCP_RING: /* ring 0 - FCP */
  8467. /* numCiocb and numRiocb are used in config_port */
  8468. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  8469. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  8470. pring->sli.sli3.numCiocb +=
  8471. SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8472. pring->sli.sli3.numRiocb +=
  8473. SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8474. pring->sli.sli3.numCiocb +=
  8475. SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8476. pring->sli.sli3.numRiocb +=
  8477. SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8478. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8479. SLI3_IOCB_CMD_SIZE :
  8480. SLI2_IOCB_CMD_SIZE;
  8481. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8482. SLI3_IOCB_RSP_SIZE :
  8483. SLI2_IOCB_RSP_SIZE;
  8484. pring->iotag_ctr = 0;
  8485. pring->iotag_max =
  8486. (phba->cfg_hba_queue_depth * 2);
  8487. pring->fast_iotag = pring->iotag_max;
  8488. pring->num_mask = 0;
  8489. break;
  8490. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  8491. /* numCiocb and numRiocb are used in config_port */
  8492. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  8493. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  8494. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8495. SLI3_IOCB_CMD_SIZE :
  8496. SLI2_IOCB_CMD_SIZE;
  8497. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8498. SLI3_IOCB_RSP_SIZE :
  8499. SLI2_IOCB_RSP_SIZE;
  8500. pring->iotag_max = phba->cfg_hba_queue_depth;
  8501. pring->num_mask = 0;
  8502. break;
  8503. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  8504. /* numCiocb and numRiocb are used in config_port */
  8505. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  8506. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  8507. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8508. SLI3_IOCB_CMD_SIZE :
  8509. SLI2_IOCB_CMD_SIZE;
  8510. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8511. SLI3_IOCB_RSP_SIZE :
  8512. SLI2_IOCB_RSP_SIZE;
  8513. pring->fast_iotag = 0;
  8514. pring->iotag_ctr = 0;
  8515. pring->iotag_max = 4096;
  8516. pring->lpfc_sli_rcv_async_status =
  8517. lpfc_sli_async_event_handler;
  8518. pring->num_mask = LPFC_MAX_RING_MASK;
  8519. pring->prt[0].profile = 0; /* Mask 0 */
  8520. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  8521. pring->prt[0].type = FC_TYPE_ELS;
  8522. pring->prt[0].lpfc_sli_rcv_unsol_event =
  8523. lpfc_els_unsol_event;
  8524. pring->prt[1].profile = 0; /* Mask 1 */
  8525. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  8526. pring->prt[1].type = FC_TYPE_ELS;
  8527. pring->prt[1].lpfc_sli_rcv_unsol_event =
  8528. lpfc_els_unsol_event;
  8529. pring->prt[2].profile = 0; /* Mask 2 */
  8530. /* NameServer Inquiry */
  8531. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  8532. /* NameServer */
  8533. pring->prt[2].type = FC_TYPE_CT;
  8534. pring->prt[2].lpfc_sli_rcv_unsol_event =
  8535. lpfc_ct_unsol_event;
  8536. pring->prt[3].profile = 0; /* Mask 3 */
  8537. /* NameServer response */
  8538. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8539. /* NameServer */
  8540. pring->prt[3].type = FC_TYPE_CT;
  8541. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8542. lpfc_ct_unsol_event;
  8543. break;
  8544. }
  8545. totiocbsize += (pring->sli.sli3.numCiocb *
  8546. pring->sli.sli3.sizeCiocb) +
  8547. (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
  8548. }
  8549. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8550. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8551. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8552. "SLI2 SLIM Data: x%x x%lx\n",
  8553. phba->brd_no, totiocbsize,
  8554. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8555. }
  8556. if (phba->cfg_multi_ring_support == 2)
  8557. lpfc_extra_ring_setup(phba);
  8558. return 0;
  8559. }
  8560. /**
  8561. * lpfc_sli_queue_setup - Queue initialization function
  8562. * @phba: Pointer to HBA context object.
  8563. *
  8564. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8565. * ring. This function also initializes ring indices of each ring.
  8566. * This function is called during the initialization of the SLI
  8567. * interface of an HBA.
  8568. * This function is called with no lock held and always returns
  8569. * 1.
  8570. **/
  8571. int
  8572. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8573. {
  8574. struct lpfc_sli *psli;
  8575. struct lpfc_sli_ring *pring;
  8576. int i;
  8577. psli = &phba->sli;
  8578. spin_lock_irq(&phba->hbalock);
  8579. INIT_LIST_HEAD(&psli->mboxq);
  8580. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8581. /* Initialize list headers for txq and txcmplq as double linked lists */
  8582. for (i = 0; i < psli->num_rings; i++) {
  8583. pring = &psli->ring[i];
  8584. pring->ringno = i;
  8585. pring->sli.sli3.next_cmdidx = 0;
  8586. pring->sli.sli3.local_getidx = 0;
  8587. pring->sli.sli3.cmdidx = 0;
  8588. pring->flag = 0;
  8589. INIT_LIST_HEAD(&pring->txq);
  8590. INIT_LIST_HEAD(&pring->txcmplq);
  8591. INIT_LIST_HEAD(&pring->iocb_continueq);
  8592. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8593. INIT_LIST_HEAD(&pring->postbufq);
  8594. spin_lock_init(&pring->ring_lock);
  8595. }
  8596. spin_unlock_irq(&phba->hbalock);
  8597. return 1;
  8598. }
  8599. /**
  8600. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8601. * @phba: Pointer to HBA context object.
  8602. *
  8603. * This routine flushes the mailbox command subsystem. It will unconditionally
  8604. * flush all the mailbox commands in the three possible stages in the mailbox
  8605. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8606. * command; and completed mailbox command queue. It is caller's responsibility
  8607. * to make sure that the driver is in the proper state to flush the mailbox
  8608. * command sub-system. Namely, the posting of mailbox commands into the
  8609. * pending mailbox command queue from the various clients must be stopped;
  8610. * either the HBA is in a state that it will never works on the outstanding
  8611. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8612. * mailbox command has been completed.
  8613. **/
  8614. static void
  8615. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8616. {
  8617. LIST_HEAD(completions);
  8618. struct lpfc_sli *psli = &phba->sli;
  8619. LPFC_MBOXQ_t *pmb;
  8620. unsigned long iflag;
  8621. /* Flush all the mailbox commands in the mbox system */
  8622. spin_lock_irqsave(&phba->hbalock, iflag);
  8623. /* The pending mailbox command queue */
  8624. list_splice_init(&phba->sli.mboxq, &completions);
  8625. /* The outstanding active mailbox command */
  8626. if (psli->mbox_active) {
  8627. list_add_tail(&psli->mbox_active->list, &completions);
  8628. psli->mbox_active = NULL;
  8629. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8630. }
  8631. /* The completed mailbox command queue */
  8632. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8633. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8634. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8635. while (!list_empty(&completions)) {
  8636. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8637. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8638. if (pmb->mbox_cmpl)
  8639. pmb->mbox_cmpl(phba, pmb);
  8640. }
  8641. }
  8642. /**
  8643. * lpfc_sli_host_down - Vport cleanup function
  8644. * @vport: Pointer to virtual port object.
  8645. *
  8646. * lpfc_sli_host_down is called to clean up the resources
  8647. * associated with a vport before destroying virtual
  8648. * port data structures.
  8649. * This function does following operations:
  8650. * - Free discovery resources associated with this virtual
  8651. * port.
  8652. * - Free iocbs associated with this virtual port in
  8653. * the txq.
  8654. * - Send abort for all iocb commands associated with this
  8655. * vport in txcmplq.
  8656. *
  8657. * This function is called with no lock held and always returns 1.
  8658. **/
  8659. int
  8660. lpfc_sli_host_down(struct lpfc_vport *vport)
  8661. {
  8662. LIST_HEAD(completions);
  8663. struct lpfc_hba *phba = vport->phba;
  8664. struct lpfc_sli *psli = &phba->sli;
  8665. struct lpfc_sli_ring *pring;
  8666. struct lpfc_iocbq *iocb, *next_iocb;
  8667. int i;
  8668. unsigned long flags = 0;
  8669. uint16_t prev_pring_flag;
  8670. lpfc_cleanup_discovery_resources(vport);
  8671. spin_lock_irqsave(&phba->hbalock, flags);
  8672. for (i = 0; i < psli->num_rings; i++) {
  8673. pring = &psli->ring[i];
  8674. prev_pring_flag = pring->flag;
  8675. /* Only slow rings */
  8676. if (pring->ringno == LPFC_ELS_RING) {
  8677. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8678. /* Set the lpfc data pending flag */
  8679. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8680. }
  8681. /*
  8682. * Error everything on the txq since these iocbs have not been
  8683. * given to the FW yet.
  8684. */
  8685. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8686. if (iocb->vport != vport)
  8687. continue;
  8688. list_move_tail(&iocb->list, &completions);
  8689. }
  8690. /* Next issue ABTS for everything on the txcmplq */
  8691. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8692. list) {
  8693. if (iocb->vport != vport)
  8694. continue;
  8695. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8696. }
  8697. pring->flag = prev_pring_flag;
  8698. }
  8699. spin_unlock_irqrestore(&phba->hbalock, flags);
  8700. /* Cancel all the IOCBs from the completions list */
  8701. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8702. IOERR_SLI_DOWN);
  8703. return 1;
  8704. }
  8705. /**
  8706. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8707. * @phba: Pointer to HBA context object.
  8708. *
  8709. * This function cleans up all iocb, buffers, mailbox commands
  8710. * while shutting down the HBA. This function is called with no
  8711. * lock held and always returns 1.
  8712. * This function does the following to cleanup driver resources:
  8713. * - Free discovery resources for each virtual port
  8714. * - Cleanup any pending fabric iocbs
  8715. * - Iterate through the iocb txq and free each entry
  8716. * in the list.
  8717. * - Free up any buffer posted to the HBA
  8718. * - Free mailbox commands in the mailbox queue.
  8719. **/
  8720. int
  8721. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8722. {
  8723. LIST_HEAD(completions);
  8724. struct lpfc_sli *psli = &phba->sli;
  8725. struct lpfc_sli_ring *pring;
  8726. struct lpfc_dmabuf *buf_ptr;
  8727. unsigned long flags = 0;
  8728. int i;
  8729. /* Shutdown the mailbox command sub-system */
  8730. lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
  8731. lpfc_hba_down_prep(phba);
  8732. lpfc_fabric_abort_hba(phba);
  8733. spin_lock_irqsave(&phba->hbalock, flags);
  8734. for (i = 0; i < psli->num_rings; i++) {
  8735. pring = &psli->ring[i];
  8736. /* Only slow rings */
  8737. if (pring->ringno == LPFC_ELS_RING) {
  8738. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8739. /* Set the lpfc data pending flag */
  8740. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8741. }
  8742. /*
  8743. * Error everything on the txq since these iocbs have not been
  8744. * given to the FW yet.
  8745. */
  8746. list_splice_init(&pring->txq, &completions);
  8747. }
  8748. spin_unlock_irqrestore(&phba->hbalock, flags);
  8749. /* Cancel all the IOCBs from the completions list */
  8750. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8751. IOERR_SLI_DOWN);
  8752. spin_lock_irqsave(&phba->hbalock, flags);
  8753. list_splice_init(&phba->elsbuf, &completions);
  8754. phba->elsbuf_cnt = 0;
  8755. phba->elsbuf_prev_cnt = 0;
  8756. spin_unlock_irqrestore(&phba->hbalock, flags);
  8757. while (!list_empty(&completions)) {
  8758. list_remove_head(&completions, buf_ptr,
  8759. struct lpfc_dmabuf, list);
  8760. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8761. kfree(buf_ptr);
  8762. }
  8763. /* Return any active mbox cmds */
  8764. del_timer_sync(&psli->mbox_tmo);
  8765. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8766. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8767. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8768. return 1;
  8769. }
  8770. /**
  8771. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8772. * @srcp: Source memory pointer.
  8773. * @destp: Destination memory pointer.
  8774. * @cnt: Number of words required to be copied.
  8775. *
  8776. * This function is used for copying data between driver memory
  8777. * and the SLI memory. This function also changes the endianness
  8778. * of each word if native endianness is different from SLI
  8779. * endianness. This function can be called with or without
  8780. * lock.
  8781. **/
  8782. void
  8783. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8784. {
  8785. uint32_t *src = srcp;
  8786. uint32_t *dest = destp;
  8787. uint32_t ldata;
  8788. int i;
  8789. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8790. ldata = *src;
  8791. ldata = le32_to_cpu(ldata);
  8792. *dest = ldata;
  8793. src++;
  8794. dest++;
  8795. }
  8796. }
  8797. /**
  8798. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8799. * @srcp: Source memory pointer.
  8800. * @destp: Destination memory pointer.
  8801. * @cnt: Number of words required to be copied.
  8802. *
  8803. * This function is used for copying data between a data structure
  8804. * with big endian representation to local endianness.
  8805. * This function can be called with or without lock.
  8806. **/
  8807. void
  8808. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8809. {
  8810. uint32_t *src = srcp;
  8811. uint32_t *dest = destp;
  8812. uint32_t ldata;
  8813. int i;
  8814. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8815. ldata = *src;
  8816. ldata = be32_to_cpu(ldata);
  8817. *dest = ldata;
  8818. src++;
  8819. dest++;
  8820. }
  8821. }
  8822. /**
  8823. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8824. * @phba: Pointer to HBA context object.
  8825. * @pring: Pointer to driver SLI ring object.
  8826. * @mp: Pointer to driver buffer object.
  8827. *
  8828. * This function is called with no lock held.
  8829. * It always return zero after adding the buffer to the postbufq
  8830. * buffer list.
  8831. **/
  8832. int
  8833. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8834. struct lpfc_dmabuf *mp)
  8835. {
  8836. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8837. later */
  8838. spin_lock_irq(&phba->hbalock);
  8839. list_add_tail(&mp->list, &pring->postbufq);
  8840. pring->postbufq_cnt++;
  8841. spin_unlock_irq(&phba->hbalock);
  8842. return 0;
  8843. }
  8844. /**
  8845. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8846. * @phba: Pointer to HBA context object.
  8847. *
  8848. * When HBQ is enabled, buffers are searched based on tags. This function
  8849. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8850. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8851. * does not conflict with tags of buffer posted for unsolicited events.
  8852. * The function returns the allocated tag. The function is called with
  8853. * no locks held.
  8854. **/
  8855. uint32_t
  8856. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8857. {
  8858. spin_lock_irq(&phba->hbalock);
  8859. phba->buffer_tag_count++;
  8860. /*
  8861. * Always set the QUE_BUFTAG_BIT to distiguish between
  8862. * a tag assigned by HBQ.
  8863. */
  8864. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8865. spin_unlock_irq(&phba->hbalock);
  8866. return phba->buffer_tag_count;
  8867. }
  8868. /**
  8869. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8870. * @phba: Pointer to HBA context object.
  8871. * @pring: Pointer to driver SLI ring object.
  8872. * @tag: Buffer tag.
  8873. *
  8874. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8875. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8876. * iocb is posted to the response ring with the tag of the buffer.
  8877. * This function searches the pring->postbufq list using the tag
  8878. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8879. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8880. * buffer is returned to the caller else NULL is returned.
  8881. * This function is called with no lock held.
  8882. **/
  8883. struct lpfc_dmabuf *
  8884. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8885. uint32_t tag)
  8886. {
  8887. struct lpfc_dmabuf *mp, *next_mp;
  8888. struct list_head *slp = &pring->postbufq;
  8889. /* Search postbufq, from the beginning, looking for a match on tag */
  8890. spin_lock_irq(&phba->hbalock);
  8891. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8892. if (mp->buffer_tag == tag) {
  8893. list_del_init(&mp->list);
  8894. pring->postbufq_cnt--;
  8895. spin_unlock_irq(&phba->hbalock);
  8896. return mp;
  8897. }
  8898. }
  8899. spin_unlock_irq(&phba->hbalock);
  8900. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8901. "0402 Cannot find virtual addr for buffer tag on "
  8902. "ring %d Data x%lx x%p x%p x%x\n",
  8903. pring->ringno, (unsigned long) tag,
  8904. slp->next, slp->prev, pring->postbufq_cnt);
  8905. return NULL;
  8906. }
  8907. /**
  8908. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8909. * @phba: Pointer to HBA context object.
  8910. * @pring: Pointer to driver SLI ring object.
  8911. * @phys: DMA address of the buffer.
  8912. *
  8913. * This function searches the buffer list using the dma_address
  8914. * of unsolicited event to find the driver's lpfc_dmabuf object
  8915. * corresponding to the dma_address. The function returns the
  8916. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8917. * This function is called by the ct and els unsolicited event
  8918. * handlers to get the buffer associated with the unsolicited
  8919. * event.
  8920. *
  8921. * This function is called with no lock held.
  8922. **/
  8923. struct lpfc_dmabuf *
  8924. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8925. dma_addr_t phys)
  8926. {
  8927. struct lpfc_dmabuf *mp, *next_mp;
  8928. struct list_head *slp = &pring->postbufq;
  8929. /* Search postbufq, from the beginning, looking for a match on phys */
  8930. spin_lock_irq(&phba->hbalock);
  8931. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8932. if (mp->phys == phys) {
  8933. list_del_init(&mp->list);
  8934. pring->postbufq_cnt--;
  8935. spin_unlock_irq(&phba->hbalock);
  8936. return mp;
  8937. }
  8938. }
  8939. spin_unlock_irq(&phba->hbalock);
  8940. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8941. "0410 Cannot find virtual addr for mapped buf on "
  8942. "ring %d Data x%llx x%p x%p x%x\n",
  8943. pring->ringno, (unsigned long long)phys,
  8944. slp->next, slp->prev, pring->postbufq_cnt);
  8945. return NULL;
  8946. }
  8947. /**
  8948. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8949. * @phba: Pointer to HBA context object.
  8950. * @cmdiocb: Pointer to driver command iocb object.
  8951. * @rspiocb: Pointer to driver response iocb object.
  8952. *
  8953. * This function is the completion handler for the abort iocbs for
  8954. * ELS commands. This function is called from the ELS ring event
  8955. * handler with no lock held. This function frees memory resources
  8956. * associated with the abort iocb.
  8957. **/
  8958. static void
  8959. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8960. struct lpfc_iocbq *rspiocb)
  8961. {
  8962. IOCB_t *irsp = &rspiocb->iocb;
  8963. uint16_t abort_iotag, abort_context;
  8964. struct lpfc_iocbq *abort_iocb = NULL;
  8965. if (irsp->ulpStatus) {
  8966. /*
  8967. * Assume that the port already completed and returned, or
  8968. * will return the iocb. Just Log the message.
  8969. */
  8970. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8971. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8972. spin_lock_irq(&phba->hbalock);
  8973. if (phba->sli_rev < LPFC_SLI_REV4) {
  8974. if (abort_iotag != 0 &&
  8975. abort_iotag <= phba->sli.last_iotag)
  8976. abort_iocb =
  8977. phba->sli.iocbq_lookup[abort_iotag];
  8978. } else
  8979. /* For sli4 the abort_tag is the XRI,
  8980. * so the abort routine puts the iotag of the iocb
  8981. * being aborted in the context field of the abort
  8982. * IOCB.
  8983. */
  8984. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8985. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8986. "0327 Cannot abort els iocb %p "
  8987. "with tag %x context %x, abort status %x, "
  8988. "abort code %x\n",
  8989. abort_iocb, abort_iotag, abort_context,
  8990. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8991. spin_unlock_irq(&phba->hbalock);
  8992. }
  8993. lpfc_sli_release_iocbq(phba, cmdiocb);
  8994. return;
  8995. }
  8996. /**
  8997. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8998. * @phba: Pointer to HBA context object.
  8999. * @cmdiocb: Pointer to driver command iocb object.
  9000. * @rspiocb: Pointer to driver response iocb object.
  9001. *
  9002. * The function is called from SLI ring event handler with no
  9003. * lock held. This function is the completion handler for ELS commands
  9004. * which are aborted. The function frees memory resources used for
  9005. * the aborted ELS commands.
  9006. **/
  9007. static void
  9008. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  9009. struct lpfc_iocbq *rspiocb)
  9010. {
  9011. IOCB_t *irsp = &rspiocb->iocb;
  9012. /* ELS cmd tag <ulpIoTag> completes */
  9013. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9014. "0139 Ignoring ELS cmd tag x%x completion Data: "
  9015. "x%x x%x x%x\n",
  9016. irsp->ulpIoTag, irsp->ulpStatus,
  9017. irsp->un.ulpWord[4], irsp->ulpTimeout);
  9018. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  9019. lpfc_ct_free_iocb(phba, cmdiocb);
  9020. else
  9021. lpfc_els_free_iocb(phba, cmdiocb);
  9022. return;
  9023. }
  9024. /**
  9025. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  9026. * @phba: Pointer to HBA context object.
  9027. * @pring: Pointer to driver SLI ring object.
  9028. * @cmdiocb: Pointer to driver command iocb object.
  9029. *
  9030. * This function issues an abort iocb for the provided command iocb down to
  9031. * the port. Other than the case the outstanding command iocb is an abort
  9032. * request, this function issues abort out unconditionally. This function is
  9033. * called with hbalock held. The function returns 0 when it fails due to
  9034. * memory allocation failure or when the command iocb is an abort request.
  9035. **/
  9036. static int
  9037. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  9038. struct lpfc_iocbq *cmdiocb)
  9039. {
  9040. struct lpfc_vport *vport = cmdiocb->vport;
  9041. struct lpfc_iocbq *abtsiocbp;
  9042. IOCB_t *icmd = NULL;
  9043. IOCB_t *iabt = NULL;
  9044. int ring_number;
  9045. int retval;
  9046. unsigned long iflags;
  9047. lockdep_assert_held(&phba->hbalock);
  9048. /*
  9049. * There are certain command types we don't want to abort. And we
  9050. * don't want to abort commands that are already in the process of
  9051. * being aborted.
  9052. */
  9053. icmd = &cmdiocb->iocb;
  9054. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  9055. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  9056. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  9057. return 0;
  9058. /* issue ABTS for this IOCB based on iotag */
  9059. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  9060. if (abtsiocbp == NULL)
  9061. return 0;
  9062. /* This signals the response to set the correct status
  9063. * before calling the completion handler
  9064. */
  9065. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  9066. iabt = &abtsiocbp->iocb;
  9067. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  9068. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  9069. if (phba->sli_rev == LPFC_SLI_REV4) {
  9070. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  9071. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  9072. }
  9073. else
  9074. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  9075. iabt->ulpLe = 1;
  9076. iabt->ulpClass = icmd->ulpClass;
  9077. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  9078. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  9079. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  9080. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  9081. if (cmdiocb->iocb_flag & LPFC_IO_FOF)
  9082. abtsiocbp->iocb_flag |= LPFC_IO_FOF;
  9083. if (phba->link_state >= LPFC_LINK_UP)
  9084. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  9085. else
  9086. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  9087. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  9088. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  9089. "0339 Abort xri x%x, original iotag x%x, "
  9090. "abort cmd iotag x%x\n",
  9091. iabt->un.acxri.abortIoTag,
  9092. iabt->un.acxri.abortContextTag,
  9093. abtsiocbp->iotag);
  9094. if (phba->sli_rev == LPFC_SLI_REV4) {
  9095. ring_number =
  9096. lpfc_sli_calc_ring(phba, pring->ringno, abtsiocbp);
  9097. if (unlikely(ring_number == LPFC_HBA_ERROR))
  9098. return 0;
  9099. pring = &phba->sli.ring[ring_number];
  9100. /* Note: both hbalock and ring_lock need to be set here */
  9101. spin_lock_irqsave(&pring->ring_lock, iflags);
  9102. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  9103. abtsiocbp, 0);
  9104. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  9105. } else {
  9106. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  9107. abtsiocbp, 0);
  9108. }
  9109. if (retval)
  9110. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  9111. /*
  9112. * Caller to this routine should check for IOCB_ERROR
  9113. * and handle it properly. This routine no longer removes
  9114. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  9115. */
  9116. return retval;
  9117. }
  9118. /**
  9119. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  9120. * @phba: Pointer to HBA context object.
  9121. * @pring: Pointer to driver SLI ring object.
  9122. * @cmdiocb: Pointer to driver command iocb object.
  9123. *
  9124. * This function issues an abort iocb for the provided command iocb. In case
  9125. * of unloading, the abort iocb will not be issued to commands on the ELS
  9126. * ring. Instead, the callback function shall be changed to those commands
  9127. * so that nothing happens when them finishes. This function is called with
  9128. * hbalock held. The function returns 0 when the command iocb is an abort
  9129. * request.
  9130. **/
  9131. int
  9132. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  9133. struct lpfc_iocbq *cmdiocb)
  9134. {
  9135. struct lpfc_vport *vport = cmdiocb->vport;
  9136. int retval = IOCB_ERROR;
  9137. IOCB_t *icmd = NULL;
  9138. lockdep_assert_held(&phba->hbalock);
  9139. /*
  9140. * There are certain command types we don't want to abort. And we
  9141. * don't want to abort commands that are already in the process of
  9142. * being aborted.
  9143. */
  9144. icmd = &cmdiocb->iocb;
  9145. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  9146. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  9147. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  9148. return 0;
  9149. /*
  9150. * If we're unloading, don't abort iocb on the ELS ring, but change
  9151. * the callback so that nothing happens when it finishes.
  9152. */
  9153. if ((vport->load_flag & FC_UNLOADING) &&
  9154. (pring->ringno == LPFC_ELS_RING)) {
  9155. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  9156. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  9157. else
  9158. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  9159. goto abort_iotag_exit;
  9160. }
  9161. /* Now, we try to issue the abort to the cmdiocb out */
  9162. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  9163. abort_iotag_exit:
  9164. /*
  9165. * Caller to this routine should check for IOCB_ERROR
  9166. * and handle it properly. This routine no longer removes
  9167. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  9168. */
  9169. return retval;
  9170. }
  9171. /**
  9172. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  9173. * @phba: pointer to lpfc HBA data structure.
  9174. *
  9175. * This routine will abort all pending and outstanding iocbs to an HBA.
  9176. **/
  9177. void
  9178. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  9179. {
  9180. struct lpfc_sli *psli = &phba->sli;
  9181. struct lpfc_sli_ring *pring;
  9182. int i;
  9183. for (i = 0; i < psli->num_rings; i++) {
  9184. pring = &psli->ring[i];
  9185. lpfc_sli_abort_iocb_ring(phba, pring);
  9186. }
  9187. }
  9188. /**
  9189. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  9190. * @iocbq: Pointer to driver iocb object.
  9191. * @vport: Pointer to driver virtual port object.
  9192. * @tgt_id: SCSI ID of the target.
  9193. * @lun_id: LUN ID of the scsi device.
  9194. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  9195. *
  9196. * This function acts as an iocb filter for functions which abort or count
  9197. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  9198. * 0 if the filtering criteria is met for the given iocb and will return
  9199. * 1 if the filtering criteria is not met.
  9200. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  9201. * given iocb is for the SCSI device specified by vport, tgt_id and
  9202. * lun_id parameter.
  9203. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  9204. * given iocb is for the SCSI target specified by vport and tgt_id
  9205. * parameters.
  9206. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  9207. * given iocb is for the SCSI host associated with the given vport.
  9208. * This function is called with no locks held.
  9209. **/
  9210. static int
  9211. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  9212. uint16_t tgt_id, uint64_t lun_id,
  9213. lpfc_ctx_cmd ctx_cmd)
  9214. {
  9215. struct lpfc_scsi_buf *lpfc_cmd;
  9216. int rc = 1;
  9217. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  9218. return rc;
  9219. if (iocbq->vport != vport)
  9220. return rc;
  9221. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  9222. if (lpfc_cmd->pCmd == NULL)
  9223. return rc;
  9224. switch (ctx_cmd) {
  9225. case LPFC_CTX_LUN:
  9226. if ((lpfc_cmd->rdata->pnode) &&
  9227. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  9228. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  9229. rc = 0;
  9230. break;
  9231. case LPFC_CTX_TGT:
  9232. if ((lpfc_cmd->rdata->pnode) &&
  9233. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  9234. rc = 0;
  9235. break;
  9236. case LPFC_CTX_HOST:
  9237. rc = 0;
  9238. break;
  9239. default:
  9240. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  9241. __func__, ctx_cmd);
  9242. break;
  9243. }
  9244. return rc;
  9245. }
  9246. /**
  9247. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  9248. * @vport: Pointer to virtual port.
  9249. * @tgt_id: SCSI ID of the target.
  9250. * @lun_id: LUN ID of the scsi device.
  9251. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9252. *
  9253. * This function returns number of FCP commands pending for the vport.
  9254. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  9255. * commands pending on the vport associated with SCSI device specified
  9256. * by tgt_id and lun_id parameters.
  9257. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  9258. * commands pending on the vport associated with SCSI target specified
  9259. * by tgt_id parameter.
  9260. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  9261. * commands pending on the vport.
  9262. * This function returns the number of iocbs which satisfy the filter.
  9263. * This function is called without any lock held.
  9264. **/
  9265. int
  9266. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  9267. lpfc_ctx_cmd ctx_cmd)
  9268. {
  9269. struct lpfc_hba *phba = vport->phba;
  9270. struct lpfc_iocbq *iocbq;
  9271. int sum, i;
  9272. spin_lock_irq(&phba->hbalock);
  9273. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  9274. iocbq = phba->sli.iocbq_lookup[i];
  9275. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  9276. ctx_cmd) == 0)
  9277. sum++;
  9278. }
  9279. spin_unlock_irq(&phba->hbalock);
  9280. return sum;
  9281. }
  9282. /**
  9283. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  9284. * @phba: Pointer to HBA context object
  9285. * @cmdiocb: Pointer to command iocb object.
  9286. * @rspiocb: Pointer to response iocb object.
  9287. *
  9288. * This function is called when an aborted FCP iocb completes. This
  9289. * function is called by the ring event handler with no lock held.
  9290. * This function frees the iocb.
  9291. **/
  9292. void
  9293. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  9294. struct lpfc_iocbq *rspiocb)
  9295. {
  9296. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9297. "3096 ABORT_XRI_CN completing on rpi x%x "
  9298. "original iotag x%x, abort cmd iotag x%x "
  9299. "status 0x%x, reason 0x%x\n",
  9300. cmdiocb->iocb.un.acxri.abortContextTag,
  9301. cmdiocb->iocb.un.acxri.abortIoTag,
  9302. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  9303. rspiocb->iocb.un.ulpWord[4]);
  9304. lpfc_sli_release_iocbq(phba, cmdiocb);
  9305. return;
  9306. }
  9307. /**
  9308. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  9309. * @vport: Pointer to virtual port.
  9310. * @pring: Pointer to driver SLI ring object.
  9311. * @tgt_id: SCSI ID of the target.
  9312. * @lun_id: LUN ID of the scsi device.
  9313. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9314. *
  9315. * This function sends an abort command for every SCSI command
  9316. * associated with the given virtual port pending on the ring
  9317. * filtered by lpfc_sli_validate_fcp_iocb function.
  9318. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  9319. * FCP iocbs associated with lun specified by tgt_id and lun_id
  9320. * parameters
  9321. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  9322. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  9323. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  9324. * FCP iocbs associated with virtual port.
  9325. * This function returns number of iocbs it failed to abort.
  9326. * This function is called with no locks held.
  9327. **/
  9328. int
  9329. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  9330. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  9331. {
  9332. struct lpfc_hba *phba = vport->phba;
  9333. struct lpfc_iocbq *iocbq;
  9334. struct lpfc_iocbq *abtsiocb;
  9335. IOCB_t *cmd = NULL;
  9336. int errcnt = 0, ret_val = 0;
  9337. int i;
  9338. for (i = 1; i <= phba->sli.last_iotag; i++) {
  9339. iocbq = phba->sli.iocbq_lookup[i];
  9340. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  9341. abort_cmd) != 0)
  9342. continue;
  9343. /*
  9344. * If the iocbq is already being aborted, don't take a second
  9345. * action, but do count it.
  9346. */
  9347. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  9348. continue;
  9349. /* issue ABTS for this IOCB based on iotag */
  9350. abtsiocb = lpfc_sli_get_iocbq(phba);
  9351. if (abtsiocb == NULL) {
  9352. errcnt++;
  9353. continue;
  9354. }
  9355. /* indicate the IO is being aborted by the driver. */
  9356. iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
  9357. cmd = &iocbq->iocb;
  9358. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  9359. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  9360. if (phba->sli_rev == LPFC_SLI_REV4)
  9361. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  9362. else
  9363. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  9364. abtsiocb->iocb.ulpLe = 1;
  9365. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  9366. abtsiocb->vport = vport;
  9367. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  9368. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  9369. if (iocbq->iocb_flag & LPFC_IO_FCP)
  9370. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  9371. if (iocbq->iocb_flag & LPFC_IO_FOF)
  9372. abtsiocb->iocb_flag |= LPFC_IO_FOF;
  9373. if (lpfc_is_link_up(phba))
  9374. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  9375. else
  9376. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  9377. /* Setup callback routine and issue the command. */
  9378. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  9379. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  9380. abtsiocb, 0);
  9381. if (ret_val == IOCB_ERROR) {
  9382. lpfc_sli_release_iocbq(phba, abtsiocb);
  9383. errcnt++;
  9384. continue;
  9385. }
  9386. }
  9387. return errcnt;
  9388. }
  9389. /**
  9390. * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
  9391. * @vport: Pointer to virtual port.
  9392. * @pring: Pointer to driver SLI ring object.
  9393. * @tgt_id: SCSI ID of the target.
  9394. * @lun_id: LUN ID of the scsi device.
  9395. * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9396. *
  9397. * This function sends an abort command for every SCSI command
  9398. * associated with the given virtual port pending on the ring
  9399. * filtered by lpfc_sli_validate_fcp_iocb function.
  9400. * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
  9401. * FCP iocbs associated with lun specified by tgt_id and lun_id
  9402. * parameters
  9403. * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
  9404. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  9405. * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
  9406. * FCP iocbs associated with virtual port.
  9407. * This function returns number of iocbs it aborted .
  9408. * This function is called with no locks held right after a taskmgmt
  9409. * command is sent.
  9410. **/
  9411. int
  9412. lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  9413. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
  9414. {
  9415. struct lpfc_hba *phba = vport->phba;
  9416. struct lpfc_scsi_buf *lpfc_cmd;
  9417. struct lpfc_iocbq *abtsiocbq;
  9418. struct lpfc_nodelist *ndlp;
  9419. struct lpfc_iocbq *iocbq;
  9420. IOCB_t *icmd;
  9421. int sum, i, ret_val;
  9422. unsigned long iflags;
  9423. struct lpfc_sli_ring *pring_s4;
  9424. uint32_t ring_number;
  9425. spin_lock_irq(&phba->hbalock);
  9426. /* all I/Os are in process of being flushed */
  9427. if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
  9428. spin_unlock_irq(&phba->hbalock);
  9429. return 0;
  9430. }
  9431. sum = 0;
  9432. for (i = 1; i <= phba->sli.last_iotag; i++) {
  9433. iocbq = phba->sli.iocbq_lookup[i];
  9434. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  9435. cmd) != 0)
  9436. continue;
  9437. /*
  9438. * If the iocbq is already being aborted, don't take a second
  9439. * action, but do count it.
  9440. */
  9441. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  9442. continue;
  9443. /* issue ABTS for this IOCB based on iotag */
  9444. abtsiocbq = __lpfc_sli_get_iocbq(phba);
  9445. if (abtsiocbq == NULL)
  9446. continue;
  9447. icmd = &iocbq->iocb;
  9448. abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  9449. abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
  9450. if (phba->sli_rev == LPFC_SLI_REV4)
  9451. abtsiocbq->iocb.un.acxri.abortIoTag =
  9452. iocbq->sli4_xritag;
  9453. else
  9454. abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
  9455. abtsiocbq->iocb.ulpLe = 1;
  9456. abtsiocbq->iocb.ulpClass = icmd->ulpClass;
  9457. abtsiocbq->vport = vport;
  9458. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  9459. abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx;
  9460. if (iocbq->iocb_flag & LPFC_IO_FCP)
  9461. abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
  9462. if (iocbq->iocb_flag & LPFC_IO_FOF)
  9463. abtsiocbq->iocb_flag |= LPFC_IO_FOF;
  9464. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  9465. ndlp = lpfc_cmd->rdata->pnode;
  9466. if (lpfc_is_link_up(phba) &&
  9467. (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
  9468. abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  9469. else
  9470. abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  9471. /* Setup callback routine and issue the command. */
  9472. abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  9473. /*
  9474. * Indicate the IO is being aborted by the driver and set
  9475. * the caller's flag into the aborted IO.
  9476. */
  9477. iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
  9478. if (phba->sli_rev == LPFC_SLI_REV4) {
  9479. ring_number = MAX_SLI3_CONFIGURED_RINGS +
  9480. iocbq->fcp_wqidx;
  9481. pring_s4 = &phba->sli.ring[ring_number];
  9482. /* Note: both hbalock and ring_lock must be set here */
  9483. spin_lock_irqsave(&pring_s4->ring_lock, iflags);
  9484. ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
  9485. abtsiocbq, 0);
  9486. spin_unlock_irqrestore(&pring_s4->ring_lock, iflags);
  9487. } else {
  9488. ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
  9489. abtsiocbq, 0);
  9490. }
  9491. if (ret_val == IOCB_ERROR)
  9492. __lpfc_sli_release_iocbq(phba, abtsiocbq);
  9493. else
  9494. sum++;
  9495. }
  9496. spin_unlock_irq(&phba->hbalock);
  9497. return sum;
  9498. }
  9499. /**
  9500. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  9501. * @phba: Pointer to HBA context object.
  9502. * @cmdiocbq: Pointer to command iocb.
  9503. * @rspiocbq: Pointer to response iocb.
  9504. *
  9505. * This function is the completion handler for iocbs issued using
  9506. * lpfc_sli_issue_iocb_wait function. This function is called by the
  9507. * ring event handler function without any lock held. This function
  9508. * can be called from both worker thread context and interrupt
  9509. * context. This function also can be called from other thread which
  9510. * cleans up the SLI layer objects.
  9511. * This function copy the contents of the response iocb to the
  9512. * response iocb memory object provided by the caller of
  9513. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  9514. * sleeps for the iocb completion.
  9515. **/
  9516. static void
  9517. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  9518. struct lpfc_iocbq *cmdiocbq,
  9519. struct lpfc_iocbq *rspiocbq)
  9520. {
  9521. wait_queue_head_t *pdone_q;
  9522. unsigned long iflags;
  9523. struct lpfc_scsi_buf *lpfc_cmd;
  9524. spin_lock_irqsave(&phba->hbalock, iflags);
  9525. if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
  9526. /*
  9527. * A time out has occurred for the iocb. If a time out
  9528. * completion handler has been supplied, call it. Otherwise,
  9529. * just free the iocbq.
  9530. */
  9531. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9532. cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
  9533. cmdiocbq->wait_iocb_cmpl = NULL;
  9534. if (cmdiocbq->iocb_cmpl)
  9535. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
  9536. else
  9537. lpfc_sli_release_iocbq(phba, cmdiocbq);
  9538. return;
  9539. }
  9540. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  9541. if (cmdiocbq->context2 && rspiocbq)
  9542. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  9543. &rspiocbq->iocb, sizeof(IOCB_t));
  9544. /* Set the exchange busy flag for task management commands */
  9545. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  9546. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  9547. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  9548. cur_iocbq);
  9549. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  9550. }
  9551. pdone_q = cmdiocbq->context_un.wait_queue;
  9552. if (pdone_q)
  9553. wake_up(pdone_q);
  9554. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9555. return;
  9556. }
  9557. /**
  9558. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  9559. * @phba: Pointer to HBA context object..
  9560. * @piocbq: Pointer to command iocb.
  9561. * @flag: Flag to test.
  9562. *
  9563. * This routine grabs the hbalock and then test the iocb_flag to
  9564. * see if the passed in flag is set.
  9565. * Returns:
  9566. * 1 if flag is set.
  9567. * 0 if flag is not set.
  9568. **/
  9569. static int
  9570. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  9571. struct lpfc_iocbq *piocbq, uint32_t flag)
  9572. {
  9573. unsigned long iflags;
  9574. int ret;
  9575. spin_lock_irqsave(&phba->hbalock, iflags);
  9576. ret = piocbq->iocb_flag & flag;
  9577. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9578. return ret;
  9579. }
  9580. /**
  9581. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  9582. * @phba: Pointer to HBA context object..
  9583. * @pring: Pointer to sli ring.
  9584. * @piocb: Pointer to command iocb.
  9585. * @prspiocbq: Pointer to response iocb.
  9586. * @timeout: Timeout in number of seconds.
  9587. *
  9588. * This function issues the iocb to firmware and waits for the
  9589. * iocb to complete. The iocb_cmpl field of the shall be used
  9590. * to handle iocbs which time out. If the field is NULL, the
  9591. * function shall free the iocbq structure. If more clean up is
  9592. * needed, the caller is expected to provide a completion function
  9593. * that will provide the needed clean up. If the iocb command is
  9594. * not completed within timeout seconds, the function will either
  9595. * free the iocbq structure (if iocb_cmpl == NULL) or execute the
  9596. * completion function set in the iocb_cmpl field and then return
  9597. * a status of IOCB_TIMEDOUT. The caller should not free the iocb
  9598. * resources if this function returns IOCB_TIMEDOUT.
  9599. * The function waits for the iocb completion using an
  9600. * non-interruptible wait.
  9601. * This function will sleep while waiting for iocb completion.
  9602. * So, this function should not be called from any context which
  9603. * does not allow sleeping. Due to the same reason, this function
  9604. * cannot be called with interrupt disabled.
  9605. * This function assumes that the iocb completions occur while
  9606. * this function sleep. So, this function cannot be called from
  9607. * the thread which process iocb completion for this ring.
  9608. * This function clears the iocb_flag of the iocb object before
  9609. * issuing the iocb and the iocb completion handler sets this
  9610. * flag and wakes this thread when the iocb completes.
  9611. * The contents of the response iocb will be copied to prspiocbq
  9612. * by the completion handler when the command completes.
  9613. * This function returns IOCB_SUCCESS when success.
  9614. * This function is called with no lock held.
  9615. **/
  9616. int
  9617. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  9618. uint32_t ring_number,
  9619. struct lpfc_iocbq *piocb,
  9620. struct lpfc_iocbq *prspiocbq,
  9621. uint32_t timeout)
  9622. {
  9623. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9624. long timeleft, timeout_req = 0;
  9625. int retval = IOCB_SUCCESS;
  9626. uint32_t creg_val;
  9627. struct lpfc_iocbq *iocb;
  9628. int txq_cnt = 0;
  9629. int txcmplq_cnt = 0;
  9630. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9631. unsigned long iflags;
  9632. bool iocb_completed = true;
  9633. /*
  9634. * If the caller has provided a response iocbq buffer, then context2
  9635. * is NULL or its an error.
  9636. */
  9637. if (prspiocbq) {
  9638. if (piocb->context2)
  9639. return IOCB_ERROR;
  9640. piocb->context2 = prspiocbq;
  9641. }
  9642. piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
  9643. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  9644. piocb->context_un.wait_queue = &done_q;
  9645. piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
  9646. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9647. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9648. return IOCB_ERROR;
  9649. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  9650. writel(creg_val, phba->HCregaddr);
  9651. readl(phba->HCregaddr); /* flush */
  9652. }
  9653. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  9654. SLI_IOCB_RET_IOCB);
  9655. if (retval == IOCB_SUCCESS) {
  9656. timeout_req = msecs_to_jiffies(timeout * 1000);
  9657. timeleft = wait_event_timeout(done_q,
  9658. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  9659. timeout_req);
  9660. spin_lock_irqsave(&phba->hbalock, iflags);
  9661. if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
  9662. /*
  9663. * IOCB timed out. Inform the wake iocb wait
  9664. * completion function and set local status
  9665. */
  9666. iocb_completed = false;
  9667. piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
  9668. }
  9669. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9670. if (iocb_completed) {
  9671. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9672. "0331 IOCB wake signaled\n");
  9673. /* Note: we are not indicating if the IOCB has a success
  9674. * status or not - that's for the caller to check.
  9675. * IOCB_SUCCESS means just that the command was sent and
  9676. * completed. Not that it completed successfully.
  9677. * */
  9678. } else if (timeleft == 0) {
  9679. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9680. "0338 IOCB wait timeout error - no "
  9681. "wake response Data x%x\n", timeout);
  9682. retval = IOCB_TIMEDOUT;
  9683. } else {
  9684. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9685. "0330 IOCB wake NOT set, "
  9686. "Data x%x x%lx\n",
  9687. timeout, (timeleft / jiffies));
  9688. retval = IOCB_TIMEDOUT;
  9689. }
  9690. } else if (retval == IOCB_BUSY) {
  9691. if (phba->cfg_log_verbose & LOG_SLI) {
  9692. list_for_each_entry(iocb, &pring->txq, list) {
  9693. txq_cnt++;
  9694. }
  9695. list_for_each_entry(iocb, &pring->txcmplq, list) {
  9696. txcmplq_cnt++;
  9697. }
  9698. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9699. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9700. phba->iocb_cnt, txq_cnt, txcmplq_cnt);
  9701. }
  9702. return retval;
  9703. } else {
  9704. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9705. "0332 IOCB wait issue failed, Data x%x\n",
  9706. retval);
  9707. retval = IOCB_ERROR;
  9708. }
  9709. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9710. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9711. return IOCB_ERROR;
  9712. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9713. writel(creg_val, phba->HCregaddr);
  9714. readl(phba->HCregaddr); /* flush */
  9715. }
  9716. if (prspiocbq)
  9717. piocb->context2 = NULL;
  9718. piocb->context_un.wait_queue = NULL;
  9719. piocb->iocb_cmpl = NULL;
  9720. return retval;
  9721. }
  9722. /**
  9723. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9724. * @phba: Pointer to HBA context object.
  9725. * @pmboxq: Pointer to driver mailbox object.
  9726. * @timeout: Timeout in number of seconds.
  9727. *
  9728. * This function issues the mailbox to firmware and waits for the
  9729. * mailbox command to complete. If the mailbox command is not
  9730. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9731. * The function waits for the mailbox completion using an
  9732. * interruptible wait. If the thread is woken up due to a
  9733. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9734. * should not free the mailbox resources, if this function returns
  9735. * MBX_TIMEOUT.
  9736. * This function will sleep while waiting for mailbox completion.
  9737. * So, this function should not be called from any context which
  9738. * does not allow sleeping. Due to the same reason, this function
  9739. * cannot be called with interrupt disabled.
  9740. * This function assumes that the mailbox completion occurs while
  9741. * this function sleep. So, this function cannot be called from
  9742. * the worker thread which processes mailbox completion.
  9743. * This function is called in the context of HBA management
  9744. * applications.
  9745. * This function returns MBX_SUCCESS when successful.
  9746. * This function is called with no lock held.
  9747. **/
  9748. int
  9749. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9750. uint32_t timeout)
  9751. {
  9752. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9753. MAILBOX_t *mb = NULL;
  9754. int retval;
  9755. unsigned long flag;
  9756. /* The caller might set context1 for extended buffer */
  9757. if (pmboxq->context1)
  9758. mb = (MAILBOX_t *)pmboxq->context1;
  9759. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9760. /* setup wake call as IOCB callback */
  9761. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9762. /* setup context field to pass wait_queue pointer to wake function */
  9763. pmboxq->context1 = &done_q;
  9764. /* now issue the command */
  9765. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9766. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9767. wait_event_interruptible_timeout(done_q,
  9768. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9769. msecs_to_jiffies(timeout * 1000));
  9770. spin_lock_irqsave(&phba->hbalock, flag);
  9771. /* restore the possible extended buffer for free resource */
  9772. pmboxq->context1 = (uint8_t *)mb;
  9773. /*
  9774. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9775. * else do not free the resources.
  9776. */
  9777. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9778. retval = MBX_SUCCESS;
  9779. } else {
  9780. retval = MBX_TIMEOUT;
  9781. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9782. }
  9783. spin_unlock_irqrestore(&phba->hbalock, flag);
  9784. } else {
  9785. /* restore the possible extended buffer for free resource */
  9786. pmboxq->context1 = (uint8_t *)mb;
  9787. }
  9788. return retval;
  9789. }
  9790. /**
  9791. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9792. * @phba: Pointer to HBA context.
  9793. *
  9794. * This function is called to shutdown the driver's mailbox sub-system.
  9795. * It first marks the mailbox sub-system is in a block state to prevent
  9796. * the asynchronous mailbox command from issued off the pending mailbox
  9797. * command queue. If the mailbox command sub-system shutdown is due to
  9798. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9799. * the mailbox sub-system flush routine to forcefully bring down the
  9800. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9801. * as with offline or HBA function reset), this routine will wait for the
  9802. * outstanding mailbox command to complete before invoking the mailbox
  9803. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9804. **/
  9805. void
  9806. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
  9807. {
  9808. struct lpfc_sli *psli = &phba->sli;
  9809. unsigned long timeout;
  9810. if (mbx_action == LPFC_MBX_NO_WAIT) {
  9811. /* delay 100ms for port state */
  9812. msleep(100);
  9813. lpfc_sli_mbox_sys_flush(phba);
  9814. return;
  9815. }
  9816. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9817. spin_lock_irq(&phba->hbalock);
  9818. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9819. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9820. /* Determine how long we might wait for the active mailbox
  9821. * command to be gracefully completed by firmware.
  9822. */
  9823. if (phba->sli.mbox_active)
  9824. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9825. phba->sli.mbox_active) *
  9826. 1000) + jiffies;
  9827. spin_unlock_irq(&phba->hbalock);
  9828. while (phba->sli.mbox_active) {
  9829. /* Check active mailbox complete status every 2ms */
  9830. msleep(2);
  9831. if (time_after(jiffies, timeout))
  9832. /* Timeout, let the mailbox flush routine to
  9833. * forcefully release active mailbox command
  9834. */
  9835. break;
  9836. }
  9837. } else
  9838. spin_unlock_irq(&phba->hbalock);
  9839. lpfc_sli_mbox_sys_flush(phba);
  9840. }
  9841. /**
  9842. * lpfc_sli_eratt_read - read sli-3 error attention events
  9843. * @phba: Pointer to HBA context.
  9844. *
  9845. * This function is called to read the SLI3 device error attention registers
  9846. * for possible error attention events. The caller must hold the hostlock
  9847. * with spin_lock_irq().
  9848. *
  9849. * This function returns 1 when there is Error Attention in the Host Attention
  9850. * Register and returns 0 otherwise.
  9851. **/
  9852. static int
  9853. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9854. {
  9855. uint32_t ha_copy;
  9856. /* Read chip Host Attention (HA) register */
  9857. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9858. goto unplug_err;
  9859. if (ha_copy & HA_ERATT) {
  9860. /* Read host status register to retrieve error event */
  9861. if (lpfc_sli_read_hs(phba))
  9862. goto unplug_err;
  9863. /* Check if there is a deferred error condition is active */
  9864. if ((HS_FFER1 & phba->work_hs) &&
  9865. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9866. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9867. phba->hba_flag |= DEFER_ERATT;
  9868. /* Clear all interrupt enable conditions */
  9869. writel(0, phba->HCregaddr);
  9870. readl(phba->HCregaddr);
  9871. }
  9872. /* Set the driver HA work bitmap */
  9873. phba->work_ha |= HA_ERATT;
  9874. /* Indicate polling handles this ERATT */
  9875. phba->hba_flag |= HBA_ERATT_HANDLED;
  9876. return 1;
  9877. }
  9878. return 0;
  9879. unplug_err:
  9880. /* Set the driver HS work bitmap */
  9881. phba->work_hs |= UNPLUG_ERR;
  9882. /* Set the driver HA work bitmap */
  9883. phba->work_ha |= HA_ERATT;
  9884. /* Indicate polling handles this ERATT */
  9885. phba->hba_flag |= HBA_ERATT_HANDLED;
  9886. return 1;
  9887. }
  9888. /**
  9889. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9890. * @phba: Pointer to HBA context.
  9891. *
  9892. * This function is called to read the SLI4 device error attention registers
  9893. * for possible error attention events. The caller must hold the hostlock
  9894. * with spin_lock_irq().
  9895. *
  9896. * This function returns 1 when there is Error Attention in the Host Attention
  9897. * Register and returns 0 otherwise.
  9898. **/
  9899. static int
  9900. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9901. {
  9902. uint32_t uerr_sta_hi, uerr_sta_lo;
  9903. uint32_t if_type, portsmphr;
  9904. struct lpfc_register portstat_reg;
  9905. /*
  9906. * For now, use the SLI4 device internal unrecoverable error
  9907. * registers for error attention. This can be changed later.
  9908. */
  9909. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9910. switch (if_type) {
  9911. case LPFC_SLI_INTF_IF_TYPE_0:
  9912. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9913. &uerr_sta_lo) ||
  9914. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9915. &uerr_sta_hi)) {
  9916. phba->work_hs |= UNPLUG_ERR;
  9917. phba->work_ha |= HA_ERATT;
  9918. phba->hba_flag |= HBA_ERATT_HANDLED;
  9919. return 1;
  9920. }
  9921. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9922. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9923. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9924. "1423 HBA Unrecoverable error: "
  9925. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9926. "ue_mask_lo_reg=0x%x, "
  9927. "ue_mask_hi_reg=0x%x\n",
  9928. uerr_sta_lo, uerr_sta_hi,
  9929. phba->sli4_hba.ue_mask_lo,
  9930. phba->sli4_hba.ue_mask_hi);
  9931. phba->work_status[0] = uerr_sta_lo;
  9932. phba->work_status[1] = uerr_sta_hi;
  9933. phba->work_ha |= HA_ERATT;
  9934. phba->hba_flag |= HBA_ERATT_HANDLED;
  9935. return 1;
  9936. }
  9937. break;
  9938. case LPFC_SLI_INTF_IF_TYPE_2:
  9939. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9940. &portstat_reg.word0) ||
  9941. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9942. &portsmphr)){
  9943. phba->work_hs |= UNPLUG_ERR;
  9944. phba->work_ha |= HA_ERATT;
  9945. phba->hba_flag |= HBA_ERATT_HANDLED;
  9946. return 1;
  9947. }
  9948. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9949. phba->work_status[0] =
  9950. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9951. phba->work_status[1] =
  9952. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9953. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9954. "2885 Port Status Event: "
  9955. "port status reg 0x%x, "
  9956. "port smphr reg 0x%x, "
  9957. "error 1=0x%x, error 2=0x%x\n",
  9958. portstat_reg.word0,
  9959. portsmphr,
  9960. phba->work_status[0],
  9961. phba->work_status[1]);
  9962. phba->work_ha |= HA_ERATT;
  9963. phba->hba_flag |= HBA_ERATT_HANDLED;
  9964. return 1;
  9965. }
  9966. break;
  9967. case LPFC_SLI_INTF_IF_TYPE_1:
  9968. default:
  9969. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9970. "2886 HBA Error Attention on unsupported "
  9971. "if type %d.", if_type);
  9972. return 1;
  9973. }
  9974. return 0;
  9975. }
  9976. /**
  9977. * lpfc_sli_check_eratt - check error attention events
  9978. * @phba: Pointer to HBA context.
  9979. *
  9980. * This function is called from timer soft interrupt context to check HBA's
  9981. * error attention register bit for error attention events.
  9982. *
  9983. * This function returns 1 when there is Error Attention in the Host Attention
  9984. * Register and returns 0 otherwise.
  9985. **/
  9986. int
  9987. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9988. {
  9989. uint32_t ha_copy;
  9990. /* If somebody is waiting to handle an eratt, don't process it
  9991. * here. The brdkill function will do this.
  9992. */
  9993. if (phba->link_flag & LS_IGNORE_ERATT)
  9994. return 0;
  9995. /* Check if interrupt handler handles this ERATT */
  9996. spin_lock_irq(&phba->hbalock);
  9997. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9998. /* Interrupt handler has handled ERATT */
  9999. spin_unlock_irq(&phba->hbalock);
  10000. return 0;
  10001. }
  10002. /*
  10003. * If there is deferred error attention, do not check for error
  10004. * attention
  10005. */
  10006. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10007. spin_unlock_irq(&phba->hbalock);
  10008. return 0;
  10009. }
  10010. /* If PCI channel is offline, don't process it */
  10011. if (unlikely(pci_channel_offline(phba->pcidev))) {
  10012. spin_unlock_irq(&phba->hbalock);
  10013. return 0;
  10014. }
  10015. switch (phba->sli_rev) {
  10016. case LPFC_SLI_REV2:
  10017. case LPFC_SLI_REV3:
  10018. /* Read chip Host Attention (HA) register */
  10019. ha_copy = lpfc_sli_eratt_read(phba);
  10020. break;
  10021. case LPFC_SLI_REV4:
  10022. /* Read device Uncoverable Error (UERR) registers */
  10023. ha_copy = lpfc_sli4_eratt_read(phba);
  10024. break;
  10025. default:
  10026. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10027. "0299 Invalid SLI revision (%d)\n",
  10028. phba->sli_rev);
  10029. ha_copy = 0;
  10030. break;
  10031. }
  10032. spin_unlock_irq(&phba->hbalock);
  10033. return ha_copy;
  10034. }
  10035. /**
  10036. * lpfc_intr_state_check - Check device state for interrupt handling
  10037. * @phba: Pointer to HBA context.
  10038. *
  10039. * This inline routine checks whether a device or its PCI slot is in a state
  10040. * that the interrupt should be handled.
  10041. *
  10042. * This function returns 0 if the device or the PCI slot is in a state that
  10043. * interrupt should be handled, otherwise -EIO.
  10044. */
  10045. static inline int
  10046. lpfc_intr_state_check(struct lpfc_hba *phba)
  10047. {
  10048. /* If the pci channel is offline, ignore all the interrupts */
  10049. if (unlikely(pci_channel_offline(phba->pcidev)))
  10050. return -EIO;
  10051. /* Update device level interrupt statistics */
  10052. phba->sli.slistat.sli_intr++;
  10053. /* Ignore all interrupts during initialization. */
  10054. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  10055. return -EIO;
  10056. return 0;
  10057. }
  10058. /**
  10059. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  10060. * @irq: Interrupt number.
  10061. * @dev_id: The device context pointer.
  10062. *
  10063. * This function is directly called from the PCI layer as an interrupt
  10064. * service routine when device with SLI-3 interface spec is enabled with
  10065. * MSI-X multi-message interrupt mode and there are slow-path events in
  10066. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  10067. * interrupt mode, this function is called as part of the device-level
  10068. * interrupt handler. When the PCI slot is in error recovery or the HBA
  10069. * is undergoing initialization, the interrupt handler will not process
  10070. * the interrupt. The link attention and ELS ring attention events are
  10071. * handled by the worker thread. The interrupt handler signals the worker
  10072. * thread and returns for these events. This function is called without
  10073. * any lock held. It gets the hbalock to access and update SLI data
  10074. * structures.
  10075. *
  10076. * This function returns IRQ_HANDLED when interrupt is handled else it
  10077. * returns IRQ_NONE.
  10078. **/
  10079. irqreturn_t
  10080. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  10081. {
  10082. struct lpfc_hba *phba;
  10083. uint32_t ha_copy, hc_copy;
  10084. uint32_t work_ha_copy;
  10085. unsigned long status;
  10086. unsigned long iflag;
  10087. uint32_t control;
  10088. MAILBOX_t *mbox, *pmbox;
  10089. struct lpfc_vport *vport;
  10090. struct lpfc_nodelist *ndlp;
  10091. struct lpfc_dmabuf *mp;
  10092. LPFC_MBOXQ_t *pmb;
  10093. int rc;
  10094. /*
  10095. * Get the driver's phba structure from the dev_id and
  10096. * assume the HBA is not interrupting.
  10097. */
  10098. phba = (struct lpfc_hba *)dev_id;
  10099. if (unlikely(!phba))
  10100. return IRQ_NONE;
  10101. /*
  10102. * Stuff needs to be attented to when this function is invoked as an
  10103. * individual interrupt handler in MSI-X multi-message interrupt mode
  10104. */
  10105. if (phba->intr_type == MSIX) {
  10106. /* Check device state for handling interrupt */
  10107. if (lpfc_intr_state_check(phba))
  10108. return IRQ_NONE;
  10109. /* Need to read HA REG for slow-path events */
  10110. spin_lock_irqsave(&phba->hbalock, iflag);
  10111. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  10112. goto unplug_error;
  10113. /* If somebody is waiting to handle an eratt don't process it
  10114. * here. The brdkill function will do this.
  10115. */
  10116. if (phba->link_flag & LS_IGNORE_ERATT)
  10117. ha_copy &= ~HA_ERATT;
  10118. /* Check the need for handling ERATT in interrupt handler */
  10119. if (ha_copy & HA_ERATT) {
  10120. if (phba->hba_flag & HBA_ERATT_HANDLED)
  10121. /* ERATT polling has handled ERATT */
  10122. ha_copy &= ~HA_ERATT;
  10123. else
  10124. /* Indicate interrupt handler handles ERATT */
  10125. phba->hba_flag |= HBA_ERATT_HANDLED;
  10126. }
  10127. /*
  10128. * If there is deferred error attention, do not check for any
  10129. * interrupt.
  10130. */
  10131. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10132. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10133. return IRQ_NONE;
  10134. }
  10135. /* Clear up only attention source related to slow-path */
  10136. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  10137. goto unplug_error;
  10138. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  10139. HC_LAINT_ENA | HC_ERINT_ENA),
  10140. phba->HCregaddr);
  10141. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  10142. phba->HAregaddr);
  10143. writel(hc_copy, phba->HCregaddr);
  10144. readl(phba->HAregaddr); /* flush */
  10145. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10146. } else
  10147. ha_copy = phba->ha_copy;
  10148. work_ha_copy = ha_copy & phba->work_ha_mask;
  10149. if (work_ha_copy) {
  10150. if (work_ha_copy & HA_LATT) {
  10151. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  10152. /*
  10153. * Turn off Link Attention interrupts
  10154. * until CLEAR_LA done
  10155. */
  10156. spin_lock_irqsave(&phba->hbalock, iflag);
  10157. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  10158. if (lpfc_readl(phba->HCregaddr, &control))
  10159. goto unplug_error;
  10160. control &= ~HC_LAINT_ENA;
  10161. writel(control, phba->HCregaddr);
  10162. readl(phba->HCregaddr); /* flush */
  10163. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10164. }
  10165. else
  10166. work_ha_copy &= ~HA_LATT;
  10167. }
  10168. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  10169. /*
  10170. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  10171. * the only slow ring.
  10172. */
  10173. status = (work_ha_copy &
  10174. (HA_RXMASK << (4*LPFC_ELS_RING)));
  10175. status >>= (4*LPFC_ELS_RING);
  10176. if (status & HA_RXMASK) {
  10177. spin_lock_irqsave(&phba->hbalock, iflag);
  10178. if (lpfc_readl(phba->HCregaddr, &control))
  10179. goto unplug_error;
  10180. lpfc_debugfs_slow_ring_trc(phba,
  10181. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  10182. control, status,
  10183. (uint32_t)phba->sli.slistat.sli_intr);
  10184. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  10185. lpfc_debugfs_slow_ring_trc(phba,
  10186. "ISR Disable ring:"
  10187. "pwork:x%x hawork:x%x wait:x%x",
  10188. phba->work_ha, work_ha_copy,
  10189. (uint32_t)((unsigned long)
  10190. &phba->work_waitq));
  10191. control &=
  10192. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  10193. writel(control, phba->HCregaddr);
  10194. readl(phba->HCregaddr); /* flush */
  10195. }
  10196. else {
  10197. lpfc_debugfs_slow_ring_trc(phba,
  10198. "ISR slow ring: pwork:"
  10199. "x%x hawork:x%x wait:x%x",
  10200. phba->work_ha, work_ha_copy,
  10201. (uint32_t)((unsigned long)
  10202. &phba->work_waitq));
  10203. }
  10204. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10205. }
  10206. }
  10207. spin_lock_irqsave(&phba->hbalock, iflag);
  10208. if (work_ha_copy & HA_ERATT) {
  10209. if (lpfc_sli_read_hs(phba))
  10210. goto unplug_error;
  10211. /*
  10212. * Check if there is a deferred error condition
  10213. * is active
  10214. */
  10215. if ((HS_FFER1 & phba->work_hs) &&
  10216. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  10217. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  10218. phba->work_hs)) {
  10219. phba->hba_flag |= DEFER_ERATT;
  10220. /* Clear all interrupt enable conditions */
  10221. writel(0, phba->HCregaddr);
  10222. readl(phba->HCregaddr);
  10223. }
  10224. }
  10225. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  10226. pmb = phba->sli.mbox_active;
  10227. pmbox = &pmb->u.mb;
  10228. mbox = phba->mbox;
  10229. vport = pmb->vport;
  10230. /* First check out the status word */
  10231. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  10232. if (pmbox->mbxOwner != OWN_HOST) {
  10233. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10234. /*
  10235. * Stray Mailbox Interrupt, mbxCommand <cmd>
  10236. * mbxStatus <status>
  10237. */
  10238. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10239. LOG_SLI,
  10240. "(%d):0304 Stray Mailbox "
  10241. "Interrupt mbxCommand x%x "
  10242. "mbxStatus x%x\n",
  10243. (vport ? vport->vpi : 0),
  10244. pmbox->mbxCommand,
  10245. pmbox->mbxStatus);
  10246. /* clear mailbox attention bit */
  10247. work_ha_copy &= ~HA_MBATT;
  10248. } else {
  10249. phba->sli.mbox_active = NULL;
  10250. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10251. phba->last_completion_time = jiffies;
  10252. del_timer(&phba->sli.mbox_tmo);
  10253. if (pmb->mbox_cmpl) {
  10254. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  10255. MAILBOX_CMD_SIZE);
  10256. if (pmb->out_ext_byte_len &&
  10257. pmb->context2)
  10258. lpfc_sli_pcimem_bcopy(
  10259. phba->mbox_ext,
  10260. pmb->context2,
  10261. pmb->out_ext_byte_len);
  10262. }
  10263. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10264. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10265. lpfc_debugfs_disc_trc(vport,
  10266. LPFC_DISC_TRC_MBOX_VPORT,
  10267. "MBOX dflt rpi: : "
  10268. "status:x%x rpi:x%x",
  10269. (uint32_t)pmbox->mbxStatus,
  10270. pmbox->un.varWords[0], 0);
  10271. if (!pmbox->mbxStatus) {
  10272. mp = (struct lpfc_dmabuf *)
  10273. (pmb->context1);
  10274. ndlp = (struct lpfc_nodelist *)
  10275. pmb->context2;
  10276. /* Reg_LOGIN of dflt RPI was
  10277. * successful. new lets get
  10278. * rid of the RPI using the
  10279. * same mbox buffer.
  10280. */
  10281. lpfc_unreg_login(phba,
  10282. vport->vpi,
  10283. pmbox->un.varWords[0],
  10284. pmb);
  10285. pmb->mbox_cmpl =
  10286. lpfc_mbx_cmpl_dflt_rpi;
  10287. pmb->context1 = mp;
  10288. pmb->context2 = ndlp;
  10289. pmb->vport = vport;
  10290. rc = lpfc_sli_issue_mbox(phba,
  10291. pmb,
  10292. MBX_NOWAIT);
  10293. if (rc != MBX_BUSY)
  10294. lpfc_printf_log(phba,
  10295. KERN_ERR,
  10296. LOG_MBOX | LOG_SLI,
  10297. "0350 rc should have"
  10298. "been MBX_BUSY\n");
  10299. if (rc != MBX_NOT_FINISHED)
  10300. goto send_current_mbox;
  10301. }
  10302. }
  10303. spin_lock_irqsave(
  10304. &phba->pport->work_port_lock,
  10305. iflag);
  10306. phba->pport->work_port_events &=
  10307. ~WORKER_MBOX_TMO;
  10308. spin_unlock_irqrestore(
  10309. &phba->pport->work_port_lock,
  10310. iflag);
  10311. lpfc_mbox_cmpl_put(phba, pmb);
  10312. }
  10313. } else
  10314. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10315. if ((work_ha_copy & HA_MBATT) &&
  10316. (phba->sli.mbox_active == NULL)) {
  10317. send_current_mbox:
  10318. /* Process next mailbox command if there is one */
  10319. do {
  10320. rc = lpfc_sli_issue_mbox(phba, NULL,
  10321. MBX_NOWAIT);
  10322. } while (rc == MBX_NOT_FINISHED);
  10323. if (rc != MBX_SUCCESS)
  10324. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10325. LOG_SLI, "0349 rc should be "
  10326. "MBX_SUCCESS\n");
  10327. }
  10328. spin_lock_irqsave(&phba->hbalock, iflag);
  10329. phba->work_ha |= work_ha_copy;
  10330. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10331. lpfc_worker_wake_up(phba);
  10332. }
  10333. return IRQ_HANDLED;
  10334. unplug_error:
  10335. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10336. return IRQ_HANDLED;
  10337. } /* lpfc_sli_sp_intr_handler */
  10338. /**
  10339. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  10340. * @irq: Interrupt number.
  10341. * @dev_id: The device context pointer.
  10342. *
  10343. * This function is directly called from the PCI layer as an interrupt
  10344. * service routine when device with SLI-3 interface spec is enabled with
  10345. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10346. * ring event in the HBA. However, when the device is enabled with either
  10347. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10348. * device-level interrupt handler. When the PCI slot is in error recovery
  10349. * or the HBA is undergoing initialization, the interrupt handler will not
  10350. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10351. * the intrrupt context. This function is called without any lock held.
  10352. * It gets the hbalock to access and update SLI data structures.
  10353. *
  10354. * This function returns IRQ_HANDLED when interrupt is handled else it
  10355. * returns IRQ_NONE.
  10356. **/
  10357. irqreturn_t
  10358. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  10359. {
  10360. struct lpfc_hba *phba;
  10361. uint32_t ha_copy;
  10362. unsigned long status;
  10363. unsigned long iflag;
  10364. /* Get the driver's phba structure from the dev_id and
  10365. * assume the HBA is not interrupting.
  10366. */
  10367. phba = (struct lpfc_hba *) dev_id;
  10368. if (unlikely(!phba))
  10369. return IRQ_NONE;
  10370. /*
  10371. * Stuff needs to be attented to when this function is invoked as an
  10372. * individual interrupt handler in MSI-X multi-message interrupt mode
  10373. */
  10374. if (phba->intr_type == MSIX) {
  10375. /* Check device state for handling interrupt */
  10376. if (lpfc_intr_state_check(phba))
  10377. return IRQ_NONE;
  10378. /* Need to read HA REG for FCP ring and other ring events */
  10379. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  10380. return IRQ_HANDLED;
  10381. /* Clear up only attention source related to fast-path */
  10382. spin_lock_irqsave(&phba->hbalock, iflag);
  10383. /*
  10384. * If there is deferred error attention, do not check for
  10385. * any interrupt.
  10386. */
  10387. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10388. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10389. return IRQ_NONE;
  10390. }
  10391. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  10392. phba->HAregaddr);
  10393. readl(phba->HAregaddr); /* flush */
  10394. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10395. } else
  10396. ha_copy = phba->ha_copy;
  10397. /*
  10398. * Process all events on FCP ring. Take the optimized path for FCP IO.
  10399. */
  10400. ha_copy &= ~(phba->work_ha_mask);
  10401. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  10402. status >>= (4*LPFC_FCP_RING);
  10403. if (status & HA_RXMASK)
  10404. lpfc_sli_handle_fast_ring_event(phba,
  10405. &phba->sli.ring[LPFC_FCP_RING],
  10406. status);
  10407. if (phba->cfg_multi_ring_support == 2) {
  10408. /*
  10409. * Process all events on extra ring. Take the optimized path
  10410. * for extra ring IO.
  10411. */
  10412. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  10413. status >>= (4*LPFC_EXTRA_RING);
  10414. if (status & HA_RXMASK) {
  10415. lpfc_sli_handle_fast_ring_event(phba,
  10416. &phba->sli.ring[LPFC_EXTRA_RING],
  10417. status);
  10418. }
  10419. }
  10420. return IRQ_HANDLED;
  10421. } /* lpfc_sli_fp_intr_handler */
  10422. /**
  10423. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  10424. * @irq: Interrupt number.
  10425. * @dev_id: The device context pointer.
  10426. *
  10427. * This function is the HBA device-level interrupt handler to device with
  10428. * SLI-3 interface spec, called from the PCI layer when either MSI or
  10429. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  10430. * requires driver attention. This function invokes the slow-path interrupt
  10431. * attention handling function and fast-path interrupt attention handling
  10432. * function in turn to process the relevant HBA attention events. This
  10433. * function is called without any lock held. It gets the hbalock to access
  10434. * and update SLI data structures.
  10435. *
  10436. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10437. * returns IRQ_NONE.
  10438. **/
  10439. irqreturn_t
  10440. lpfc_sli_intr_handler(int irq, void *dev_id)
  10441. {
  10442. struct lpfc_hba *phba;
  10443. irqreturn_t sp_irq_rc, fp_irq_rc;
  10444. unsigned long status1, status2;
  10445. uint32_t hc_copy;
  10446. /*
  10447. * Get the driver's phba structure from the dev_id and
  10448. * assume the HBA is not interrupting.
  10449. */
  10450. phba = (struct lpfc_hba *) dev_id;
  10451. if (unlikely(!phba))
  10452. return IRQ_NONE;
  10453. /* Check device state for handling interrupt */
  10454. if (lpfc_intr_state_check(phba))
  10455. return IRQ_NONE;
  10456. spin_lock(&phba->hbalock);
  10457. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  10458. spin_unlock(&phba->hbalock);
  10459. return IRQ_HANDLED;
  10460. }
  10461. if (unlikely(!phba->ha_copy)) {
  10462. spin_unlock(&phba->hbalock);
  10463. return IRQ_NONE;
  10464. } else if (phba->ha_copy & HA_ERATT) {
  10465. if (phba->hba_flag & HBA_ERATT_HANDLED)
  10466. /* ERATT polling has handled ERATT */
  10467. phba->ha_copy &= ~HA_ERATT;
  10468. else
  10469. /* Indicate interrupt handler handles ERATT */
  10470. phba->hba_flag |= HBA_ERATT_HANDLED;
  10471. }
  10472. /*
  10473. * If there is deferred error attention, do not check for any interrupt.
  10474. */
  10475. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10476. spin_unlock(&phba->hbalock);
  10477. return IRQ_NONE;
  10478. }
  10479. /* Clear attention sources except link and error attentions */
  10480. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  10481. spin_unlock(&phba->hbalock);
  10482. return IRQ_HANDLED;
  10483. }
  10484. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  10485. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  10486. phba->HCregaddr);
  10487. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  10488. writel(hc_copy, phba->HCregaddr);
  10489. readl(phba->HAregaddr); /* flush */
  10490. spin_unlock(&phba->hbalock);
  10491. /*
  10492. * Invokes slow-path host attention interrupt handling as appropriate.
  10493. */
  10494. /* status of events with mailbox and link attention */
  10495. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  10496. /* status of events with ELS ring */
  10497. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  10498. status2 >>= (4*LPFC_ELS_RING);
  10499. if (status1 || (status2 & HA_RXMASK))
  10500. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  10501. else
  10502. sp_irq_rc = IRQ_NONE;
  10503. /*
  10504. * Invoke fast-path host attention interrupt handling as appropriate.
  10505. */
  10506. /* status of events with FCP ring */
  10507. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  10508. status1 >>= (4*LPFC_FCP_RING);
  10509. /* status of events with extra ring */
  10510. if (phba->cfg_multi_ring_support == 2) {
  10511. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  10512. status2 >>= (4*LPFC_EXTRA_RING);
  10513. } else
  10514. status2 = 0;
  10515. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  10516. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  10517. else
  10518. fp_irq_rc = IRQ_NONE;
  10519. /* Return device-level interrupt handling status */
  10520. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  10521. } /* lpfc_sli_intr_handler */
  10522. /**
  10523. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  10524. * @phba: pointer to lpfc hba data structure.
  10525. *
  10526. * This routine is invoked by the worker thread to process all the pending
  10527. * SLI4 FCP abort XRI events.
  10528. **/
  10529. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  10530. {
  10531. struct lpfc_cq_event *cq_event;
  10532. /* First, declare the fcp xri abort event has been handled */
  10533. spin_lock_irq(&phba->hbalock);
  10534. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  10535. spin_unlock_irq(&phba->hbalock);
  10536. /* Now, handle all the fcp xri abort events */
  10537. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  10538. /* Get the first event from the head of the event queue */
  10539. spin_lock_irq(&phba->hbalock);
  10540. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  10541. cq_event, struct lpfc_cq_event, list);
  10542. spin_unlock_irq(&phba->hbalock);
  10543. /* Notify aborted XRI for FCP work queue */
  10544. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10545. /* Free the event processed back to the free pool */
  10546. lpfc_sli4_cq_event_release(phba, cq_event);
  10547. }
  10548. }
  10549. /**
  10550. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  10551. * @phba: pointer to lpfc hba data structure.
  10552. *
  10553. * This routine is invoked by the worker thread to process all the pending
  10554. * SLI4 els abort xri events.
  10555. **/
  10556. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  10557. {
  10558. struct lpfc_cq_event *cq_event;
  10559. /* First, declare the els xri abort event has been handled */
  10560. spin_lock_irq(&phba->hbalock);
  10561. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  10562. spin_unlock_irq(&phba->hbalock);
  10563. /* Now, handle all the els xri abort events */
  10564. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  10565. /* Get the first event from the head of the event queue */
  10566. spin_lock_irq(&phba->hbalock);
  10567. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  10568. cq_event, struct lpfc_cq_event, list);
  10569. spin_unlock_irq(&phba->hbalock);
  10570. /* Notify aborted XRI for ELS work queue */
  10571. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10572. /* Free the event processed back to the free pool */
  10573. lpfc_sli4_cq_event_release(phba, cq_event);
  10574. }
  10575. }
  10576. /**
  10577. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  10578. * @phba: pointer to lpfc hba data structure
  10579. * @pIocbIn: pointer to the rspiocbq
  10580. * @pIocbOut: pointer to the cmdiocbq
  10581. * @wcqe: pointer to the complete wcqe
  10582. *
  10583. * This routine transfers the fields of a command iocbq to a response iocbq
  10584. * by copying all the IOCB fields from command iocbq and transferring the
  10585. * completion status information from the complete wcqe.
  10586. **/
  10587. static void
  10588. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  10589. struct lpfc_iocbq *pIocbIn,
  10590. struct lpfc_iocbq *pIocbOut,
  10591. struct lpfc_wcqe_complete *wcqe)
  10592. {
  10593. int numBdes, i;
  10594. unsigned long iflags;
  10595. uint32_t status, max_response;
  10596. struct lpfc_dmabuf *dmabuf;
  10597. struct ulp_bde64 *bpl, bde;
  10598. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  10599. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  10600. sizeof(struct lpfc_iocbq) - offset);
  10601. /* Map WCQE parameters into irspiocb parameters */
  10602. status = bf_get(lpfc_wcqe_c_status, wcqe);
  10603. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  10604. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  10605. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  10606. pIocbIn->iocb.un.fcpi.fcpi_parm =
  10607. pIocbOut->iocb.un.fcpi.fcpi_parm -
  10608. wcqe->total_data_placed;
  10609. else
  10610. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10611. else {
  10612. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10613. switch (pIocbOut->iocb.ulpCommand) {
  10614. case CMD_ELS_REQUEST64_CR:
  10615. dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
  10616. bpl = (struct ulp_bde64 *)dmabuf->virt;
  10617. bde.tus.w = le32_to_cpu(bpl[1].tus.w);
  10618. max_response = bde.tus.f.bdeSize;
  10619. break;
  10620. case CMD_GEN_REQUEST64_CR:
  10621. max_response = 0;
  10622. if (!pIocbOut->context3)
  10623. break;
  10624. numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
  10625. sizeof(struct ulp_bde64);
  10626. dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
  10627. bpl = (struct ulp_bde64 *)dmabuf->virt;
  10628. for (i = 0; i < numBdes; i++) {
  10629. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  10630. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  10631. max_response += bde.tus.f.bdeSize;
  10632. }
  10633. break;
  10634. default:
  10635. max_response = wcqe->total_data_placed;
  10636. break;
  10637. }
  10638. if (max_response < wcqe->total_data_placed)
  10639. pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
  10640. else
  10641. pIocbIn->iocb.un.genreq64.bdl.bdeSize =
  10642. wcqe->total_data_placed;
  10643. }
  10644. /* Convert BG errors for completion status */
  10645. if (status == CQE_STATUS_DI_ERROR) {
  10646. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  10647. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  10648. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  10649. else
  10650. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  10651. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  10652. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  10653. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10654. BGS_GUARD_ERR_MASK;
  10655. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  10656. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10657. BGS_APPTAG_ERR_MASK;
  10658. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  10659. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10660. BGS_REFTAG_ERR_MASK;
  10661. /* Check to see if there was any good data before the error */
  10662. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  10663. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10664. BGS_HI_WATER_MARK_PRESENT_MASK;
  10665. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  10666. wcqe->total_data_placed;
  10667. }
  10668. /*
  10669. * Set ALL the error bits to indicate we don't know what
  10670. * type of error it is.
  10671. */
  10672. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  10673. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10674. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  10675. BGS_GUARD_ERR_MASK);
  10676. }
  10677. /* Pick up HBA exchange busy condition */
  10678. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  10679. spin_lock_irqsave(&phba->hbalock, iflags);
  10680. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  10681. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10682. }
  10683. }
  10684. /**
  10685. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  10686. * @phba: Pointer to HBA context object.
  10687. * @wcqe: Pointer to work-queue completion queue entry.
  10688. *
  10689. * This routine handles an ELS work-queue completion event and construct
  10690. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  10691. * discovery engine to handle.
  10692. *
  10693. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  10694. **/
  10695. static struct lpfc_iocbq *
  10696. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  10697. struct lpfc_iocbq *irspiocbq)
  10698. {
  10699. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  10700. struct lpfc_iocbq *cmdiocbq;
  10701. struct lpfc_wcqe_complete *wcqe;
  10702. unsigned long iflags;
  10703. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  10704. spin_lock_irqsave(&pring->ring_lock, iflags);
  10705. pring->stats.iocb_event++;
  10706. /* Look up the ELS command IOCB and create pseudo response IOCB */
  10707. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10708. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10709. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10710. if (unlikely(!cmdiocbq)) {
  10711. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10712. "0386 ELS complete with no corresponding "
  10713. "cmdiocb: iotag (%d)\n",
  10714. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10715. lpfc_sli_release_iocbq(phba, irspiocbq);
  10716. return NULL;
  10717. }
  10718. /* Fake the irspiocbq and copy necessary response information */
  10719. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  10720. return irspiocbq;
  10721. }
  10722. /**
  10723. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  10724. * @phba: Pointer to HBA context object.
  10725. * @cqe: Pointer to mailbox completion queue entry.
  10726. *
  10727. * This routine process a mailbox completion queue entry with asynchrous
  10728. * event.
  10729. *
  10730. * Return: true if work posted to worker thread, otherwise false.
  10731. **/
  10732. static bool
  10733. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10734. {
  10735. struct lpfc_cq_event *cq_event;
  10736. unsigned long iflags;
  10737. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10738. "0392 Async Event: word0:x%x, word1:x%x, "
  10739. "word2:x%x, word3:x%x\n", mcqe->word0,
  10740. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10741. /* Allocate a new internal CQ_EVENT entry */
  10742. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10743. if (!cq_event) {
  10744. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10745. "0394 Failed to allocate CQ_EVENT entry\n");
  10746. return false;
  10747. }
  10748. /* Move the CQE into an asynchronous event entry */
  10749. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10750. spin_lock_irqsave(&phba->hbalock, iflags);
  10751. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10752. /* Set the async event flag */
  10753. phba->hba_flag |= ASYNC_EVENT;
  10754. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10755. return true;
  10756. }
  10757. /**
  10758. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10759. * @phba: Pointer to HBA context object.
  10760. * @cqe: Pointer to mailbox completion queue entry.
  10761. *
  10762. * This routine process a mailbox completion queue entry with mailbox
  10763. * completion event.
  10764. *
  10765. * Return: true if work posted to worker thread, otherwise false.
  10766. **/
  10767. static bool
  10768. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10769. {
  10770. uint32_t mcqe_status;
  10771. MAILBOX_t *mbox, *pmbox;
  10772. struct lpfc_mqe *mqe;
  10773. struct lpfc_vport *vport;
  10774. struct lpfc_nodelist *ndlp;
  10775. struct lpfc_dmabuf *mp;
  10776. unsigned long iflags;
  10777. LPFC_MBOXQ_t *pmb;
  10778. bool workposted = false;
  10779. int rc;
  10780. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10781. if (!bf_get(lpfc_trailer_completed, mcqe))
  10782. goto out_no_mqe_complete;
  10783. /* Get the reference to the active mbox command */
  10784. spin_lock_irqsave(&phba->hbalock, iflags);
  10785. pmb = phba->sli.mbox_active;
  10786. if (unlikely(!pmb)) {
  10787. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10788. "1832 No pending MBOX command to handle\n");
  10789. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10790. goto out_no_mqe_complete;
  10791. }
  10792. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10793. mqe = &pmb->u.mqe;
  10794. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10795. mbox = phba->mbox;
  10796. vport = pmb->vport;
  10797. /* Reset heartbeat timer */
  10798. phba->last_completion_time = jiffies;
  10799. del_timer(&phba->sli.mbox_tmo);
  10800. /* Move mbox data to caller's mailbox region, do endian swapping */
  10801. if (pmb->mbox_cmpl && mbox)
  10802. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10803. /*
  10804. * For mcqe errors, conditionally move a modified error code to
  10805. * the mbox so that the error will not be missed.
  10806. */
  10807. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10808. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10809. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10810. bf_set(lpfc_mqe_status, mqe,
  10811. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10812. }
  10813. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10814. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10815. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10816. "MBOX dflt rpi: status:x%x rpi:x%x",
  10817. mcqe_status,
  10818. pmbox->un.varWords[0], 0);
  10819. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10820. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10821. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10822. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10823. * RID of the PPI using the same mbox buffer.
  10824. */
  10825. lpfc_unreg_login(phba, vport->vpi,
  10826. pmbox->un.varWords[0], pmb);
  10827. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10828. pmb->context1 = mp;
  10829. pmb->context2 = ndlp;
  10830. pmb->vport = vport;
  10831. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10832. if (rc != MBX_BUSY)
  10833. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10834. LOG_SLI, "0385 rc should "
  10835. "have been MBX_BUSY\n");
  10836. if (rc != MBX_NOT_FINISHED)
  10837. goto send_current_mbox;
  10838. }
  10839. }
  10840. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10841. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10842. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10843. /* There is mailbox completion work to do */
  10844. spin_lock_irqsave(&phba->hbalock, iflags);
  10845. __lpfc_mbox_cmpl_put(phba, pmb);
  10846. phba->work_ha |= HA_MBATT;
  10847. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10848. workposted = true;
  10849. send_current_mbox:
  10850. spin_lock_irqsave(&phba->hbalock, iflags);
  10851. /* Release the mailbox command posting token */
  10852. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10853. /* Setting active mailbox pointer need to be in sync to flag clear */
  10854. phba->sli.mbox_active = NULL;
  10855. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10856. /* Wake up worker thread to post the next pending mailbox command */
  10857. lpfc_worker_wake_up(phba);
  10858. out_no_mqe_complete:
  10859. if (bf_get(lpfc_trailer_consumed, mcqe))
  10860. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10861. return workposted;
  10862. }
  10863. /**
  10864. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10865. * @phba: Pointer to HBA context object.
  10866. * @cqe: Pointer to mailbox completion queue entry.
  10867. *
  10868. * This routine process a mailbox completion queue entry, it invokes the
  10869. * proper mailbox complete handling or asynchrous event handling routine
  10870. * according to the MCQE's async bit.
  10871. *
  10872. * Return: true if work posted to worker thread, otherwise false.
  10873. **/
  10874. static bool
  10875. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10876. {
  10877. struct lpfc_mcqe mcqe;
  10878. bool workposted;
  10879. /* Copy the mailbox MCQE and convert endian order as needed */
  10880. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10881. /* Invoke the proper event handling routine */
  10882. if (!bf_get(lpfc_trailer_async, &mcqe))
  10883. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10884. else
  10885. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10886. return workposted;
  10887. }
  10888. /**
  10889. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10890. * @phba: Pointer to HBA context object.
  10891. * @cq: Pointer to associated CQ
  10892. * @wcqe: Pointer to work-queue completion queue entry.
  10893. *
  10894. * This routine handles an ELS work-queue completion event.
  10895. *
  10896. * Return: true if work posted to worker thread, otherwise false.
  10897. **/
  10898. static bool
  10899. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10900. struct lpfc_wcqe_complete *wcqe)
  10901. {
  10902. struct lpfc_iocbq *irspiocbq;
  10903. unsigned long iflags;
  10904. struct lpfc_sli_ring *pring = cq->pring;
  10905. int txq_cnt = 0;
  10906. int txcmplq_cnt = 0;
  10907. int fcp_txcmplq_cnt = 0;
  10908. /* Get an irspiocbq for later ELS response processing use */
  10909. irspiocbq = lpfc_sli_get_iocbq(phba);
  10910. if (!irspiocbq) {
  10911. if (!list_empty(&pring->txq))
  10912. txq_cnt++;
  10913. if (!list_empty(&pring->txcmplq))
  10914. txcmplq_cnt++;
  10915. if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
  10916. fcp_txcmplq_cnt++;
  10917. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10918. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10919. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10920. txq_cnt, phba->iocb_cnt,
  10921. fcp_txcmplq_cnt,
  10922. txcmplq_cnt);
  10923. return false;
  10924. }
  10925. /* Save off the slow-path queue event for work thread to process */
  10926. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10927. spin_lock_irqsave(&phba->hbalock, iflags);
  10928. list_add_tail(&irspiocbq->cq_event.list,
  10929. &phba->sli4_hba.sp_queue_event);
  10930. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10931. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10932. return true;
  10933. }
  10934. /**
  10935. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10936. * @phba: Pointer to HBA context object.
  10937. * @wcqe: Pointer to work-queue completion queue entry.
  10938. *
  10939. * This routine handles slow-path WQ entry comsumed event by invoking the
  10940. * proper WQ release routine to the slow-path WQ.
  10941. **/
  10942. static void
  10943. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10944. struct lpfc_wcqe_release *wcqe)
  10945. {
  10946. /* sanity check on queue memory */
  10947. if (unlikely(!phba->sli4_hba.els_wq))
  10948. return;
  10949. /* Check for the slow-path ELS work queue */
  10950. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10951. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10952. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10953. else
  10954. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10955. "2579 Slow-path wqe consume event carries "
  10956. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10957. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10958. phba->sli4_hba.els_wq->queue_id);
  10959. }
  10960. /**
  10961. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10962. * @phba: Pointer to HBA context object.
  10963. * @cq: Pointer to a WQ completion queue.
  10964. * @wcqe: Pointer to work-queue completion queue entry.
  10965. *
  10966. * This routine handles an XRI abort event.
  10967. *
  10968. * Return: true if work posted to worker thread, otherwise false.
  10969. **/
  10970. static bool
  10971. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10972. struct lpfc_queue *cq,
  10973. struct sli4_wcqe_xri_aborted *wcqe)
  10974. {
  10975. bool workposted = false;
  10976. struct lpfc_cq_event *cq_event;
  10977. unsigned long iflags;
  10978. /* Allocate a new internal CQ_EVENT entry */
  10979. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10980. if (!cq_event) {
  10981. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10982. "0602 Failed to allocate CQ_EVENT entry\n");
  10983. return false;
  10984. }
  10985. /* Move the CQE into the proper xri abort event list */
  10986. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10987. switch (cq->subtype) {
  10988. case LPFC_FCP:
  10989. spin_lock_irqsave(&phba->hbalock, iflags);
  10990. list_add_tail(&cq_event->list,
  10991. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10992. /* Set the fcp xri abort event flag */
  10993. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10994. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10995. workposted = true;
  10996. break;
  10997. case LPFC_ELS:
  10998. spin_lock_irqsave(&phba->hbalock, iflags);
  10999. list_add_tail(&cq_event->list,
  11000. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  11001. /* Set the els xri abort event flag */
  11002. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  11003. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11004. workposted = true;
  11005. break;
  11006. default:
  11007. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11008. "0603 Invalid work queue CQE subtype (x%x)\n",
  11009. cq->subtype);
  11010. workposted = false;
  11011. break;
  11012. }
  11013. return workposted;
  11014. }
  11015. /**
  11016. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  11017. * @phba: Pointer to HBA context object.
  11018. * @rcqe: Pointer to receive-queue completion queue entry.
  11019. *
  11020. * This routine process a receive-queue completion queue entry.
  11021. *
  11022. * Return: true if work posted to worker thread, otherwise false.
  11023. **/
  11024. static bool
  11025. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  11026. {
  11027. bool workposted = false;
  11028. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  11029. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  11030. struct hbq_dmabuf *dma_buf;
  11031. uint32_t status, rq_id;
  11032. unsigned long iflags;
  11033. /* sanity check on queue memory */
  11034. if (unlikely(!hrq) || unlikely(!drq))
  11035. return workposted;
  11036. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  11037. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  11038. else
  11039. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  11040. if (rq_id != hrq->queue_id)
  11041. goto out;
  11042. status = bf_get(lpfc_rcqe_status, rcqe);
  11043. switch (status) {
  11044. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  11045. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11046. "2537 Receive Frame Truncated!!\n");
  11047. hrq->RQ_buf_trunc++;
  11048. case FC_STATUS_RQ_SUCCESS:
  11049. lpfc_sli4_rq_release(hrq, drq);
  11050. spin_lock_irqsave(&phba->hbalock, iflags);
  11051. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  11052. if (!dma_buf) {
  11053. hrq->RQ_no_buf_found++;
  11054. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11055. goto out;
  11056. }
  11057. hrq->RQ_rcv_buf++;
  11058. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  11059. /* save off the frame for the word thread to process */
  11060. list_add_tail(&dma_buf->cq_event.list,
  11061. &phba->sli4_hba.sp_queue_event);
  11062. /* Frame received */
  11063. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  11064. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11065. workposted = true;
  11066. break;
  11067. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  11068. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  11069. hrq->RQ_no_posted_buf++;
  11070. /* Post more buffers if possible */
  11071. spin_lock_irqsave(&phba->hbalock, iflags);
  11072. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  11073. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11074. workposted = true;
  11075. break;
  11076. }
  11077. out:
  11078. return workposted;
  11079. }
  11080. /**
  11081. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  11082. * @phba: Pointer to HBA context object.
  11083. * @cq: Pointer to the completion queue.
  11084. * @wcqe: Pointer to a completion queue entry.
  11085. *
  11086. * This routine process a slow-path work-queue or receive queue completion queue
  11087. * entry.
  11088. *
  11089. * Return: true if work posted to worker thread, otherwise false.
  11090. **/
  11091. static bool
  11092. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11093. struct lpfc_cqe *cqe)
  11094. {
  11095. struct lpfc_cqe cqevt;
  11096. bool workposted = false;
  11097. /* Copy the work queue CQE and convert endian order if needed */
  11098. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  11099. /* Check and process for different type of WCQE and dispatch */
  11100. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  11101. case CQE_CODE_COMPL_WQE:
  11102. /* Process the WQ/RQ complete event */
  11103. phba->last_completion_time = jiffies;
  11104. workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
  11105. (struct lpfc_wcqe_complete *)&cqevt);
  11106. break;
  11107. case CQE_CODE_RELEASE_WQE:
  11108. /* Process the WQ release event */
  11109. lpfc_sli4_sp_handle_rel_wcqe(phba,
  11110. (struct lpfc_wcqe_release *)&cqevt);
  11111. break;
  11112. case CQE_CODE_XRI_ABORTED:
  11113. /* Process the WQ XRI abort event */
  11114. phba->last_completion_time = jiffies;
  11115. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  11116. (struct sli4_wcqe_xri_aborted *)&cqevt);
  11117. break;
  11118. case CQE_CODE_RECEIVE:
  11119. case CQE_CODE_RECEIVE_V1:
  11120. /* Process the RQ event */
  11121. phba->last_completion_time = jiffies;
  11122. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  11123. (struct lpfc_rcqe *)&cqevt);
  11124. break;
  11125. default:
  11126. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11127. "0388 Not a valid WCQE code: x%x\n",
  11128. bf_get(lpfc_cqe_code, &cqevt));
  11129. break;
  11130. }
  11131. return workposted;
  11132. }
  11133. /**
  11134. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  11135. * @phba: Pointer to HBA context object.
  11136. * @eqe: Pointer to fast-path event queue entry.
  11137. *
  11138. * This routine process a event queue entry from the slow-path event queue.
  11139. * It will check the MajorCode and MinorCode to determine this is for a
  11140. * completion event on a completion queue, if not, an error shall be logged
  11141. * and just return. Otherwise, it will get to the corresponding completion
  11142. * queue and process all the entries on that completion queue, rearm the
  11143. * completion queue, and then return.
  11144. *
  11145. **/
  11146. static void
  11147. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  11148. struct lpfc_queue *speq)
  11149. {
  11150. struct lpfc_queue *cq = NULL, *childq;
  11151. struct lpfc_cqe *cqe;
  11152. bool workposted = false;
  11153. int ecount = 0;
  11154. uint16_t cqid;
  11155. /* Get the reference to the corresponding CQ */
  11156. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11157. list_for_each_entry(childq, &speq->child_list, list) {
  11158. if (childq->queue_id == cqid) {
  11159. cq = childq;
  11160. break;
  11161. }
  11162. }
  11163. if (unlikely(!cq)) {
  11164. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11165. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11166. "0365 Slow-path CQ identifier "
  11167. "(%d) does not exist\n", cqid);
  11168. return;
  11169. }
  11170. /* Process all the entries to the CQ */
  11171. switch (cq->type) {
  11172. case LPFC_MCQ:
  11173. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11174. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  11175. if (!(++ecount % cq->entry_repost))
  11176. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11177. cq->CQ_mbox++;
  11178. }
  11179. break;
  11180. case LPFC_WCQ:
  11181. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11182. if (cq->subtype == LPFC_FCP)
  11183. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  11184. cqe);
  11185. else
  11186. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  11187. cqe);
  11188. if (!(++ecount % cq->entry_repost))
  11189. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11190. }
  11191. /* Track the max number of CQEs processed in 1 EQ */
  11192. if (ecount > cq->CQ_max_cqe)
  11193. cq->CQ_max_cqe = ecount;
  11194. break;
  11195. default:
  11196. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11197. "0370 Invalid completion queue type (%d)\n",
  11198. cq->type);
  11199. return;
  11200. }
  11201. /* Catch the no cq entry condition, log an error */
  11202. if (unlikely(ecount == 0))
  11203. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11204. "0371 No entry from the CQ: identifier "
  11205. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  11206. /* In any case, flash and re-arm the RCQ */
  11207. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11208. /* wake up worker thread if there are works to be done */
  11209. if (workposted)
  11210. lpfc_worker_wake_up(phba);
  11211. }
  11212. /**
  11213. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  11214. * @phba: Pointer to HBA context object.
  11215. * @cq: Pointer to associated CQ
  11216. * @wcqe: Pointer to work-queue completion queue entry.
  11217. *
  11218. * This routine process a fast-path work queue completion entry from fast-path
  11219. * event queue for FCP command response completion.
  11220. **/
  11221. static void
  11222. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11223. struct lpfc_wcqe_complete *wcqe)
  11224. {
  11225. struct lpfc_sli_ring *pring = cq->pring;
  11226. struct lpfc_iocbq *cmdiocbq;
  11227. struct lpfc_iocbq irspiocbq;
  11228. unsigned long iflags;
  11229. /* Check for response status */
  11230. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  11231. /* If resource errors reported from HBA, reduce queue
  11232. * depth of the SCSI device.
  11233. */
  11234. if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
  11235. IOSTAT_LOCAL_REJECT)) &&
  11236. ((wcqe->parameter & IOERR_PARAM_MASK) ==
  11237. IOERR_NO_RESOURCES))
  11238. phba->lpfc_rampdown_queue_depth(phba);
  11239. /* Log the error status */
  11240. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11241. "0373 FCP complete error: status=x%x, "
  11242. "hw_status=x%x, total_data_specified=%d, "
  11243. "parameter=x%x, word3=x%x\n",
  11244. bf_get(lpfc_wcqe_c_status, wcqe),
  11245. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  11246. wcqe->total_data_placed, wcqe->parameter,
  11247. wcqe->word3);
  11248. }
  11249. /* Look up the FCP command IOCB and create pseudo response IOCB */
  11250. spin_lock_irqsave(&pring->ring_lock, iflags);
  11251. pring->stats.iocb_event++;
  11252. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  11253. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11254. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  11255. if (unlikely(!cmdiocbq)) {
  11256. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11257. "0374 FCP complete with no corresponding "
  11258. "cmdiocb: iotag (%d)\n",
  11259. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11260. return;
  11261. }
  11262. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  11263. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11264. "0375 FCP cmdiocb not callback function "
  11265. "iotag: (%d)\n",
  11266. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11267. return;
  11268. }
  11269. /* Fake the irspiocb and copy necessary response information */
  11270. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  11271. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  11272. spin_lock_irqsave(&phba->hbalock, iflags);
  11273. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  11274. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11275. }
  11276. /* Pass the cmd_iocb and the rsp state to the upper layer */
  11277. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  11278. }
  11279. /**
  11280. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  11281. * @phba: Pointer to HBA context object.
  11282. * @cq: Pointer to completion queue.
  11283. * @wcqe: Pointer to work-queue completion queue entry.
  11284. *
  11285. * This routine handles an fast-path WQ entry comsumed event by invoking the
  11286. * proper WQ release routine to the slow-path WQ.
  11287. **/
  11288. static void
  11289. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11290. struct lpfc_wcqe_release *wcqe)
  11291. {
  11292. struct lpfc_queue *childwq;
  11293. bool wqid_matched = false;
  11294. uint16_t fcp_wqid;
  11295. /* Check for fast-path FCP work queue release */
  11296. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  11297. list_for_each_entry(childwq, &cq->child_list, list) {
  11298. if (childwq->queue_id == fcp_wqid) {
  11299. lpfc_sli4_wq_release(childwq,
  11300. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  11301. wqid_matched = true;
  11302. break;
  11303. }
  11304. }
  11305. /* Report warning log message if no match found */
  11306. if (wqid_matched != true)
  11307. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11308. "2580 Fast-path wqe consume event carries "
  11309. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  11310. }
  11311. /**
  11312. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  11313. * @cq: Pointer to the completion queue.
  11314. * @eqe: Pointer to fast-path completion queue entry.
  11315. *
  11316. * This routine process a fast-path work queue completion entry from fast-path
  11317. * event queue for FCP command response completion.
  11318. **/
  11319. static int
  11320. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11321. struct lpfc_cqe *cqe)
  11322. {
  11323. struct lpfc_wcqe_release wcqe;
  11324. bool workposted = false;
  11325. /* Copy the work queue CQE and convert endian order if needed */
  11326. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  11327. /* Check and process for different type of WCQE and dispatch */
  11328. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  11329. case CQE_CODE_COMPL_WQE:
  11330. cq->CQ_wq++;
  11331. /* Process the WQ complete event */
  11332. phba->last_completion_time = jiffies;
  11333. lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
  11334. (struct lpfc_wcqe_complete *)&wcqe);
  11335. break;
  11336. case CQE_CODE_RELEASE_WQE:
  11337. cq->CQ_release_wqe++;
  11338. /* Process the WQ release event */
  11339. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  11340. (struct lpfc_wcqe_release *)&wcqe);
  11341. break;
  11342. case CQE_CODE_XRI_ABORTED:
  11343. cq->CQ_xri_aborted++;
  11344. /* Process the WQ XRI abort event */
  11345. phba->last_completion_time = jiffies;
  11346. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  11347. (struct sli4_wcqe_xri_aborted *)&wcqe);
  11348. break;
  11349. default:
  11350. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11351. "0144 Not a valid WCQE code: x%x\n",
  11352. bf_get(lpfc_wcqe_c_code, &wcqe));
  11353. break;
  11354. }
  11355. return workposted;
  11356. }
  11357. /**
  11358. * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
  11359. * @phba: Pointer to HBA context object.
  11360. * @eqe: Pointer to fast-path event queue entry.
  11361. *
  11362. * This routine process a event queue entry from the fast-path event queue.
  11363. * It will check the MajorCode and MinorCode to determine this is for a
  11364. * completion event on a completion queue, if not, an error shall be logged
  11365. * and just return. Otherwise, it will get to the corresponding completion
  11366. * queue and process all the entries on the completion queue, rearm the
  11367. * completion queue, and then return.
  11368. **/
  11369. static void
  11370. lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  11371. uint32_t qidx)
  11372. {
  11373. struct lpfc_queue *cq;
  11374. struct lpfc_cqe *cqe;
  11375. bool workposted = false;
  11376. uint16_t cqid;
  11377. int ecount = 0;
  11378. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  11379. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11380. "0366 Not a valid completion "
  11381. "event: majorcode=x%x, minorcode=x%x\n",
  11382. bf_get_le32(lpfc_eqe_major_code, eqe),
  11383. bf_get_le32(lpfc_eqe_minor_code, eqe));
  11384. return;
  11385. }
  11386. /* Get the reference to the corresponding CQ */
  11387. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11388. /* Check if this is a Slow path event */
  11389. if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
  11390. lpfc_sli4_sp_handle_eqe(phba, eqe,
  11391. phba->sli4_hba.hba_eq[qidx]);
  11392. return;
  11393. }
  11394. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  11395. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11396. "3146 Fast-path completion queues "
  11397. "does not exist\n");
  11398. return;
  11399. }
  11400. cq = phba->sli4_hba.fcp_cq[qidx];
  11401. if (unlikely(!cq)) {
  11402. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11403. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11404. "0367 Fast-path completion queue "
  11405. "(%d) does not exist\n", qidx);
  11406. return;
  11407. }
  11408. if (unlikely(cqid != cq->queue_id)) {
  11409. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11410. "0368 Miss-matched fast-path completion "
  11411. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  11412. cqid, cq->queue_id);
  11413. return;
  11414. }
  11415. /* Process all the entries to the CQ */
  11416. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11417. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  11418. if (!(++ecount % cq->entry_repost))
  11419. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11420. }
  11421. /* Track the max number of CQEs processed in 1 EQ */
  11422. if (ecount > cq->CQ_max_cqe)
  11423. cq->CQ_max_cqe = ecount;
  11424. /* Catch the no cq entry condition */
  11425. if (unlikely(ecount == 0))
  11426. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11427. "0369 No entry from fast-path completion "
  11428. "queue fcpcqid=%d\n", cq->queue_id);
  11429. /* In any case, flash and re-arm the CQ */
  11430. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11431. /* wake up worker thread if there are works to be done */
  11432. if (workposted)
  11433. lpfc_worker_wake_up(phba);
  11434. }
  11435. static void
  11436. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11437. {
  11438. struct lpfc_eqe *eqe;
  11439. /* walk all the EQ entries and drop on the floor */
  11440. while ((eqe = lpfc_sli4_eq_get(eq)))
  11441. ;
  11442. /* Clear and re-arm the EQ */
  11443. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  11444. }
  11445. /**
  11446. * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
  11447. * entry
  11448. * @phba: Pointer to HBA context object.
  11449. * @eqe: Pointer to fast-path event queue entry.
  11450. *
  11451. * This routine process a event queue entry from the Flash Optimized Fabric
  11452. * event queue. It will check the MajorCode and MinorCode to determine this
  11453. * is for a completion event on a completion queue, if not, an error shall be
  11454. * logged and just return. Otherwise, it will get to the corresponding
  11455. * completion queue and process all the entries on the completion queue, rearm
  11456. * the completion queue, and then return.
  11457. **/
  11458. static void
  11459. lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  11460. {
  11461. struct lpfc_queue *cq;
  11462. struct lpfc_cqe *cqe;
  11463. bool workposted = false;
  11464. uint16_t cqid;
  11465. int ecount = 0;
  11466. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  11467. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11468. "9147 Not a valid completion "
  11469. "event: majorcode=x%x, minorcode=x%x\n",
  11470. bf_get_le32(lpfc_eqe_major_code, eqe),
  11471. bf_get_le32(lpfc_eqe_minor_code, eqe));
  11472. return;
  11473. }
  11474. /* Get the reference to the corresponding CQ */
  11475. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11476. /* Next check for OAS */
  11477. cq = phba->sli4_hba.oas_cq;
  11478. if (unlikely(!cq)) {
  11479. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11480. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11481. "9148 OAS completion queue "
  11482. "does not exist\n");
  11483. return;
  11484. }
  11485. if (unlikely(cqid != cq->queue_id)) {
  11486. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11487. "9149 Miss-matched fast-path compl "
  11488. "queue id: eqcqid=%d, fcpcqid=%d\n",
  11489. cqid, cq->queue_id);
  11490. return;
  11491. }
  11492. /* Process all the entries to the OAS CQ */
  11493. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11494. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  11495. if (!(++ecount % cq->entry_repost))
  11496. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11497. }
  11498. /* Track the max number of CQEs processed in 1 EQ */
  11499. if (ecount > cq->CQ_max_cqe)
  11500. cq->CQ_max_cqe = ecount;
  11501. /* Catch the no cq entry condition */
  11502. if (unlikely(ecount == 0))
  11503. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11504. "9153 No entry from fast-path completion "
  11505. "queue fcpcqid=%d\n", cq->queue_id);
  11506. /* In any case, flash and re-arm the CQ */
  11507. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11508. /* wake up worker thread if there are works to be done */
  11509. if (workposted)
  11510. lpfc_worker_wake_up(phba);
  11511. }
  11512. /**
  11513. * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
  11514. * @irq: Interrupt number.
  11515. * @dev_id: The device context pointer.
  11516. *
  11517. * This function is directly called from the PCI layer as an interrupt
  11518. * service routine when device with SLI-4 interface spec is enabled with
  11519. * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
  11520. * IOCB ring event in the HBA. However, when the device is enabled with either
  11521. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  11522. * device-level interrupt handler. When the PCI slot is in error recovery
  11523. * or the HBA is undergoing initialization, the interrupt handler will not
  11524. * process the interrupt. The Flash Optimized Fabric ring event are handled in
  11525. * the intrrupt context. This function is called without any lock held.
  11526. * It gets the hbalock to access and update SLI data structures. Note that,
  11527. * the EQ to CQ are one-to-one map such that the EQ index is
  11528. * equal to that of CQ index.
  11529. *
  11530. * This function returns IRQ_HANDLED when interrupt is handled else it
  11531. * returns IRQ_NONE.
  11532. **/
  11533. irqreturn_t
  11534. lpfc_sli4_fof_intr_handler(int irq, void *dev_id)
  11535. {
  11536. struct lpfc_hba *phba;
  11537. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  11538. struct lpfc_queue *eq;
  11539. struct lpfc_eqe *eqe;
  11540. unsigned long iflag;
  11541. int ecount = 0;
  11542. /* Get the driver's phba structure from the dev_id */
  11543. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  11544. phba = fcp_eq_hdl->phba;
  11545. if (unlikely(!phba))
  11546. return IRQ_NONE;
  11547. /* Get to the EQ struct associated with this vector */
  11548. eq = phba->sli4_hba.fof_eq;
  11549. if (unlikely(!eq))
  11550. return IRQ_NONE;
  11551. /* Check device state for handling interrupt */
  11552. if (unlikely(lpfc_intr_state_check(phba))) {
  11553. eq->EQ_badstate++;
  11554. /* Check again for link_state with lock held */
  11555. spin_lock_irqsave(&phba->hbalock, iflag);
  11556. if (phba->link_state < LPFC_LINK_DOWN)
  11557. /* Flush, clear interrupt, and rearm the EQ */
  11558. lpfc_sli4_eq_flush(phba, eq);
  11559. spin_unlock_irqrestore(&phba->hbalock, iflag);
  11560. return IRQ_NONE;
  11561. }
  11562. /*
  11563. * Process all the event on FCP fast-path EQ
  11564. */
  11565. while ((eqe = lpfc_sli4_eq_get(eq))) {
  11566. lpfc_sli4_fof_handle_eqe(phba, eqe);
  11567. if (!(++ecount % eq->entry_repost))
  11568. lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM);
  11569. eq->EQ_processed++;
  11570. }
  11571. /* Track the max number of EQEs processed in 1 intr */
  11572. if (ecount > eq->EQ_max_eqe)
  11573. eq->EQ_max_eqe = ecount;
  11574. if (unlikely(ecount == 0)) {
  11575. eq->EQ_no_entry++;
  11576. if (phba->intr_type == MSIX)
  11577. /* MSI-X treated interrupt served as no EQ share INT */
  11578. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11579. "9145 MSI-X interrupt with no EQE\n");
  11580. else {
  11581. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11582. "9146 ISR interrupt with no EQE\n");
  11583. /* Non MSI-X treated on interrupt as EQ share INT */
  11584. return IRQ_NONE;
  11585. }
  11586. }
  11587. /* Always clear and re-arm the fast-path EQ */
  11588. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  11589. return IRQ_HANDLED;
  11590. }
  11591. /**
  11592. * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
  11593. * @irq: Interrupt number.
  11594. * @dev_id: The device context pointer.
  11595. *
  11596. * This function is directly called from the PCI layer as an interrupt
  11597. * service routine when device with SLI-4 interface spec is enabled with
  11598. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  11599. * ring event in the HBA. However, when the device is enabled with either
  11600. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  11601. * device-level interrupt handler. When the PCI slot is in error recovery
  11602. * or the HBA is undergoing initialization, the interrupt handler will not
  11603. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  11604. * the intrrupt context. This function is called without any lock held.
  11605. * It gets the hbalock to access and update SLI data structures. Note that,
  11606. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  11607. * equal to that of FCP CQ index.
  11608. *
  11609. * The link attention and ELS ring attention events are handled
  11610. * by the worker thread. The interrupt handler signals the worker thread
  11611. * and returns for these events. This function is called without any lock
  11612. * held. It gets the hbalock to access and update SLI data structures.
  11613. *
  11614. * This function returns IRQ_HANDLED when interrupt is handled else it
  11615. * returns IRQ_NONE.
  11616. **/
  11617. irqreturn_t
  11618. lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
  11619. {
  11620. struct lpfc_hba *phba;
  11621. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  11622. struct lpfc_queue *fpeq;
  11623. struct lpfc_eqe *eqe;
  11624. unsigned long iflag;
  11625. int ecount = 0;
  11626. int fcp_eqidx;
  11627. /* Get the driver's phba structure from the dev_id */
  11628. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  11629. phba = fcp_eq_hdl->phba;
  11630. fcp_eqidx = fcp_eq_hdl->idx;
  11631. if (unlikely(!phba))
  11632. return IRQ_NONE;
  11633. if (unlikely(!phba->sli4_hba.hba_eq))
  11634. return IRQ_NONE;
  11635. /* Get to the EQ struct associated with this vector */
  11636. fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11637. if (unlikely(!fpeq))
  11638. return IRQ_NONE;
  11639. if (lpfc_fcp_look_ahead) {
  11640. if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
  11641. lpfc_sli4_eq_clr_intr(fpeq);
  11642. else {
  11643. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11644. return IRQ_NONE;
  11645. }
  11646. }
  11647. /* Check device state for handling interrupt */
  11648. if (unlikely(lpfc_intr_state_check(phba))) {
  11649. fpeq->EQ_badstate++;
  11650. /* Check again for link_state with lock held */
  11651. spin_lock_irqsave(&phba->hbalock, iflag);
  11652. if (phba->link_state < LPFC_LINK_DOWN)
  11653. /* Flush, clear interrupt, and rearm the EQ */
  11654. lpfc_sli4_eq_flush(phba, fpeq);
  11655. spin_unlock_irqrestore(&phba->hbalock, iflag);
  11656. if (lpfc_fcp_look_ahead)
  11657. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11658. return IRQ_NONE;
  11659. }
  11660. /*
  11661. * Process all the event on FCP fast-path EQ
  11662. */
  11663. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  11664. if (eqe == NULL)
  11665. break;
  11666. lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
  11667. if (!(++ecount % fpeq->entry_repost))
  11668. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  11669. fpeq->EQ_processed++;
  11670. }
  11671. /* Track the max number of EQEs processed in 1 intr */
  11672. if (ecount > fpeq->EQ_max_eqe)
  11673. fpeq->EQ_max_eqe = ecount;
  11674. /* Always clear and re-arm the fast-path EQ */
  11675. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  11676. if (unlikely(ecount == 0)) {
  11677. fpeq->EQ_no_entry++;
  11678. if (lpfc_fcp_look_ahead) {
  11679. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11680. return IRQ_NONE;
  11681. }
  11682. if (phba->intr_type == MSIX)
  11683. /* MSI-X treated interrupt served as no EQ share INT */
  11684. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11685. "0358 MSI-X interrupt with no EQE\n");
  11686. else
  11687. /* Non MSI-X treated on interrupt as EQ share INT */
  11688. return IRQ_NONE;
  11689. }
  11690. if (lpfc_fcp_look_ahead)
  11691. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11692. return IRQ_HANDLED;
  11693. } /* lpfc_sli4_fp_intr_handler */
  11694. /**
  11695. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  11696. * @irq: Interrupt number.
  11697. * @dev_id: The device context pointer.
  11698. *
  11699. * This function is the device-level interrupt handler to device with SLI-4
  11700. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  11701. * interrupt mode is enabled and there is an event in the HBA which requires
  11702. * driver attention. This function invokes the slow-path interrupt attention
  11703. * handling function and fast-path interrupt attention handling function in
  11704. * turn to process the relevant HBA attention events. This function is called
  11705. * without any lock held. It gets the hbalock to access and update SLI data
  11706. * structures.
  11707. *
  11708. * This function returns IRQ_HANDLED when interrupt is handled, else it
  11709. * returns IRQ_NONE.
  11710. **/
  11711. irqreturn_t
  11712. lpfc_sli4_intr_handler(int irq, void *dev_id)
  11713. {
  11714. struct lpfc_hba *phba;
  11715. irqreturn_t hba_irq_rc;
  11716. bool hba_handled = false;
  11717. int fcp_eqidx;
  11718. /* Get the driver's phba structure from the dev_id */
  11719. phba = (struct lpfc_hba *)dev_id;
  11720. if (unlikely(!phba))
  11721. return IRQ_NONE;
  11722. /*
  11723. * Invoke fast-path host attention interrupt handling as appropriate.
  11724. */
  11725. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  11726. hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
  11727. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  11728. if (hba_irq_rc == IRQ_HANDLED)
  11729. hba_handled |= true;
  11730. }
  11731. if (phba->cfg_fof) {
  11732. hba_irq_rc = lpfc_sli4_fof_intr_handler(irq,
  11733. &phba->sli4_hba.fcp_eq_hdl[0]);
  11734. if (hba_irq_rc == IRQ_HANDLED)
  11735. hba_handled |= true;
  11736. }
  11737. return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
  11738. } /* lpfc_sli4_intr_handler */
  11739. /**
  11740. * lpfc_sli4_queue_free - free a queue structure and associated memory
  11741. * @queue: The queue structure to free.
  11742. *
  11743. * This function frees a queue structure and the DMAable memory used for
  11744. * the host resident queue. This function must be called after destroying the
  11745. * queue on the HBA.
  11746. **/
  11747. void
  11748. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  11749. {
  11750. struct lpfc_dmabuf *dmabuf;
  11751. if (!queue)
  11752. return;
  11753. while (!list_empty(&queue->page_list)) {
  11754. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  11755. list);
  11756. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  11757. dmabuf->virt, dmabuf->phys);
  11758. kfree(dmabuf);
  11759. }
  11760. kfree(queue);
  11761. return;
  11762. }
  11763. /**
  11764. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  11765. * @phba: The HBA that this queue is being created on.
  11766. * @entry_size: The size of each queue entry for this queue.
  11767. * @entry count: The number of entries that this queue will handle.
  11768. *
  11769. * This function allocates a queue structure and the DMAable memory used for
  11770. * the host resident queue. This function must be called before creating the
  11771. * queue on the HBA.
  11772. **/
  11773. struct lpfc_queue *
  11774. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  11775. uint32_t entry_count)
  11776. {
  11777. struct lpfc_queue *queue;
  11778. struct lpfc_dmabuf *dmabuf;
  11779. int x, total_qe_count;
  11780. void *dma_pointer;
  11781. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11782. if (!phba->sli4_hba.pc_sli4_params.supported)
  11783. hw_page_size = SLI4_PAGE_SIZE;
  11784. queue = kzalloc(sizeof(struct lpfc_queue) +
  11785. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  11786. if (!queue)
  11787. return NULL;
  11788. queue->page_count = (ALIGN(entry_size * entry_count,
  11789. hw_page_size))/hw_page_size;
  11790. INIT_LIST_HEAD(&queue->list);
  11791. INIT_LIST_HEAD(&queue->page_list);
  11792. INIT_LIST_HEAD(&queue->child_list);
  11793. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  11794. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  11795. if (!dmabuf)
  11796. goto out_fail;
  11797. dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
  11798. hw_page_size, &dmabuf->phys,
  11799. GFP_KERNEL);
  11800. if (!dmabuf->virt) {
  11801. kfree(dmabuf);
  11802. goto out_fail;
  11803. }
  11804. dmabuf->buffer_tag = x;
  11805. list_add_tail(&dmabuf->list, &queue->page_list);
  11806. /* initialize queue's entry array */
  11807. dma_pointer = dmabuf->virt;
  11808. for (; total_qe_count < entry_count &&
  11809. dma_pointer < (hw_page_size + dmabuf->virt);
  11810. total_qe_count++, dma_pointer += entry_size) {
  11811. queue->qe[total_qe_count].address = dma_pointer;
  11812. }
  11813. }
  11814. queue->entry_size = entry_size;
  11815. queue->entry_count = entry_count;
  11816. /*
  11817. * entry_repost is calculated based on the number of entries in the
  11818. * queue. This works out except for RQs. If buffers are NOT initially
  11819. * posted for every RQE, entry_repost should be adjusted accordingly.
  11820. */
  11821. queue->entry_repost = (entry_count >> 3);
  11822. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  11823. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  11824. queue->phba = phba;
  11825. return queue;
  11826. out_fail:
  11827. lpfc_sli4_queue_free(queue);
  11828. return NULL;
  11829. }
  11830. /**
  11831. * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
  11832. * @phba: HBA structure that indicates port to create a queue on.
  11833. * @pci_barset: PCI BAR set flag.
  11834. *
  11835. * This function shall perform iomap of the specified PCI BAR address to host
  11836. * memory address if not already done so and return it. The returned host
  11837. * memory address can be NULL.
  11838. */
  11839. static void __iomem *
  11840. lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
  11841. {
  11842. if (!phba->pcidev)
  11843. return NULL;
  11844. switch (pci_barset) {
  11845. case WQ_PCI_BAR_0_AND_1:
  11846. return phba->pci_bar0_memmap_p;
  11847. case WQ_PCI_BAR_2_AND_3:
  11848. return phba->pci_bar2_memmap_p;
  11849. case WQ_PCI_BAR_4_AND_5:
  11850. return phba->pci_bar4_memmap_p;
  11851. default:
  11852. break;
  11853. }
  11854. return NULL;
  11855. }
  11856. /**
  11857. * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
  11858. * @phba: HBA structure that indicates port to create a queue on.
  11859. * @startq: The starting FCP EQ to modify
  11860. *
  11861. * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
  11862. *
  11863. * The @phba struct is used to send mailbox command to HBA. The @startq
  11864. * is used to get the starting FCP EQ to change.
  11865. * This function is asynchronous and will wait for the mailbox
  11866. * command to finish before continuing.
  11867. *
  11868. * On success this function will return a zero. If unable to allocate enough
  11869. * memory this function will return -ENOMEM. If the queue create mailbox command
  11870. * fails this function will return -ENXIO.
  11871. **/
  11872. int
  11873. lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint32_t startq)
  11874. {
  11875. struct lpfc_mbx_modify_eq_delay *eq_delay;
  11876. LPFC_MBOXQ_t *mbox;
  11877. struct lpfc_queue *eq;
  11878. int cnt, rc, length, status = 0;
  11879. uint32_t shdr_status, shdr_add_status;
  11880. uint32_t result;
  11881. int fcp_eqidx;
  11882. union lpfc_sli4_cfg_shdr *shdr;
  11883. uint16_t dmult;
  11884. if (startq >= phba->cfg_fcp_io_channel)
  11885. return 0;
  11886. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11887. if (!mbox)
  11888. return -ENOMEM;
  11889. length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
  11890. sizeof(struct lpfc_sli4_cfg_mhdr));
  11891. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11892. LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
  11893. length, LPFC_SLI4_MBX_EMBED);
  11894. eq_delay = &mbox->u.mqe.un.eq_delay;
  11895. /* Calculate delay multiper from maximum interrupt per second */
  11896. result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
  11897. if (result > LPFC_DMULT_CONST)
  11898. dmult = 0;
  11899. else
  11900. dmult = LPFC_DMULT_CONST/result - 1;
  11901. cnt = 0;
  11902. for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
  11903. fcp_eqidx++) {
  11904. eq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11905. if (!eq)
  11906. continue;
  11907. eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
  11908. eq_delay->u.request.eq[cnt].phase = 0;
  11909. eq_delay->u.request.eq[cnt].delay_multi = dmult;
  11910. cnt++;
  11911. if (cnt >= LPFC_MAX_EQ_DELAY)
  11912. break;
  11913. }
  11914. eq_delay->u.request.num_eq = cnt;
  11915. mbox->vport = phba->pport;
  11916. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11917. mbox->context1 = NULL;
  11918. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11919. shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
  11920. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11921. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11922. if (shdr_status || shdr_add_status || rc) {
  11923. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11924. "2512 MODIFY_EQ_DELAY mailbox failed with "
  11925. "status x%x add_status x%x, mbx status x%x\n",
  11926. shdr_status, shdr_add_status, rc);
  11927. status = -ENXIO;
  11928. }
  11929. mempool_free(mbox, phba->mbox_mem_pool);
  11930. return status;
  11931. }
  11932. /**
  11933. * lpfc_eq_create - Create an Event Queue on the HBA
  11934. * @phba: HBA structure that indicates port to create a queue on.
  11935. * @eq: The queue structure to use to create the event queue.
  11936. * @imax: The maximum interrupt per second limit.
  11937. *
  11938. * This function creates an event queue, as detailed in @eq, on a port,
  11939. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  11940. *
  11941. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  11942. * is used to get the entry count and entry size that are necessary to
  11943. * determine the number of pages to allocate and use for this queue. This
  11944. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  11945. * event queue. This function is asynchronous and will wait for the mailbox
  11946. * command to finish before continuing.
  11947. *
  11948. * On success this function will return a zero. If unable to allocate enough
  11949. * memory this function will return -ENOMEM. If the queue create mailbox command
  11950. * fails this function will return -ENXIO.
  11951. **/
  11952. int
  11953. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
  11954. {
  11955. struct lpfc_mbx_eq_create *eq_create;
  11956. LPFC_MBOXQ_t *mbox;
  11957. int rc, length, status = 0;
  11958. struct lpfc_dmabuf *dmabuf;
  11959. uint32_t shdr_status, shdr_add_status;
  11960. union lpfc_sli4_cfg_shdr *shdr;
  11961. uint16_t dmult;
  11962. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11963. /* sanity check on queue memory */
  11964. if (!eq)
  11965. return -ENODEV;
  11966. if (!phba->sli4_hba.pc_sli4_params.supported)
  11967. hw_page_size = SLI4_PAGE_SIZE;
  11968. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11969. if (!mbox)
  11970. return -ENOMEM;
  11971. length = (sizeof(struct lpfc_mbx_eq_create) -
  11972. sizeof(struct lpfc_sli4_cfg_mhdr));
  11973. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11974. LPFC_MBOX_OPCODE_EQ_CREATE,
  11975. length, LPFC_SLI4_MBX_EMBED);
  11976. eq_create = &mbox->u.mqe.un.eq_create;
  11977. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11978. eq->page_count);
  11979. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11980. LPFC_EQE_SIZE);
  11981. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11982. /* don't setup delay multiplier using EQ_CREATE */
  11983. dmult = 0;
  11984. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11985. dmult);
  11986. switch (eq->entry_count) {
  11987. default:
  11988. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11989. "0360 Unsupported EQ count. (%d)\n",
  11990. eq->entry_count);
  11991. if (eq->entry_count < 256)
  11992. return -EINVAL;
  11993. /* otherwise default to smallest count (drop through) */
  11994. case 256:
  11995. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11996. LPFC_EQ_CNT_256);
  11997. break;
  11998. case 512:
  11999. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12000. LPFC_EQ_CNT_512);
  12001. break;
  12002. case 1024:
  12003. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12004. LPFC_EQ_CNT_1024);
  12005. break;
  12006. case 2048:
  12007. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12008. LPFC_EQ_CNT_2048);
  12009. break;
  12010. case 4096:
  12011. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12012. LPFC_EQ_CNT_4096);
  12013. break;
  12014. }
  12015. list_for_each_entry(dmabuf, &eq->page_list, list) {
  12016. memset(dmabuf->virt, 0, hw_page_size);
  12017. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12018. putPaddrLow(dmabuf->phys);
  12019. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12020. putPaddrHigh(dmabuf->phys);
  12021. }
  12022. mbox->vport = phba->pport;
  12023. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12024. mbox->context1 = NULL;
  12025. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12026. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  12027. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12028. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12029. if (shdr_status || shdr_add_status || rc) {
  12030. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12031. "2500 EQ_CREATE mailbox failed with "
  12032. "status x%x add_status x%x, mbx status x%x\n",
  12033. shdr_status, shdr_add_status, rc);
  12034. status = -ENXIO;
  12035. }
  12036. eq->type = LPFC_EQ;
  12037. eq->subtype = LPFC_NONE;
  12038. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  12039. if (eq->queue_id == 0xFFFF)
  12040. status = -ENXIO;
  12041. eq->host_index = 0;
  12042. eq->hba_index = 0;
  12043. mempool_free(mbox, phba->mbox_mem_pool);
  12044. return status;
  12045. }
  12046. /**
  12047. * lpfc_cq_create - Create a Completion Queue on the HBA
  12048. * @phba: HBA structure that indicates port to create a queue on.
  12049. * @cq: The queue structure to use to create the completion queue.
  12050. * @eq: The event queue to bind this completion queue to.
  12051. *
  12052. * This function creates a completion queue, as detailed in @wq, on a port,
  12053. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  12054. *
  12055. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  12056. * is used to get the entry count and entry size that are necessary to
  12057. * determine the number of pages to allocate and use for this queue. The @eq
  12058. * is used to indicate which event queue to bind this completion queue to. This
  12059. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  12060. * completion queue. This function is asynchronous and will wait for the mailbox
  12061. * command to finish before continuing.
  12062. *
  12063. * On success this function will return a zero. If unable to allocate enough
  12064. * memory this function will return -ENOMEM. If the queue create mailbox command
  12065. * fails this function will return -ENXIO.
  12066. **/
  12067. int
  12068. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  12069. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  12070. {
  12071. struct lpfc_mbx_cq_create *cq_create;
  12072. struct lpfc_dmabuf *dmabuf;
  12073. LPFC_MBOXQ_t *mbox;
  12074. int rc, length, status = 0;
  12075. uint32_t shdr_status, shdr_add_status;
  12076. union lpfc_sli4_cfg_shdr *shdr;
  12077. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12078. /* sanity check on queue memory */
  12079. if (!cq || !eq)
  12080. return -ENODEV;
  12081. if (!phba->sli4_hba.pc_sli4_params.supported)
  12082. hw_page_size = SLI4_PAGE_SIZE;
  12083. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12084. if (!mbox)
  12085. return -ENOMEM;
  12086. length = (sizeof(struct lpfc_mbx_cq_create) -
  12087. sizeof(struct lpfc_sli4_cfg_mhdr));
  12088. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12089. LPFC_MBOX_OPCODE_CQ_CREATE,
  12090. length, LPFC_SLI4_MBX_EMBED);
  12091. cq_create = &mbox->u.mqe.un.cq_create;
  12092. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  12093. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  12094. cq->page_count);
  12095. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  12096. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  12097. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12098. phba->sli4_hba.pc_sli4_params.cqv);
  12099. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  12100. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  12101. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  12102. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  12103. eq->queue_id);
  12104. } else {
  12105. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  12106. eq->queue_id);
  12107. }
  12108. switch (cq->entry_count) {
  12109. default:
  12110. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12111. "0361 Unsupported CQ count. (%d)\n",
  12112. cq->entry_count);
  12113. if (cq->entry_count < 256) {
  12114. status = -EINVAL;
  12115. goto out;
  12116. }
  12117. /* otherwise default to smallest count (drop through) */
  12118. case 256:
  12119. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  12120. LPFC_CQ_CNT_256);
  12121. break;
  12122. case 512:
  12123. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  12124. LPFC_CQ_CNT_512);
  12125. break;
  12126. case 1024:
  12127. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  12128. LPFC_CQ_CNT_1024);
  12129. break;
  12130. }
  12131. list_for_each_entry(dmabuf, &cq->page_list, list) {
  12132. memset(dmabuf->virt, 0, hw_page_size);
  12133. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12134. putPaddrLow(dmabuf->phys);
  12135. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12136. putPaddrHigh(dmabuf->phys);
  12137. }
  12138. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12139. /* The IOCTL status is embedded in the mailbox subheader. */
  12140. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12141. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12142. if (shdr_status || shdr_add_status || rc) {
  12143. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12144. "2501 CQ_CREATE mailbox failed with "
  12145. "status x%x add_status x%x, mbx status x%x\n",
  12146. shdr_status, shdr_add_status, rc);
  12147. status = -ENXIO;
  12148. goto out;
  12149. }
  12150. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  12151. if (cq->queue_id == 0xFFFF) {
  12152. status = -ENXIO;
  12153. goto out;
  12154. }
  12155. /* link the cq onto the parent eq child list */
  12156. list_add_tail(&cq->list, &eq->child_list);
  12157. /* Set up completion queue's type and subtype */
  12158. cq->type = type;
  12159. cq->subtype = subtype;
  12160. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  12161. cq->assoc_qid = eq->queue_id;
  12162. cq->host_index = 0;
  12163. cq->hba_index = 0;
  12164. out:
  12165. mempool_free(mbox, phba->mbox_mem_pool);
  12166. return status;
  12167. }
  12168. /**
  12169. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  12170. * @phba: HBA structure that indicates port to create a queue on.
  12171. * @mq: The queue structure to use to create the mailbox queue.
  12172. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  12173. * @cq: The completion queue to associate with this cq.
  12174. *
  12175. * This function provides failback (fb) functionality when the
  12176. * mq_create_ext fails on older FW generations. It's purpose is identical
  12177. * to mq_create_ext otherwise.
  12178. *
  12179. * This routine cannot fail as all attributes were previously accessed and
  12180. * initialized in mq_create_ext.
  12181. **/
  12182. static void
  12183. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  12184. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  12185. {
  12186. struct lpfc_mbx_mq_create *mq_create;
  12187. struct lpfc_dmabuf *dmabuf;
  12188. int length;
  12189. length = (sizeof(struct lpfc_mbx_mq_create) -
  12190. sizeof(struct lpfc_sli4_cfg_mhdr));
  12191. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12192. LPFC_MBOX_OPCODE_MQ_CREATE,
  12193. length, LPFC_SLI4_MBX_EMBED);
  12194. mq_create = &mbox->u.mqe.un.mq_create;
  12195. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  12196. mq->page_count);
  12197. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  12198. cq->queue_id);
  12199. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  12200. switch (mq->entry_count) {
  12201. case 16:
  12202. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12203. LPFC_MQ_RING_SIZE_16);
  12204. break;
  12205. case 32:
  12206. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12207. LPFC_MQ_RING_SIZE_32);
  12208. break;
  12209. case 64:
  12210. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12211. LPFC_MQ_RING_SIZE_64);
  12212. break;
  12213. case 128:
  12214. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12215. LPFC_MQ_RING_SIZE_128);
  12216. break;
  12217. }
  12218. list_for_each_entry(dmabuf, &mq->page_list, list) {
  12219. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12220. putPaddrLow(dmabuf->phys);
  12221. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12222. putPaddrHigh(dmabuf->phys);
  12223. }
  12224. }
  12225. /**
  12226. * lpfc_mq_create - Create a mailbox Queue on the HBA
  12227. * @phba: HBA structure that indicates port to create a queue on.
  12228. * @mq: The queue structure to use to create the mailbox queue.
  12229. * @cq: The completion queue to associate with this cq.
  12230. * @subtype: The queue's subtype.
  12231. *
  12232. * This function creates a mailbox queue, as detailed in @mq, on a port,
  12233. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  12234. *
  12235. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  12236. * is used to get the entry count and entry size that are necessary to
  12237. * determine the number of pages to allocate and use for this queue. This
  12238. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  12239. * mailbox queue. This function is asynchronous and will wait for the mailbox
  12240. * command to finish before continuing.
  12241. *
  12242. * On success this function will return a zero. If unable to allocate enough
  12243. * memory this function will return -ENOMEM. If the queue create mailbox command
  12244. * fails this function will return -ENXIO.
  12245. **/
  12246. int32_t
  12247. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  12248. struct lpfc_queue *cq, uint32_t subtype)
  12249. {
  12250. struct lpfc_mbx_mq_create *mq_create;
  12251. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  12252. struct lpfc_dmabuf *dmabuf;
  12253. LPFC_MBOXQ_t *mbox;
  12254. int rc, length, status = 0;
  12255. uint32_t shdr_status, shdr_add_status;
  12256. union lpfc_sli4_cfg_shdr *shdr;
  12257. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12258. /* sanity check on queue memory */
  12259. if (!mq || !cq)
  12260. return -ENODEV;
  12261. if (!phba->sli4_hba.pc_sli4_params.supported)
  12262. hw_page_size = SLI4_PAGE_SIZE;
  12263. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12264. if (!mbox)
  12265. return -ENOMEM;
  12266. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  12267. sizeof(struct lpfc_sli4_cfg_mhdr));
  12268. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12269. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  12270. length, LPFC_SLI4_MBX_EMBED);
  12271. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  12272. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  12273. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  12274. &mq_create_ext->u.request, mq->page_count);
  12275. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  12276. &mq_create_ext->u.request, 1);
  12277. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  12278. &mq_create_ext->u.request, 1);
  12279. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  12280. &mq_create_ext->u.request, 1);
  12281. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  12282. &mq_create_ext->u.request, 1);
  12283. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  12284. &mq_create_ext->u.request, 1);
  12285. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  12286. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12287. phba->sli4_hba.pc_sli4_params.mqv);
  12288. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  12289. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  12290. cq->queue_id);
  12291. else
  12292. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  12293. cq->queue_id);
  12294. switch (mq->entry_count) {
  12295. default:
  12296. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12297. "0362 Unsupported MQ count. (%d)\n",
  12298. mq->entry_count);
  12299. if (mq->entry_count < 16) {
  12300. status = -EINVAL;
  12301. goto out;
  12302. }
  12303. /* otherwise default to smallest count (drop through) */
  12304. case 16:
  12305. bf_set(lpfc_mq_context_ring_size,
  12306. &mq_create_ext->u.request.context,
  12307. LPFC_MQ_RING_SIZE_16);
  12308. break;
  12309. case 32:
  12310. bf_set(lpfc_mq_context_ring_size,
  12311. &mq_create_ext->u.request.context,
  12312. LPFC_MQ_RING_SIZE_32);
  12313. break;
  12314. case 64:
  12315. bf_set(lpfc_mq_context_ring_size,
  12316. &mq_create_ext->u.request.context,
  12317. LPFC_MQ_RING_SIZE_64);
  12318. break;
  12319. case 128:
  12320. bf_set(lpfc_mq_context_ring_size,
  12321. &mq_create_ext->u.request.context,
  12322. LPFC_MQ_RING_SIZE_128);
  12323. break;
  12324. }
  12325. list_for_each_entry(dmabuf, &mq->page_list, list) {
  12326. memset(dmabuf->virt, 0, hw_page_size);
  12327. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  12328. putPaddrLow(dmabuf->phys);
  12329. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  12330. putPaddrHigh(dmabuf->phys);
  12331. }
  12332. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12333. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  12334. &mq_create_ext->u.response);
  12335. if (rc != MBX_SUCCESS) {
  12336. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12337. "2795 MQ_CREATE_EXT failed with "
  12338. "status x%x. Failback to MQ_CREATE.\n",
  12339. rc);
  12340. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  12341. mq_create = &mbox->u.mqe.un.mq_create;
  12342. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12343. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  12344. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  12345. &mq_create->u.response);
  12346. }
  12347. /* The IOCTL status is embedded in the mailbox subheader. */
  12348. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12349. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12350. if (shdr_status || shdr_add_status || rc) {
  12351. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12352. "2502 MQ_CREATE mailbox failed with "
  12353. "status x%x add_status x%x, mbx status x%x\n",
  12354. shdr_status, shdr_add_status, rc);
  12355. status = -ENXIO;
  12356. goto out;
  12357. }
  12358. if (mq->queue_id == 0xFFFF) {
  12359. status = -ENXIO;
  12360. goto out;
  12361. }
  12362. mq->type = LPFC_MQ;
  12363. mq->assoc_qid = cq->queue_id;
  12364. mq->subtype = subtype;
  12365. mq->host_index = 0;
  12366. mq->hba_index = 0;
  12367. /* link the mq onto the parent cq child list */
  12368. list_add_tail(&mq->list, &cq->child_list);
  12369. out:
  12370. mempool_free(mbox, phba->mbox_mem_pool);
  12371. return status;
  12372. }
  12373. /**
  12374. * lpfc_wq_create - Create a Work Queue on the HBA
  12375. * @phba: HBA structure that indicates port to create a queue on.
  12376. * @wq: The queue structure to use to create the work queue.
  12377. * @cq: The completion queue to bind this work queue to.
  12378. * @subtype: The subtype of the work queue indicating its functionality.
  12379. *
  12380. * This function creates a work queue, as detailed in @wq, on a port, described
  12381. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  12382. *
  12383. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  12384. * is used to get the entry count and entry size that are necessary to
  12385. * determine the number of pages to allocate and use for this queue. The @cq
  12386. * is used to indicate which completion queue to bind this work queue to. This
  12387. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  12388. * work queue. This function is asynchronous and will wait for the mailbox
  12389. * command to finish before continuing.
  12390. *
  12391. * On success this function will return a zero. If unable to allocate enough
  12392. * memory this function will return -ENOMEM. If the queue create mailbox command
  12393. * fails this function will return -ENXIO.
  12394. **/
  12395. int
  12396. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  12397. struct lpfc_queue *cq, uint32_t subtype)
  12398. {
  12399. struct lpfc_mbx_wq_create *wq_create;
  12400. struct lpfc_dmabuf *dmabuf;
  12401. LPFC_MBOXQ_t *mbox;
  12402. int rc, length, status = 0;
  12403. uint32_t shdr_status, shdr_add_status;
  12404. union lpfc_sli4_cfg_shdr *shdr;
  12405. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12406. struct dma_address *page;
  12407. void __iomem *bar_memmap_p;
  12408. uint32_t db_offset;
  12409. uint16_t pci_barset;
  12410. /* sanity check on queue memory */
  12411. if (!wq || !cq)
  12412. return -ENODEV;
  12413. if (!phba->sli4_hba.pc_sli4_params.supported)
  12414. hw_page_size = SLI4_PAGE_SIZE;
  12415. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12416. if (!mbox)
  12417. return -ENOMEM;
  12418. length = (sizeof(struct lpfc_mbx_wq_create) -
  12419. sizeof(struct lpfc_sli4_cfg_mhdr));
  12420. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12421. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  12422. length, LPFC_SLI4_MBX_EMBED);
  12423. wq_create = &mbox->u.mqe.un.wq_create;
  12424. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  12425. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  12426. wq->page_count);
  12427. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  12428. cq->queue_id);
  12429. /* wqv is the earliest version supported, NOT the latest */
  12430. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12431. phba->sli4_hba.pc_sli4_params.wqv);
  12432. switch (phba->sli4_hba.pc_sli4_params.wqv) {
  12433. case LPFC_Q_CREATE_VERSION_0:
  12434. switch (wq->entry_size) {
  12435. default:
  12436. case 64:
  12437. /* Nothing to do, version 0 ONLY supports 64 byte */
  12438. page = wq_create->u.request.page;
  12439. break;
  12440. case 128:
  12441. if (!(phba->sli4_hba.pc_sli4_params.wqsize &
  12442. LPFC_WQ_SZ128_SUPPORT)) {
  12443. status = -ERANGE;
  12444. goto out;
  12445. }
  12446. /* If we get here the HBA MUST also support V1 and
  12447. * we MUST use it
  12448. */
  12449. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12450. LPFC_Q_CREATE_VERSION_1);
  12451. bf_set(lpfc_mbx_wq_create_wqe_count,
  12452. &wq_create->u.request_1, wq->entry_count);
  12453. bf_set(lpfc_mbx_wq_create_wqe_size,
  12454. &wq_create->u.request_1,
  12455. LPFC_WQ_WQE_SIZE_128);
  12456. bf_set(lpfc_mbx_wq_create_page_size,
  12457. &wq_create->u.request_1,
  12458. LPFC_WQ_PAGE_SIZE_4096);
  12459. page = wq_create->u.request_1.page;
  12460. break;
  12461. }
  12462. break;
  12463. case LPFC_Q_CREATE_VERSION_1:
  12464. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  12465. wq->entry_count);
  12466. switch (wq->entry_size) {
  12467. default:
  12468. case 64:
  12469. bf_set(lpfc_mbx_wq_create_wqe_size,
  12470. &wq_create->u.request_1,
  12471. LPFC_WQ_WQE_SIZE_64);
  12472. break;
  12473. case 128:
  12474. if (!(phba->sli4_hba.pc_sli4_params.wqsize &
  12475. LPFC_WQ_SZ128_SUPPORT)) {
  12476. status = -ERANGE;
  12477. goto out;
  12478. }
  12479. bf_set(lpfc_mbx_wq_create_wqe_size,
  12480. &wq_create->u.request_1,
  12481. LPFC_WQ_WQE_SIZE_128);
  12482. break;
  12483. }
  12484. bf_set(lpfc_mbx_wq_create_page_size,
  12485. &wq_create->u.request_1,
  12486. LPFC_WQ_PAGE_SIZE_4096);
  12487. page = wq_create->u.request_1.page;
  12488. break;
  12489. default:
  12490. status = -ERANGE;
  12491. goto out;
  12492. }
  12493. list_for_each_entry(dmabuf, &wq->page_list, list) {
  12494. memset(dmabuf->virt, 0, hw_page_size);
  12495. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  12496. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  12497. }
  12498. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12499. bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
  12500. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12501. /* The IOCTL status is embedded in the mailbox subheader. */
  12502. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12503. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12504. if (shdr_status || shdr_add_status || rc) {
  12505. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12506. "2503 WQ_CREATE mailbox failed with "
  12507. "status x%x add_status x%x, mbx status x%x\n",
  12508. shdr_status, shdr_add_status, rc);
  12509. status = -ENXIO;
  12510. goto out;
  12511. }
  12512. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  12513. if (wq->queue_id == 0xFFFF) {
  12514. status = -ENXIO;
  12515. goto out;
  12516. }
  12517. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  12518. wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
  12519. &wq_create->u.response);
  12520. if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
  12521. (wq->db_format != LPFC_DB_RING_FORMAT)) {
  12522. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12523. "3265 WQ[%d] doorbell format not "
  12524. "supported: x%x\n", wq->queue_id,
  12525. wq->db_format);
  12526. status = -EINVAL;
  12527. goto out;
  12528. }
  12529. pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
  12530. &wq_create->u.response);
  12531. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  12532. if (!bar_memmap_p) {
  12533. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12534. "3263 WQ[%d] failed to memmap pci "
  12535. "barset:x%x\n", wq->queue_id,
  12536. pci_barset);
  12537. status = -ENOMEM;
  12538. goto out;
  12539. }
  12540. db_offset = wq_create->u.response.doorbell_offset;
  12541. if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
  12542. (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
  12543. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12544. "3252 WQ[%d] doorbell offset not "
  12545. "supported: x%x\n", wq->queue_id,
  12546. db_offset);
  12547. status = -EINVAL;
  12548. goto out;
  12549. }
  12550. wq->db_regaddr = bar_memmap_p + db_offset;
  12551. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12552. "3264 WQ[%d]: barset:x%x, offset:x%x, "
  12553. "format:x%x\n", wq->queue_id, pci_barset,
  12554. db_offset, wq->db_format);
  12555. } else {
  12556. wq->db_format = LPFC_DB_LIST_FORMAT;
  12557. wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
  12558. }
  12559. wq->type = LPFC_WQ;
  12560. wq->assoc_qid = cq->queue_id;
  12561. wq->subtype = subtype;
  12562. wq->host_index = 0;
  12563. wq->hba_index = 0;
  12564. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  12565. /* link the wq onto the parent cq child list */
  12566. list_add_tail(&wq->list, &cq->child_list);
  12567. out:
  12568. mempool_free(mbox, phba->mbox_mem_pool);
  12569. return status;
  12570. }
  12571. /**
  12572. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  12573. * @phba: HBA structure that indicates port to create a queue on.
  12574. * @rq: The queue structure to use for the receive queue.
  12575. * @qno: The associated HBQ number
  12576. *
  12577. *
  12578. * For SLI4 we need to adjust the RQ repost value based on
  12579. * the number of buffers that are initially posted to the RQ.
  12580. */
  12581. void
  12582. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  12583. {
  12584. uint32_t cnt;
  12585. /* sanity check on queue memory */
  12586. if (!rq)
  12587. return;
  12588. cnt = lpfc_hbq_defs[qno]->entry_count;
  12589. /* Recalc repost for RQs based on buffers initially posted */
  12590. cnt = (cnt >> 3);
  12591. if (cnt < LPFC_QUEUE_MIN_REPOST)
  12592. cnt = LPFC_QUEUE_MIN_REPOST;
  12593. rq->entry_repost = cnt;
  12594. }
  12595. /**
  12596. * lpfc_rq_create - Create a Receive Queue on the HBA
  12597. * @phba: HBA structure that indicates port to create a queue on.
  12598. * @hrq: The queue structure to use to create the header receive queue.
  12599. * @drq: The queue structure to use to create the data receive queue.
  12600. * @cq: The completion queue to bind this work queue to.
  12601. *
  12602. * This function creates a receive buffer queue pair , as detailed in @hrq and
  12603. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  12604. * to the HBA.
  12605. *
  12606. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  12607. * struct is used to get the entry count that is necessary to determine the
  12608. * number of pages to use for this queue. The @cq is used to indicate which
  12609. * completion queue to bind received buffers that are posted to these queues to.
  12610. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  12611. * receive queue pair. This function is asynchronous and will wait for the
  12612. * mailbox command to finish before continuing.
  12613. *
  12614. * On success this function will return a zero. If unable to allocate enough
  12615. * memory this function will return -ENOMEM. If the queue create mailbox command
  12616. * fails this function will return -ENXIO.
  12617. **/
  12618. int
  12619. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  12620. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  12621. {
  12622. struct lpfc_mbx_rq_create *rq_create;
  12623. struct lpfc_dmabuf *dmabuf;
  12624. LPFC_MBOXQ_t *mbox;
  12625. int rc, length, status = 0;
  12626. uint32_t shdr_status, shdr_add_status;
  12627. union lpfc_sli4_cfg_shdr *shdr;
  12628. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12629. void __iomem *bar_memmap_p;
  12630. uint32_t db_offset;
  12631. uint16_t pci_barset;
  12632. /* sanity check on queue memory */
  12633. if (!hrq || !drq || !cq)
  12634. return -ENODEV;
  12635. if (!phba->sli4_hba.pc_sli4_params.supported)
  12636. hw_page_size = SLI4_PAGE_SIZE;
  12637. if (hrq->entry_count != drq->entry_count)
  12638. return -EINVAL;
  12639. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12640. if (!mbox)
  12641. return -ENOMEM;
  12642. length = (sizeof(struct lpfc_mbx_rq_create) -
  12643. sizeof(struct lpfc_sli4_cfg_mhdr));
  12644. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12645. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12646. length, LPFC_SLI4_MBX_EMBED);
  12647. rq_create = &mbox->u.mqe.un.rq_create;
  12648. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12649. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12650. phba->sli4_hba.pc_sli4_params.rqv);
  12651. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12652. bf_set(lpfc_rq_context_rqe_count_1,
  12653. &rq_create->u.request.context,
  12654. hrq->entry_count);
  12655. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  12656. bf_set(lpfc_rq_context_rqe_size,
  12657. &rq_create->u.request.context,
  12658. LPFC_RQE_SIZE_8);
  12659. bf_set(lpfc_rq_context_page_size,
  12660. &rq_create->u.request.context,
  12661. LPFC_RQ_PAGE_SIZE_4096);
  12662. } else {
  12663. switch (hrq->entry_count) {
  12664. default:
  12665. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12666. "2535 Unsupported RQ count. (%d)\n",
  12667. hrq->entry_count);
  12668. if (hrq->entry_count < 512) {
  12669. status = -EINVAL;
  12670. goto out;
  12671. }
  12672. /* otherwise default to smallest count (drop through) */
  12673. case 512:
  12674. bf_set(lpfc_rq_context_rqe_count,
  12675. &rq_create->u.request.context,
  12676. LPFC_RQ_RING_SIZE_512);
  12677. break;
  12678. case 1024:
  12679. bf_set(lpfc_rq_context_rqe_count,
  12680. &rq_create->u.request.context,
  12681. LPFC_RQ_RING_SIZE_1024);
  12682. break;
  12683. case 2048:
  12684. bf_set(lpfc_rq_context_rqe_count,
  12685. &rq_create->u.request.context,
  12686. LPFC_RQ_RING_SIZE_2048);
  12687. break;
  12688. case 4096:
  12689. bf_set(lpfc_rq_context_rqe_count,
  12690. &rq_create->u.request.context,
  12691. LPFC_RQ_RING_SIZE_4096);
  12692. break;
  12693. }
  12694. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12695. LPFC_HDR_BUF_SIZE);
  12696. }
  12697. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12698. cq->queue_id);
  12699. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12700. hrq->page_count);
  12701. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  12702. memset(dmabuf->virt, 0, hw_page_size);
  12703. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12704. putPaddrLow(dmabuf->phys);
  12705. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12706. putPaddrHigh(dmabuf->phys);
  12707. }
  12708. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12709. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12710. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12711. /* The IOCTL status is embedded in the mailbox subheader. */
  12712. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12713. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12714. if (shdr_status || shdr_add_status || rc) {
  12715. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12716. "2504 RQ_CREATE mailbox failed with "
  12717. "status x%x add_status x%x, mbx status x%x\n",
  12718. shdr_status, shdr_add_status, rc);
  12719. status = -ENXIO;
  12720. goto out;
  12721. }
  12722. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12723. if (hrq->queue_id == 0xFFFF) {
  12724. status = -ENXIO;
  12725. goto out;
  12726. }
  12727. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  12728. hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
  12729. &rq_create->u.response);
  12730. if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
  12731. (hrq->db_format != LPFC_DB_RING_FORMAT)) {
  12732. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12733. "3262 RQ [%d] doorbell format not "
  12734. "supported: x%x\n", hrq->queue_id,
  12735. hrq->db_format);
  12736. status = -EINVAL;
  12737. goto out;
  12738. }
  12739. pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
  12740. &rq_create->u.response);
  12741. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  12742. if (!bar_memmap_p) {
  12743. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12744. "3269 RQ[%d] failed to memmap pci "
  12745. "barset:x%x\n", hrq->queue_id,
  12746. pci_barset);
  12747. status = -ENOMEM;
  12748. goto out;
  12749. }
  12750. db_offset = rq_create->u.response.doorbell_offset;
  12751. if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
  12752. (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
  12753. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12754. "3270 RQ[%d] doorbell offset not "
  12755. "supported: x%x\n", hrq->queue_id,
  12756. db_offset);
  12757. status = -EINVAL;
  12758. goto out;
  12759. }
  12760. hrq->db_regaddr = bar_memmap_p + db_offset;
  12761. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12762. "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
  12763. "format:x%x\n", hrq->queue_id, pci_barset,
  12764. db_offset, hrq->db_format);
  12765. } else {
  12766. hrq->db_format = LPFC_DB_RING_FORMAT;
  12767. hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  12768. }
  12769. hrq->type = LPFC_HRQ;
  12770. hrq->assoc_qid = cq->queue_id;
  12771. hrq->subtype = subtype;
  12772. hrq->host_index = 0;
  12773. hrq->hba_index = 0;
  12774. /* now create the data queue */
  12775. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12776. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12777. length, LPFC_SLI4_MBX_EMBED);
  12778. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12779. phba->sli4_hba.pc_sli4_params.rqv);
  12780. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12781. bf_set(lpfc_rq_context_rqe_count_1,
  12782. &rq_create->u.request.context, hrq->entry_count);
  12783. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  12784. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  12785. LPFC_RQE_SIZE_8);
  12786. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  12787. (PAGE_SIZE/SLI4_PAGE_SIZE));
  12788. } else {
  12789. switch (drq->entry_count) {
  12790. default:
  12791. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12792. "2536 Unsupported RQ count. (%d)\n",
  12793. drq->entry_count);
  12794. if (drq->entry_count < 512) {
  12795. status = -EINVAL;
  12796. goto out;
  12797. }
  12798. /* otherwise default to smallest count (drop through) */
  12799. case 512:
  12800. bf_set(lpfc_rq_context_rqe_count,
  12801. &rq_create->u.request.context,
  12802. LPFC_RQ_RING_SIZE_512);
  12803. break;
  12804. case 1024:
  12805. bf_set(lpfc_rq_context_rqe_count,
  12806. &rq_create->u.request.context,
  12807. LPFC_RQ_RING_SIZE_1024);
  12808. break;
  12809. case 2048:
  12810. bf_set(lpfc_rq_context_rqe_count,
  12811. &rq_create->u.request.context,
  12812. LPFC_RQ_RING_SIZE_2048);
  12813. break;
  12814. case 4096:
  12815. bf_set(lpfc_rq_context_rqe_count,
  12816. &rq_create->u.request.context,
  12817. LPFC_RQ_RING_SIZE_4096);
  12818. break;
  12819. }
  12820. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12821. LPFC_DATA_BUF_SIZE);
  12822. }
  12823. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12824. cq->queue_id);
  12825. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12826. drq->page_count);
  12827. list_for_each_entry(dmabuf, &drq->page_list, list) {
  12828. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12829. putPaddrLow(dmabuf->phys);
  12830. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12831. putPaddrHigh(dmabuf->phys);
  12832. }
  12833. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12834. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12835. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12836. /* The IOCTL status is embedded in the mailbox subheader. */
  12837. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12838. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12839. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12840. if (shdr_status || shdr_add_status || rc) {
  12841. status = -ENXIO;
  12842. goto out;
  12843. }
  12844. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12845. if (drq->queue_id == 0xFFFF) {
  12846. status = -ENXIO;
  12847. goto out;
  12848. }
  12849. drq->type = LPFC_DRQ;
  12850. drq->assoc_qid = cq->queue_id;
  12851. drq->subtype = subtype;
  12852. drq->host_index = 0;
  12853. drq->hba_index = 0;
  12854. /* link the header and data RQs onto the parent cq child list */
  12855. list_add_tail(&hrq->list, &cq->child_list);
  12856. list_add_tail(&drq->list, &cq->child_list);
  12857. out:
  12858. mempool_free(mbox, phba->mbox_mem_pool);
  12859. return status;
  12860. }
  12861. /**
  12862. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  12863. * @eq: The queue structure associated with the queue to destroy.
  12864. *
  12865. * This function destroys a queue, as detailed in @eq by sending an mailbox
  12866. * command, specific to the type of queue, to the HBA.
  12867. *
  12868. * The @eq struct is used to get the queue ID of the queue to destroy.
  12869. *
  12870. * On success this function will return a zero. If the queue destroy mailbox
  12871. * command fails this function will return -ENXIO.
  12872. **/
  12873. int
  12874. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  12875. {
  12876. LPFC_MBOXQ_t *mbox;
  12877. int rc, length, status = 0;
  12878. uint32_t shdr_status, shdr_add_status;
  12879. union lpfc_sli4_cfg_shdr *shdr;
  12880. /* sanity check on queue memory */
  12881. if (!eq)
  12882. return -ENODEV;
  12883. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  12884. if (!mbox)
  12885. return -ENOMEM;
  12886. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  12887. sizeof(struct lpfc_sli4_cfg_mhdr));
  12888. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12889. LPFC_MBOX_OPCODE_EQ_DESTROY,
  12890. length, LPFC_SLI4_MBX_EMBED);
  12891. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  12892. eq->queue_id);
  12893. mbox->vport = eq->phba->pport;
  12894. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12895. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  12896. /* The IOCTL status is embedded in the mailbox subheader. */
  12897. shdr = (union lpfc_sli4_cfg_shdr *)
  12898. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  12899. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12900. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12901. if (shdr_status || shdr_add_status || rc) {
  12902. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12903. "2505 EQ_DESTROY mailbox failed with "
  12904. "status x%x add_status x%x, mbx status x%x\n",
  12905. shdr_status, shdr_add_status, rc);
  12906. status = -ENXIO;
  12907. }
  12908. /* Remove eq from any list */
  12909. list_del_init(&eq->list);
  12910. mempool_free(mbox, eq->phba->mbox_mem_pool);
  12911. return status;
  12912. }
  12913. /**
  12914. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  12915. * @cq: The queue structure associated with the queue to destroy.
  12916. *
  12917. * This function destroys a queue, as detailed in @cq by sending an mailbox
  12918. * command, specific to the type of queue, to the HBA.
  12919. *
  12920. * The @cq struct is used to get the queue ID of the queue to destroy.
  12921. *
  12922. * On success this function will return a zero. If the queue destroy mailbox
  12923. * command fails this function will return -ENXIO.
  12924. **/
  12925. int
  12926. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  12927. {
  12928. LPFC_MBOXQ_t *mbox;
  12929. int rc, length, status = 0;
  12930. uint32_t shdr_status, shdr_add_status;
  12931. union lpfc_sli4_cfg_shdr *shdr;
  12932. /* sanity check on queue memory */
  12933. if (!cq)
  12934. return -ENODEV;
  12935. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  12936. if (!mbox)
  12937. return -ENOMEM;
  12938. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  12939. sizeof(struct lpfc_sli4_cfg_mhdr));
  12940. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12941. LPFC_MBOX_OPCODE_CQ_DESTROY,
  12942. length, LPFC_SLI4_MBX_EMBED);
  12943. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  12944. cq->queue_id);
  12945. mbox->vport = cq->phba->pport;
  12946. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12947. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  12948. /* The IOCTL status is embedded in the mailbox subheader. */
  12949. shdr = (union lpfc_sli4_cfg_shdr *)
  12950. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  12951. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12952. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12953. if (shdr_status || shdr_add_status || rc) {
  12954. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12955. "2506 CQ_DESTROY mailbox failed with "
  12956. "status x%x add_status x%x, mbx status x%x\n",
  12957. shdr_status, shdr_add_status, rc);
  12958. status = -ENXIO;
  12959. }
  12960. /* Remove cq from any list */
  12961. list_del_init(&cq->list);
  12962. mempool_free(mbox, cq->phba->mbox_mem_pool);
  12963. return status;
  12964. }
  12965. /**
  12966. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  12967. * @qm: The queue structure associated with the queue to destroy.
  12968. *
  12969. * This function destroys a queue, as detailed in @mq by sending an mailbox
  12970. * command, specific to the type of queue, to the HBA.
  12971. *
  12972. * The @mq struct is used to get the queue ID of the queue to destroy.
  12973. *
  12974. * On success this function will return a zero. If the queue destroy mailbox
  12975. * command fails this function will return -ENXIO.
  12976. **/
  12977. int
  12978. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  12979. {
  12980. LPFC_MBOXQ_t *mbox;
  12981. int rc, length, status = 0;
  12982. uint32_t shdr_status, shdr_add_status;
  12983. union lpfc_sli4_cfg_shdr *shdr;
  12984. /* sanity check on queue memory */
  12985. if (!mq)
  12986. return -ENODEV;
  12987. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  12988. if (!mbox)
  12989. return -ENOMEM;
  12990. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  12991. sizeof(struct lpfc_sli4_cfg_mhdr));
  12992. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12993. LPFC_MBOX_OPCODE_MQ_DESTROY,
  12994. length, LPFC_SLI4_MBX_EMBED);
  12995. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  12996. mq->queue_id);
  12997. mbox->vport = mq->phba->pport;
  12998. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12999. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  13000. /* The IOCTL status is embedded in the mailbox subheader. */
  13001. shdr = (union lpfc_sli4_cfg_shdr *)
  13002. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  13003. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13004. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13005. if (shdr_status || shdr_add_status || rc) {
  13006. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13007. "2507 MQ_DESTROY mailbox failed with "
  13008. "status x%x add_status x%x, mbx status x%x\n",
  13009. shdr_status, shdr_add_status, rc);
  13010. status = -ENXIO;
  13011. }
  13012. /* Remove mq from any list */
  13013. list_del_init(&mq->list);
  13014. mempool_free(mbox, mq->phba->mbox_mem_pool);
  13015. return status;
  13016. }
  13017. /**
  13018. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  13019. * @wq: The queue structure associated with the queue to destroy.
  13020. *
  13021. * This function destroys a queue, as detailed in @wq by sending an mailbox
  13022. * command, specific to the type of queue, to the HBA.
  13023. *
  13024. * The @wq struct is used to get the queue ID of the queue to destroy.
  13025. *
  13026. * On success this function will return a zero. If the queue destroy mailbox
  13027. * command fails this function will return -ENXIO.
  13028. **/
  13029. int
  13030. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  13031. {
  13032. LPFC_MBOXQ_t *mbox;
  13033. int rc, length, status = 0;
  13034. uint32_t shdr_status, shdr_add_status;
  13035. union lpfc_sli4_cfg_shdr *shdr;
  13036. /* sanity check on queue memory */
  13037. if (!wq)
  13038. return -ENODEV;
  13039. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  13040. if (!mbox)
  13041. return -ENOMEM;
  13042. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  13043. sizeof(struct lpfc_sli4_cfg_mhdr));
  13044. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13045. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  13046. length, LPFC_SLI4_MBX_EMBED);
  13047. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  13048. wq->queue_id);
  13049. mbox->vport = wq->phba->pport;
  13050. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13051. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  13052. shdr = (union lpfc_sli4_cfg_shdr *)
  13053. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  13054. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13055. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13056. if (shdr_status || shdr_add_status || rc) {
  13057. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13058. "2508 WQ_DESTROY mailbox failed with "
  13059. "status x%x add_status x%x, mbx status x%x\n",
  13060. shdr_status, shdr_add_status, rc);
  13061. status = -ENXIO;
  13062. }
  13063. /* Remove wq from any list */
  13064. list_del_init(&wq->list);
  13065. mempool_free(mbox, wq->phba->mbox_mem_pool);
  13066. return status;
  13067. }
  13068. /**
  13069. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  13070. * @rq: The queue structure associated with the queue to destroy.
  13071. *
  13072. * This function destroys a queue, as detailed in @rq by sending an mailbox
  13073. * command, specific to the type of queue, to the HBA.
  13074. *
  13075. * The @rq struct is used to get the queue ID of the queue to destroy.
  13076. *
  13077. * On success this function will return a zero. If the queue destroy mailbox
  13078. * command fails this function will return -ENXIO.
  13079. **/
  13080. int
  13081. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  13082. struct lpfc_queue *drq)
  13083. {
  13084. LPFC_MBOXQ_t *mbox;
  13085. int rc, length, status = 0;
  13086. uint32_t shdr_status, shdr_add_status;
  13087. union lpfc_sli4_cfg_shdr *shdr;
  13088. /* sanity check on queue memory */
  13089. if (!hrq || !drq)
  13090. return -ENODEV;
  13091. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  13092. if (!mbox)
  13093. return -ENOMEM;
  13094. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  13095. sizeof(struct lpfc_sli4_cfg_mhdr));
  13096. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13097. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  13098. length, LPFC_SLI4_MBX_EMBED);
  13099. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  13100. hrq->queue_id);
  13101. mbox->vport = hrq->phba->pport;
  13102. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13103. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  13104. /* The IOCTL status is embedded in the mailbox subheader. */
  13105. shdr = (union lpfc_sli4_cfg_shdr *)
  13106. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  13107. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13108. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13109. if (shdr_status || shdr_add_status || rc) {
  13110. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13111. "2509 RQ_DESTROY mailbox failed with "
  13112. "status x%x add_status x%x, mbx status x%x\n",
  13113. shdr_status, shdr_add_status, rc);
  13114. if (rc != MBX_TIMEOUT)
  13115. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  13116. return -ENXIO;
  13117. }
  13118. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  13119. drq->queue_id);
  13120. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  13121. shdr = (union lpfc_sli4_cfg_shdr *)
  13122. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  13123. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13124. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13125. if (shdr_status || shdr_add_status || rc) {
  13126. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13127. "2510 RQ_DESTROY mailbox failed with "
  13128. "status x%x add_status x%x, mbx status x%x\n",
  13129. shdr_status, shdr_add_status, rc);
  13130. status = -ENXIO;
  13131. }
  13132. list_del_init(&hrq->list);
  13133. list_del_init(&drq->list);
  13134. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  13135. return status;
  13136. }
  13137. /**
  13138. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  13139. * @phba: The virtual port for which this call being executed.
  13140. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  13141. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  13142. * @xritag: the xritag that ties this io to the SGL pages.
  13143. *
  13144. * This routine will post the sgl pages for the IO that has the xritag
  13145. * that is in the iocbq structure. The xritag is assigned during iocbq
  13146. * creation and persists for as long as the driver is loaded.
  13147. * if the caller has fewer than 256 scatter gather segments to map then
  13148. * pdma_phys_addr1 should be 0.
  13149. * If the caller needs to map more than 256 scatter gather segment then
  13150. * pdma_phys_addr1 should be a valid physical address.
  13151. * physical address for SGLs must be 64 byte aligned.
  13152. * If you are going to map 2 SGL's then the first one must have 256 entries
  13153. * the second sgl can have between 1 and 256 entries.
  13154. *
  13155. * Return codes:
  13156. * 0 - Success
  13157. * -ENXIO, -ENOMEM - Failure
  13158. **/
  13159. int
  13160. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  13161. dma_addr_t pdma_phys_addr0,
  13162. dma_addr_t pdma_phys_addr1,
  13163. uint16_t xritag)
  13164. {
  13165. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  13166. LPFC_MBOXQ_t *mbox;
  13167. int rc;
  13168. uint32_t shdr_status, shdr_add_status;
  13169. uint32_t mbox_tmo;
  13170. union lpfc_sli4_cfg_shdr *shdr;
  13171. if (xritag == NO_XRI) {
  13172. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13173. "0364 Invalid param:\n");
  13174. return -EINVAL;
  13175. }
  13176. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13177. if (!mbox)
  13178. return -ENOMEM;
  13179. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13180. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  13181. sizeof(struct lpfc_mbx_post_sgl_pages) -
  13182. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  13183. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  13184. &mbox->u.mqe.un.post_sgl_pages;
  13185. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  13186. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  13187. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  13188. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  13189. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  13190. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  13191. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  13192. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  13193. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  13194. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  13195. if (!phba->sli4_hba.intr_enable)
  13196. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13197. else {
  13198. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13199. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13200. }
  13201. /* The IOCTL status is embedded in the mailbox subheader. */
  13202. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  13203. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13204. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13205. if (rc != MBX_TIMEOUT)
  13206. mempool_free(mbox, phba->mbox_mem_pool);
  13207. if (shdr_status || shdr_add_status || rc) {
  13208. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13209. "2511 POST_SGL mailbox failed with "
  13210. "status x%x add_status x%x, mbx status x%x\n",
  13211. shdr_status, shdr_add_status, rc);
  13212. }
  13213. return 0;
  13214. }
  13215. /**
  13216. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  13217. * @phba: pointer to lpfc hba data structure.
  13218. *
  13219. * This routine is invoked to post rpi header templates to the
  13220. * HBA consistent with the SLI-4 interface spec. This routine
  13221. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13222. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13223. *
  13224. * Returns
  13225. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13226. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13227. **/
  13228. static uint16_t
  13229. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  13230. {
  13231. unsigned long xri;
  13232. /*
  13233. * Fetch the next logical xri. Because this index is logical,
  13234. * the driver starts at 0 each time.
  13235. */
  13236. spin_lock_irq(&phba->hbalock);
  13237. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  13238. phba->sli4_hba.max_cfg_param.max_xri, 0);
  13239. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  13240. spin_unlock_irq(&phba->hbalock);
  13241. return NO_XRI;
  13242. } else {
  13243. set_bit(xri, phba->sli4_hba.xri_bmask);
  13244. phba->sli4_hba.max_cfg_param.xri_used++;
  13245. }
  13246. spin_unlock_irq(&phba->hbalock);
  13247. return xri;
  13248. }
  13249. /**
  13250. * lpfc_sli4_free_xri - Release an xri for reuse.
  13251. * @phba: pointer to lpfc hba data structure.
  13252. *
  13253. * This routine is invoked to release an xri to the pool of
  13254. * available rpis maintained by the driver.
  13255. **/
  13256. static void
  13257. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  13258. {
  13259. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  13260. phba->sli4_hba.max_cfg_param.xri_used--;
  13261. }
  13262. }
  13263. /**
  13264. * lpfc_sli4_free_xri - Release an xri for reuse.
  13265. * @phba: pointer to lpfc hba data structure.
  13266. *
  13267. * This routine is invoked to release an xri to the pool of
  13268. * available rpis maintained by the driver.
  13269. **/
  13270. void
  13271. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  13272. {
  13273. spin_lock_irq(&phba->hbalock);
  13274. __lpfc_sli4_free_xri(phba, xri);
  13275. spin_unlock_irq(&phba->hbalock);
  13276. }
  13277. /**
  13278. * lpfc_sli4_next_xritag - Get an xritag for the io
  13279. * @phba: Pointer to HBA context object.
  13280. *
  13281. * This function gets an xritag for the iocb. If there is no unused xritag
  13282. * it will return 0xffff.
  13283. * The function returns the allocated xritag if successful, else returns zero.
  13284. * Zero is not a valid xritag.
  13285. * The caller is not required to hold any lock.
  13286. **/
  13287. uint16_t
  13288. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  13289. {
  13290. uint16_t xri_index;
  13291. xri_index = lpfc_sli4_alloc_xri(phba);
  13292. if (xri_index == NO_XRI)
  13293. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  13294. "2004 Failed to allocate XRI.last XRITAG is %d"
  13295. " Max XRI is %d, Used XRI is %d\n",
  13296. xri_index,
  13297. phba->sli4_hba.max_cfg_param.max_xri,
  13298. phba->sli4_hba.max_cfg_param.xri_used);
  13299. return xri_index;
  13300. }
  13301. /**
  13302. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  13303. * @phba: pointer to lpfc hba data structure.
  13304. * @post_sgl_list: pointer to els sgl entry list.
  13305. * @count: number of els sgl entries on the list.
  13306. *
  13307. * This routine is invoked to post a block of driver's sgl pages to the
  13308. * HBA using non-embedded mailbox command. No Lock is held. This routine
  13309. * is only called when the driver is loading and after all IO has been
  13310. * stopped.
  13311. **/
  13312. static int
  13313. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  13314. struct list_head *post_sgl_list,
  13315. int post_cnt)
  13316. {
  13317. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  13318. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  13319. struct sgl_page_pairs *sgl_pg_pairs;
  13320. void *viraddr;
  13321. LPFC_MBOXQ_t *mbox;
  13322. uint32_t reqlen, alloclen, pg_pairs;
  13323. uint32_t mbox_tmo;
  13324. uint16_t xritag_start = 0;
  13325. int rc = 0;
  13326. uint32_t shdr_status, shdr_add_status;
  13327. union lpfc_sli4_cfg_shdr *shdr;
  13328. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  13329. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  13330. if (reqlen > SLI4_PAGE_SIZE) {
  13331. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  13332. "2559 Block sgl registration required DMA "
  13333. "size (%d) great than a page\n", reqlen);
  13334. return -ENOMEM;
  13335. }
  13336. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13337. if (!mbox)
  13338. return -ENOMEM;
  13339. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13340. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13341. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  13342. LPFC_SLI4_MBX_NEMBED);
  13343. if (alloclen < reqlen) {
  13344. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13345. "0285 Allocated DMA memory size (%d) is "
  13346. "less than the requested DMA memory "
  13347. "size (%d)\n", alloclen, reqlen);
  13348. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13349. return -ENOMEM;
  13350. }
  13351. /* Set up the SGL pages in the non-embedded DMA pages */
  13352. viraddr = mbox->sge_array->addr[0];
  13353. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  13354. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  13355. pg_pairs = 0;
  13356. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  13357. /* Set up the sge entry */
  13358. sgl_pg_pairs->sgl_pg0_addr_lo =
  13359. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  13360. sgl_pg_pairs->sgl_pg0_addr_hi =
  13361. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  13362. sgl_pg_pairs->sgl_pg1_addr_lo =
  13363. cpu_to_le32(putPaddrLow(0));
  13364. sgl_pg_pairs->sgl_pg1_addr_hi =
  13365. cpu_to_le32(putPaddrHigh(0));
  13366. /* Keep the first xritag on the list */
  13367. if (pg_pairs == 0)
  13368. xritag_start = sglq_entry->sli4_xritag;
  13369. sgl_pg_pairs++;
  13370. pg_pairs++;
  13371. }
  13372. /* Complete initialization and perform endian conversion. */
  13373. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  13374. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  13375. sgl->word0 = cpu_to_le32(sgl->word0);
  13376. if (!phba->sli4_hba.intr_enable)
  13377. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13378. else {
  13379. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13380. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13381. }
  13382. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  13383. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13384. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13385. if (rc != MBX_TIMEOUT)
  13386. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13387. if (shdr_status || shdr_add_status || rc) {
  13388. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13389. "2513 POST_SGL_BLOCK mailbox command failed "
  13390. "status x%x add_status x%x mbx status x%x\n",
  13391. shdr_status, shdr_add_status, rc);
  13392. rc = -ENXIO;
  13393. }
  13394. return rc;
  13395. }
  13396. /**
  13397. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  13398. * @phba: pointer to lpfc hba data structure.
  13399. * @sblist: pointer to scsi buffer list.
  13400. * @count: number of scsi buffers on the list.
  13401. *
  13402. * This routine is invoked to post a block of @count scsi sgl pages from a
  13403. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  13404. * No Lock is held.
  13405. *
  13406. **/
  13407. int
  13408. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  13409. struct list_head *sblist,
  13410. int count)
  13411. {
  13412. struct lpfc_scsi_buf *psb;
  13413. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  13414. struct sgl_page_pairs *sgl_pg_pairs;
  13415. void *viraddr;
  13416. LPFC_MBOXQ_t *mbox;
  13417. uint32_t reqlen, alloclen, pg_pairs;
  13418. uint32_t mbox_tmo;
  13419. uint16_t xritag_start = 0;
  13420. int rc = 0;
  13421. uint32_t shdr_status, shdr_add_status;
  13422. dma_addr_t pdma_phys_bpl1;
  13423. union lpfc_sli4_cfg_shdr *shdr;
  13424. /* Calculate the requested length of the dma memory */
  13425. reqlen = count * sizeof(struct sgl_page_pairs) +
  13426. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  13427. if (reqlen > SLI4_PAGE_SIZE) {
  13428. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  13429. "0217 Block sgl registration required DMA "
  13430. "size (%d) great than a page\n", reqlen);
  13431. return -ENOMEM;
  13432. }
  13433. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13434. if (!mbox) {
  13435. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13436. "0283 Failed to allocate mbox cmd memory\n");
  13437. return -ENOMEM;
  13438. }
  13439. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13440. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13441. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  13442. LPFC_SLI4_MBX_NEMBED);
  13443. if (alloclen < reqlen) {
  13444. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13445. "2561 Allocated DMA memory size (%d) is "
  13446. "less than the requested DMA memory "
  13447. "size (%d)\n", alloclen, reqlen);
  13448. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13449. return -ENOMEM;
  13450. }
  13451. /* Get the first SGE entry from the non-embedded DMA memory */
  13452. viraddr = mbox->sge_array->addr[0];
  13453. /* Set up the SGL pages in the non-embedded DMA pages */
  13454. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  13455. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  13456. pg_pairs = 0;
  13457. list_for_each_entry(psb, sblist, list) {
  13458. /* Set up the sge entry */
  13459. sgl_pg_pairs->sgl_pg0_addr_lo =
  13460. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  13461. sgl_pg_pairs->sgl_pg0_addr_hi =
  13462. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  13463. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  13464. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  13465. else
  13466. pdma_phys_bpl1 = 0;
  13467. sgl_pg_pairs->sgl_pg1_addr_lo =
  13468. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  13469. sgl_pg_pairs->sgl_pg1_addr_hi =
  13470. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  13471. /* Keep the first xritag on the list */
  13472. if (pg_pairs == 0)
  13473. xritag_start = psb->cur_iocbq.sli4_xritag;
  13474. sgl_pg_pairs++;
  13475. pg_pairs++;
  13476. }
  13477. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  13478. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  13479. /* Perform endian conversion if necessary */
  13480. sgl->word0 = cpu_to_le32(sgl->word0);
  13481. if (!phba->sli4_hba.intr_enable)
  13482. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13483. else {
  13484. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13485. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13486. }
  13487. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  13488. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13489. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13490. if (rc != MBX_TIMEOUT)
  13491. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13492. if (shdr_status || shdr_add_status || rc) {
  13493. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13494. "2564 POST_SGL_BLOCK mailbox command failed "
  13495. "status x%x add_status x%x mbx status x%x\n",
  13496. shdr_status, shdr_add_status, rc);
  13497. rc = -ENXIO;
  13498. }
  13499. return rc;
  13500. }
  13501. /**
  13502. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  13503. * @phba: pointer to lpfc_hba struct that the frame was received on
  13504. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13505. *
  13506. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  13507. * valid type of frame that the LPFC driver will handle. This function will
  13508. * return a zero if the frame is a valid frame or a non zero value when the
  13509. * frame does not pass the check.
  13510. **/
  13511. static int
  13512. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  13513. {
  13514. /* make rctl_names static to save stack space */
  13515. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  13516. char *type_names[] = FC_TYPE_NAMES_INIT;
  13517. struct fc_vft_header *fc_vft_hdr;
  13518. uint32_t *header = (uint32_t *) fc_hdr;
  13519. switch (fc_hdr->fh_r_ctl) {
  13520. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  13521. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  13522. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  13523. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  13524. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  13525. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  13526. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  13527. case FC_RCTL_DD_CMD_STATUS: /* command status */
  13528. case FC_RCTL_ELS_REQ: /* extended link services request */
  13529. case FC_RCTL_ELS_REP: /* extended link services reply */
  13530. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  13531. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  13532. case FC_RCTL_BA_NOP: /* basic link service NOP */
  13533. case FC_RCTL_BA_ABTS: /* basic link service abort */
  13534. case FC_RCTL_BA_RMC: /* remove connection */
  13535. case FC_RCTL_BA_ACC: /* basic accept */
  13536. case FC_RCTL_BA_RJT: /* basic reject */
  13537. case FC_RCTL_BA_PRMT:
  13538. case FC_RCTL_ACK_1: /* acknowledge_1 */
  13539. case FC_RCTL_ACK_0: /* acknowledge_0 */
  13540. case FC_RCTL_P_RJT: /* port reject */
  13541. case FC_RCTL_F_RJT: /* fabric reject */
  13542. case FC_RCTL_P_BSY: /* port busy */
  13543. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  13544. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  13545. case FC_RCTL_LCR: /* link credit reset */
  13546. case FC_RCTL_END: /* end */
  13547. break;
  13548. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  13549. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  13550. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  13551. return lpfc_fc_frame_check(phba, fc_hdr);
  13552. default:
  13553. goto drop;
  13554. }
  13555. switch (fc_hdr->fh_type) {
  13556. case FC_TYPE_BLS:
  13557. case FC_TYPE_ELS:
  13558. case FC_TYPE_FCP:
  13559. case FC_TYPE_CT:
  13560. break;
  13561. case FC_TYPE_IP:
  13562. case FC_TYPE_ILS:
  13563. default:
  13564. goto drop;
  13565. }
  13566. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  13567. "2538 Received frame rctl:%s (x%x), type:%s (x%x), "
  13568. "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
  13569. rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl,
  13570. type_names[fc_hdr->fh_type], fc_hdr->fh_type,
  13571. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  13572. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  13573. be32_to_cpu(header[4]), be32_to_cpu(header[5]),
  13574. be32_to_cpu(header[6]));
  13575. return 0;
  13576. drop:
  13577. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  13578. "2539 Dropped frame rctl:%s type:%s\n",
  13579. rctl_names[fc_hdr->fh_r_ctl],
  13580. type_names[fc_hdr->fh_type]);
  13581. return 1;
  13582. }
  13583. /**
  13584. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  13585. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13586. *
  13587. * This function processes the FC header to retrieve the VFI from the VF
  13588. * header, if one exists. This function will return the VFI if one exists
  13589. * or 0 if no VSAN Header exists.
  13590. **/
  13591. static uint32_t
  13592. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  13593. {
  13594. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  13595. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  13596. return 0;
  13597. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  13598. }
  13599. /**
  13600. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  13601. * @phba: Pointer to the HBA structure to search for the vport on
  13602. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13603. * @fcfi: The FC Fabric ID that the frame came from
  13604. *
  13605. * This function searches the @phba for a vport that matches the content of the
  13606. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  13607. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  13608. * returns the matching vport pointer or NULL if unable to match frame to a
  13609. * vport.
  13610. **/
  13611. static struct lpfc_vport *
  13612. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  13613. uint16_t fcfi)
  13614. {
  13615. struct lpfc_vport **vports;
  13616. struct lpfc_vport *vport = NULL;
  13617. int i;
  13618. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  13619. fc_hdr->fh_d_id[1] << 8 |
  13620. fc_hdr->fh_d_id[2]);
  13621. if (did == Fabric_DID)
  13622. return phba->pport;
  13623. if ((phba->pport->fc_flag & FC_PT2PT) &&
  13624. !(phba->link_state == LPFC_HBA_READY))
  13625. return phba->pport;
  13626. vports = lpfc_create_vport_work_array(phba);
  13627. if (vports != NULL)
  13628. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  13629. if (phba->fcf.fcfi == fcfi &&
  13630. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  13631. vports[i]->fc_myDID == did) {
  13632. vport = vports[i];
  13633. break;
  13634. }
  13635. }
  13636. lpfc_destroy_vport_work_array(phba, vports);
  13637. return vport;
  13638. }
  13639. /**
  13640. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  13641. * @vport: The vport to work on.
  13642. *
  13643. * This function updates the receive sequence time stamp for this vport. The
  13644. * receive sequence time stamp indicates the time that the last frame of the
  13645. * the sequence that has been idle for the longest amount of time was received.
  13646. * the driver uses this time stamp to indicate if any received sequences have
  13647. * timed out.
  13648. **/
  13649. static void
  13650. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  13651. {
  13652. struct lpfc_dmabuf *h_buf;
  13653. struct hbq_dmabuf *dmabuf = NULL;
  13654. /* get the oldest sequence on the rcv list */
  13655. h_buf = list_get_first(&vport->rcv_buffer_list,
  13656. struct lpfc_dmabuf, list);
  13657. if (!h_buf)
  13658. return;
  13659. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13660. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  13661. }
  13662. /**
  13663. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  13664. * @vport: The vport that the received sequences were sent to.
  13665. *
  13666. * This function cleans up all outstanding received sequences. This is called
  13667. * by the driver when a link event or user action invalidates all the received
  13668. * sequences.
  13669. **/
  13670. void
  13671. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  13672. {
  13673. struct lpfc_dmabuf *h_buf, *hnext;
  13674. struct lpfc_dmabuf *d_buf, *dnext;
  13675. struct hbq_dmabuf *dmabuf = NULL;
  13676. /* start with the oldest sequence on the rcv list */
  13677. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  13678. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13679. list_del_init(&dmabuf->hbuf.list);
  13680. list_for_each_entry_safe(d_buf, dnext,
  13681. &dmabuf->dbuf.list, list) {
  13682. list_del_init(&d_buf->list);
  13683. lpfc_in_buf_free(vport->phba, d_buf);
  13684. }
  13685. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  13686. }
  13687. }
  13688. /**
  13689. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  13690. * @vport: The vport that the received sequences were sent to.
  13691. *
  13692. * This function determines whether any received sequences have timed out by
  13693. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  13694. * indicates that there is at least one timed out sequence this routine will
  13695. * go through the received sequences one at a time from most inactive to most
  13696. * active to determine which ones need to be cleaned up. Once it has determined
  13697. * that a sequence needs to be cleaned up it will simply free up the resources
  13698. * without sending an abort.
  13699. **/
  13700. void
  13701. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  13702. {
  13703. struct lpfc_dmabuf *h_buf, *hnext;
  13704. struct lpfc_dmabuf *d_buf, *dnext;
  13705. struct hbq_dmabuf *dmabuf = NULL;
  13706. unsigned long timeout;
  13707. int abort_count = 0;
  13708. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  13709. vport->rcv_buffer_time_stamp);
  13710. if (list_empty(&vport->rcv_buffer_list) ||
  13711. time_before(jiffies, timeout))
  13712. return;
  13713. /* start with the oldest sequence on the rcv list */
  13714. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  13715. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13716. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  13717. dmabuf->time_stamp);
  13718. if (time_before(jiffies, timeout))
  13719. break;
  13720. abort_count++;
  13721. list_del_init(&dmabuf->hbuf.list);
  13722. list_for_each_entry_safe(d_buf, dnext,
  13723. &dmabuf->dbuf.list, list) {
  13724. list_del_init(&d_buf->list);
  13725. lpfc_in_buf_free(vport->phba, d_buf);
  13726. }
  13727. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  13728. }
  13729. if (abort_count)
  13730. lpfc_update_rcv_time_stamp(vport);
  13731. }
  13732. /**
  13733. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  13734. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  13735. *
  13736. * This function searches through the existing incomplete sequences that have
  13737. * been sent to this @vport. If the frame matches one of the incomplete
  13738. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  13739. * make up that sequence. If no sequence is found that matches this frame then
  13740. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  13741. * This function returns a pointer to the first dmabuf in the sequence list that
  13742. * the frame was linked to.
  13743. **/
  13744. static struct hbq_dmabuf *
  13745. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13746. {
  13747. struct fc_frame_header *new_hdr;
  13748. struct fc_frame_header *temp_hdr;
  13749. struct lpfc_dmabuf *d_buf;
  13750. struct lpfc_dmabuf *h_buf;
  13751. struct hbq_dmabuf *seq_dmabuf = NULL;
  13752. struct hbq_dmabuf *temp_dmabuf = NULL;
  13753. uint8_t found = 0;
  13754. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13755. dmabuf->time_stamp = jiffies;
  13756. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13757. /* Use the hdr_buf to find the sequence that this frame belongs to */
  13758. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13759. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13760. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13761. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13762. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13763. continue;
  13764. /* found a pending sequence that matches this frame */
  13765. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13766. break;
  13767. }
  13768. if (!seq_dmabuf) {
  13769. /*
  13770. * This indicates first frame received for this sequence.
  13771. * Queue the buffer on the vport's rcv_buffer_list.
  13772. */
  13773. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13774. lpfc_update_rcv_time_stamp(vport);
  13775. return dmabuf;
  13776. }
  13777. temp_hdr = seq_dmabuf->hbuf.virt;
  13778. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  13779. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13780. list_del_init(&seq_dmabuf->hbuf.list);
  13781. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13782. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13783. lpfc_update_rcv_time_stamp(vport);
  13784. return dmabuf;
  13785. }
  13786. /* move this sequence to the tail to indicate a young sequence */
  13787. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13788. seq_dmabuf->time_stamp = jiffies;
  13789. lpfc_update_rcv_time_stamp(vport);
  13790. if (list_empty(&seq_dmabuf->dbuf.list)) {
  13791. temp_hdr = dmabuf->hbuf.virt;
  13792. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13793. return seq_dmabuf;
  13794. }
  13795. /* find the correct place in the sequence to insert this frame */
  13796. d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
  13797. while (!found) {
  13798. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13799. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  13800. /*
  13801. * If the frame's sequence count is greater than the frame on
  13802. * the list then insert the frame right after this frame
  13803. */
  13804. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  13805. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13806. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  13807. found = 1;
  13808. break;
  13809. }
  13810. if (&d_buf->list == &seq_dmabuf->dbuf.list)
  13811. break;
  13812. d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
  13813. }
  13814. if (found)
  13815. return seq_dmabuf;
  13816. return NULL;
  13817. }
  13818. /**
  13819. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  13820. * @vport: pointer to a vitural port
  13821. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13822. *
  13823. * This function tries to abort from the partially assembed sequence, described
  13824. * by the information from basic abbort @dmabuf. It checks to see whether such
  13825. * partially assembled sequence held by the driver. If so, it shall free up all
  13826. * the frames from the partially assembled sequence.
  13827. *
  13828. * Return
  13829. * true -- if there is matching partially assembled sequence present and all
  13830. * the frames freed with the sequence;
  13831. * false -- if there is no matching partially assembled sequence present so
  13832. * nothing got aborted in the lower layer driver
  13833. **/
  13834. static bool
  13835. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  13836. struct hbq_dmabuf *dmabuf)
  13837. {
  13838. struct fc_frame_header *new_hdr;
  13839. struct fc_frame_header *temp_hdr;
  13840. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  13841. struct hbq_dmabuf *seq_dmabuf = NULL;
  13842. /* Use the hdr_buf to find the sequence that matches this frame */
  13843. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13844. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  13845. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13846. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13847. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13848. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13849. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13850. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13851. continue;
  13852. /* found a pending sequence that matches this frame */
  13853. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13854. break;
  13855. }
  13856. /* Free up all the frames from the partially assembled sequence */
  13857. if (seq_dmabuf) {
  13858. list_for_each_entry_safe(d_buf, n_buf,
  13859. &seq_dmabuf->dbuf.list, list) {
  13860. list_del_init(&d_buf->list);
  13861. lpfc_in_buf_free(vport->phba, d_buf);
  13862. }
  13863. return true;
  13864. }
  13865. return false;
  13866. }
  13867. /**
  13868. * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
  13869. * @vport: pointer to a vitural port
  13870. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13871. *
  13872. * This function tries to abort from the assembed sequence from upper level
  13873. * protocol, described by the information from basic abbort @dmabuf. It
  13874. * checks to see whether such pending context exists at upper level protocol.
  13875. * If so, it shall clean up the pending context.
  13876. *
  13877. * Return
  13878. * true -- if there is matching pending context of the sequence cleaned
  13879. * at ulp;
  13880. * false -- if there is no matching pending context of the sequence present
  13881. * at ulp.
  13882. **/
  13883. static bool
  13884. lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13885. {
  13886. struct lpfc_hba *phba = vport->phba;
  13887. int handled;
  13888. /* Accepting abort at ulp with SLI4 only */
  13889. if (phba->sli_rev < LPFC_SLI_REV4)
  13890. return false;
  13891. /* Register all caring upper level protocols to attend abort */
  13892. handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
  13893. if (handled)
  13894. return true;
  13895. return false;
  13896. }
  13897. /**
  13898. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  13899. * @phba: Pointer to HBA context object.
  13900. * @cmd_iocbq: pointer to the command iocbq structure.
  13901. * @rsp_iocbq: pointer to the response iocbq structure.
  13902. *
  13903. * This function handles the sequence abort response iocb command complete
  13904. * event. It properly releases the memory allocated to the sequence abort
  13905. * accept iocb.
  13906. **/
  13907. static void
  13908. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  13909. struct lpfc_iocbq *cmd_iocbq,
  13910. struct lpfc_iocbq *rsp_iocbq)
  13911. {
  13912. struct lpfc_nodelist *ndlp;
  13913. if (cmd_iocbq) {
  13914. ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
  13915. lpfc_nlp_put(ndlp);
  13916. lpfc_nlp_not_used(ndlp);
  13917. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  13918. }
  13919. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  13920. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  13921. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13922. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  13923. rsp_iocbq->iocb.ulpStatus,
  13924. rsp_iocbq->iocb.un.ulpWord[4]);
  13925. }
  13926. /**
  13927. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  13928. * @phba: Pointer to HBA context object.
  13929. * @xri: xri id in transaction.
  13930. *
  13931. * This function validates the xri maps to the known range of XRIs allocated an
  13932. * used by the driver.
  13933. **/
  13934. uint16_t
  13935. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  13936. uint16_t xri)
  13937. {
  13938. uint16_t i;
  13939. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  13940. if (xri == phba->sli4_hba.xri_ids[i])
  13941. return i;
  13942. }
  13943. return NO_XRI;
  13944. }
  13945. /**
  13946. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  13947. * @phba: Pointer to HBA context object.
  13948. * @fc_hdr: pointer to a FC frame header.
  13949. *
  13950. * This function sends a basic response to a previous unsol sequence abort
  13951. * event after aborting the sequence handling.
  13952. **/
  13953. static void
  13954. lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
  13955. struct fc_frame_header *fc_hdr, bool aborted)
  13956. {
  13957. struct lpfc_hba *phba = vport->phba;
  13958. struct lpfc_iocbq *ctiocb = NULL;
  13959. struct lpfc_nodelist *ndlp;
  13960. uint16_t oxid, rxid, xri, lxri;
  13961. uint32_t sid, fctl;
  13962. IOCB_t *icmd;
  13963. int rc;
  13964. if (!lpfc_is_link_up(phba))
  13965. return;
  13966. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13967. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  13968. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  13969. ndlp = lpfc_findnode_did(vport, sid);
  13970. if (!ndlp) {
  13971. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  13972. if (!ndlp) {
  13973. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13974. "1268 Failed to allocate ndlp for "
  13975. "oxid:x%x SID:x%x\n", oxid, sid);
  13976. return;
  13977. }
  13978. lpfc_nlp_init(vport, ndlp, sid);
  13979. /* Put ndlp onto pport node list */
  13980. lpfc_enqueue_node(vport, ndlp);
  13981. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  13982. /* re-setup ndlp without removing from node list */
  13983. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  13984. if (!ndlp) {
  13985. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13986. "3275 Failed to active ndlp found "
  13987. "for oxid:x%x SID:x%x\n", oxid, sid);
  13988. return;
  13989. }
  13990. }
  13991. /* Allocate buffer for rsp iocb */
  13992. ctiocb = lpfc_sli_get_iocbq(phba);
  13993. if (!ctiocb)
  13994. return;
  13995. /* Extract the F_CTL field from FC_HDR */
  13996. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  13997. icmd = &ctiocb->iocb;
  13998. icmd->un.xseq64.bdl.bdeSize = 0;
  13999. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  14000. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  14001. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  14002. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  14003. /* Fill in the rest of iocb fields */
  14004. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  14005. icmd->ulpBdeCount = 0;
  14006. icmd->ulpLe = 1;
  14007. icmd->ulpClass = CLASS3;
  14008. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  14009. ctiocb->context1 = lpfc_nlp_get(ndlp);
  14010. ctiocb->iocb_cmpl = NULL;
  14011. ctiocb->vport = phba->pport;
  14012. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  14013. ctiocb->sli4_lxritag = NO_XRI;
  14014. ctiocb->sli4_xritag = NO_XRI;
  14015. if (fctl & FC_FC_EX_CTX)
  14016. /* Exchange responder sent the abort so we
  14017. * own the oxid.
  14018. */
  14019. xri = oxid;
  14020. else
  14021. xri = rxid;
  14022. lxri = lpfc_sli4_xri_inrange(phba, xri);
  14023. if (lxri != NO_XRI)
  14024. lpfc_set_rrq_active(phba, ndlp, lxri,
  14025. (xri == oxid) ? rxid : oxid, 0);
  14026. /* For BA_ABTS from exchange responder, if the logical xri with
  14027. * the oxid maps to the FCP XRI range, the port no longer has
  14028. * that exchange context, send a BLS_RJT. Override the IOCB for
  14029. * a BA_RJT.
  14030. */
  14031. if ((fctl & FC_FC_EX_CTX) &&
  14032. (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) {
  14033. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  14034. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  14035. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  14036. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  14037. }
  14038. /* If BA_ABTS failed to abort a partially assembled receive sequence,
  14039. * the driver no longer has that exchange, send a BLS_RJT. Override
  14040. * the IOCB for a BA_RJT.
  14041. */
  14042. if (aborted == false) {
  14043. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  14044. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  14045. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  14046. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  14047. }
  14048. if (fctl & FC_FC_EX_CTX) {
  14049. /* ABTS sent by responder to CT exchange, construction
  14050. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  14051. * field and RX_ID from ABTS for RX_ID field.
  14052. */
  14053. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  14054. } else {
  14055. /* ABTS sent by initiator to CT exchange, construction
  14056. * of BA_ACC will need to allocate a new XRI as for the
  14057. * XRI_TAG field.
  14058. */
  14059. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  14060. }
  14061. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  14062. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  14063. /* Xmit CT abts response on exchange <xid> */
  14064. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  14065. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  14066. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  14067. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  14068. if (rc == IOCB_ERROR) {
  14069. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  14070. "2925 Failed to issue CT ABTS RSP x%x on "
  14071. "xri x%x, Data x%x\n",
  14072. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  14073. phba->link_state);
  14074. lpfc_nlp_put(ndlp);
  14075. ctiocb->context1 = NULL;
  14076. lpfc_sli_release_iocbq(phba, ctiocb);
  14077. }
  14078. }
  14079. /**
  14080. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  14081. * @vport: Pointer to the vport on which this sequence was received
  14082. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  14083. *
  14084. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  14085. * receive sequence is only partially assembed by the driver, it shall abort
  14086. * the partially assembled frames for the sequence. Otherwise, if the
  14087. * unsolicited receive sequence has been completely assembled and passed to
  14088. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  14089. * unsolicited sequence has been aborted. After that, it will issue a basic
  14090. * accept to accept the abort.
  14091. **/
  14092. static void
  14093. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  14094. struct hbq_dmabuf *dmabuf)
  14095. {
  14096. struct lpfc_hba *phba = vport->phba;
  14097. struct fc_frame_header fc_hdr;
  14098. uint32_t fctl;
  14099. bool aborted;
  14100. /* Make a copy of fc_hdr before the dmabuf being released */
  14101. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  14102. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  14103. if (fctl & FC_FC_EX_CTX) {
  14104. /* ABTS by responder to exchange, no cleanup needed */
  14105. aborted = true;
  14106. } else {
  14107. /* ABTS by initiator to exchange, need to do cleanup */
  14108. aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  14109. if (aborted == false)
  14110. aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
  14111. }
  14112. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14113. /* Respond with BA_ACC or BA_RJT accordingly */
  14114. lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
  14115. }
  14116. /**
  14117. * lpfc_seq_complete - Indicates if a sequence is complete
  14118. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  14119. *
  14120. * This function checks the sequence, starting with the frame described by
  14121. * @dmabuf, to see if all the frames associated with this sequence are present.
  14122. * the frames associated with this sequence are linked to the @dmabuf using the
  14123. * dbuf list. This function looks for two major things. 1) That the first frame
  14124. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  14125. * set. 3) That there are no holes in the sequence count. The function will
  14126. * return 1 when the sequence is complete, otherwise it will return 0.
  14127. **/
  14128. static int
  14129. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  14130. {
  14131. struct fc_frame_header *hdr;
  14132. struct lpfc_dmabuf *d_buf;
  14133. struct hbq_dmabuf *seq_dmabuf;
  14134. uint32_t fctl;
  14135. int seq_count = 0;
  14136. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  14137. /* make sure first fame of sequence has a sequence count of zero */
  14138. if (hdr->fh_seq_cnt != seq_count)
  14139. return 0;
  14140. fctl = (hdr->fh_f_ctl[0] << 16 |
  14141. hdr->fh_f_ctl[1] << 8 |
  14142. hdr->fh_f_ctl[2]);
  14143. /* If last frame of sequence we can return success. */
  14144. if (fctl & FC_FC_END_SEQ)
  14145. return 1;
  14146. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  14147. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  14148. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14149. /* If there is a hole in the sequence count then fail. */
  14150. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  14151. return 0;
  14152. fctl = (hdr->fh_f_ctl[0] << 16 |
  14153. hdr->fh_f_ctl[1] << 8 |
  14154. hdr->fh_f_ctl[2]);
  14155. /* If last frame of sequence we can return success. */
  14156. if (fctl & FC_FC_END_SEQ)
  14157. return 1;
  14158. }
  14159. return 0;
  14160. }
  14161. /**
  14162. * lpfc_prep_seq - Prep sequence for ULP processing
  14163. * @vport: Pointer to the vport on which this sequence was received
  14164. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  14165. *
  14166. * This function takes a sequence, described by a list of frames, and creates
  14167. * a list of iocbq structures to describe the sequence. This iocbq list will be
  14168. * used to issue to the generic unsolicited sequence handler. This routine
  14169. * returns a pointer to the first iocbq in the list. If the function is unable
  14170. * to allocate an iocbq then it throw out the received frames that were not
  14171. * able to be described and return a pointer to the first iocbq. If unable to
  14172. * allocate any iocbqs (including the first) this function will return NULL.
  14173. **/
  14174. static struct lpfc_iocbq *
  14175. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  14176. {
  14177. struct hbq_dmabuf *hbq_buf;
  14178. struct lpfc_dmabuf *d_buf, *n_buf;
  14179. struct lpfc_iocbq *first_iocbq, *iocbq;
  14180. struct fc_frame_header *fc_hdr;
  14181. uint32_t sid;
  14182. uint32_t len, tot_len;
  14183. struct ulp_bde64 *pbde;
  14184. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14185. /* remove from receive buffer list */
  14186. list_del_init(&seq_dmabuf->hbuf.list);
  14187. lpfc_update_rcv_time_stamp(vport);
  14188. /* get the Remote Port's SID */
  14189. sid = sli4_sid_from_fc_hdr(fc_hdr);
  14190. tot_len = 0;
  14191. /* Get an iocbq struct to fill in. */
  14192. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  14193. if (first_iocbq) {
  14194. /* Initialize the first IOCB. */
  14195. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  14196. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  14197. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  14198. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  14199. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  14200. first_iocbq->iocb.un.rcvels.parmRo =
  14201. sli4_did_from_fc_hdr(fc_hdr);
  14202. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  14203. } else
  14204. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  14205. first_iocbq->iocb.ulpContext = NO_XRI;
  14206. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  14207. be16_to_cpu(fc_hdr->fh_ox_id);
  14208. /* iocbq is prepped for internal consumption. Physical vpi. */
  14209. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  14210. vport->phba->vpi_ids[vport->vpi];
  14211. /* put the first buffer into the first IOCBq */
  14212. tot_len = bf_get(lpfc_rcqe_length,
  14213. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  14214. first_iocbq->context2 = &seq_dmabuf->dbuf;
  14215. first_iocbq->context3 = NULL;
  14216. first_iocbq->iocb.ulpBdeCount = 1;
  14217. if (tot_len > LPFC_DATA_BUF_SIZE)
  14218. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  14219. LPFC_DATA_BUF_SIZE;
  14220. else
  14221. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
  14222. first_iocbq->iocb.un.rcvels.remoteID = sid;
  14223. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  14224. }
  14225. iocbq = first_iocbq;
  14226. /*
  14227. * Each IOCBq can have two Buffers assigned, so go through the list
  14228. * of buffers for this sequence and save two buffers in each IOCBq
  14229. */
  14230. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  14231. if (!iocbq) {
  14232. lpfc_in_buf_free(vport->phba, d_buf);
  14233. continue;
  14234. }
  14235. if (!iocbq->context3) {
  14236. iocbq->context3 = d_buf;
  14237. iocbq->iocb.ulpBdeCount++;
  14238. /* We need to get the size out of the right CQE */
  14239. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  14240. len = bf_get(lpfc_rcqe_length,
  14241. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  14242. pbde = (struct ulp_bde64 *)
  14243. &iocbq->iocb.unsli3.sli3Words[4];
  14244. if (len > LPFC_DATA_BUF_SIZE)
  14245. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  14246. else
  14247. pbde->tus.f.bdeSize = len;
  14248. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  14249. tot_len += len;
  14250. } else {
  14251. iocbq = lpfc_sli_get_iocbq(vport->phba);
  14252. if (!iocbq) {
  14253. if (first_iocbq) {
  14254. first_iocbq->iocb.ulpStatus =
  14255. IOSTAT_FCP_RSP_ERROR;
  14256. first_iocbq->iocb.un.ulpWord[4] =
  14257. IOERR_NO_RESOURCES;
  14258. }
  14259. lpfc_in_buf_free(vport->phba, d_buf);
  14260. continue;
  14261. }
  14262. /* We need to get the size out of the right CQE */
  14263. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  14264. len = bf_get(lpfc_rcqe_length,
  14265. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  14266. iocbq->context2 = d_buf;
  14267. iocbq->context3 = NULL;
  14268. iocbq->iocb.ulpBdeCount = 1;
  14269. if (len > LPFC_DATA_BUF_SIZE)
  14270. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  14271. LPFC_DATA_BUF_SIZE;
  14272. else
  14273. iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
  14274. tot_len += len;
  14275. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  14276. iocbq->iocb.un.rcvels.remoteID = sid;
  14277. list_add_tail(&iocbq->list, &first_iocbq->list);
  14278. }
  14279. }
  14280. return first_iocbq;
  14281. }
  14282. static void
  14283. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  14284. struct hbq_dmabuf *seq_dmabuf)
  14285. {
  14286. struct fc_frame_header *fc_hdr;
  14287. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  14288. struct lpfc_hba *phba = vport->phba;
  14289. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14290. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  14291. if (!iocbq) {
  14292. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14293. "2707 Ring %d handler: Failed to allocate "
  14294. "iocb Rctl x%x Type x%x received\n",
  14295. LPFC_ELS_RING,
  14296. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  14297. return;
  14298. }
  14299. if (!lpfc_complete_unsol_iocb(phba,
  14300. &phba->sli.ring[LPFC_ELS_RING],
  14301. iocbq, fc_hdr->fh_r_ctl,
  14302. fc_hdr->fh_type))
  14303. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14304. "2540 Ring %d handler: unexpected Rctl "
  14305. "x%x Type x%x received\n",
  14306. LPFC_ELS_RING,
  14307. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  14308. /* Free iocb created in lpfc_prep_seq */
  14309. list_for_each_entry_safe(curr_iocb, next_iocb,
  14310. &iocbq->list, list) {
  14311. list_del_init(&curr_iocb->list);
  14312. lpfc_sli_release_iocbq(phba, curr_iocb);
  14313. }
  14314. lpfc_sli_release_iocbq(phba, iocbq);
  14315. }
  14316. /**
  14317. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  14318. * @phba: Pointer to HBA context object.
  14319. *
  14320. * This function is called with no lock held. This function processes all
  14321. * the received buffers and gives it to upper layers when a received buffer
  14322. * indicates that it is the final frame in the sequence. The interrupt
  14323. * service routine processes received buffers at interrupt contexts and adds
  14324. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  14325. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  14326. * appropriate receive function when the final frame in a sequence is received.
  14327. **/
  14328. void
  14329. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  14330. struct hbq_dmabuf *dmabuf)
  14331. {
  14332. struct hbq_dmabuf *seq_dmabuf;
  14333. struct fc_frame_header *fc_hdr;
  14334. struct lpfc_vport *vport;
  14335. uint32_t fcfi;
  14336. uint32_t did;
  14337. /* Process each received buffer */
  14338. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  14339. /* check to see if this a valid type of frame */
  14340. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  14341. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14342. return;
  14343. }
  14344. if ((bf_get(lpfc_cqe_code,
  14345. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  14346. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  14347. &dmabuf->cq_event.cqe.rcqe_cmpl);
  14348. else
  14349. fcfi = bf_get(lpfc_rcqe_fcf_id,
  14350. &dmabuf->cq_event.cqe.rcqe_cmpl);
  14351. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  14352. if (!vport) {
  14353. /* throw out the frame */
  14354. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14355. return;
  14356. }
  14357. /* d_id this frame is directed to */
  14358. did = sli4_did_from_fc_hdr(fc_hdr);
  14359. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  14360. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  14361. (did != Fabric_DID)) {
  14362. /*
  14363. * Throw out the frame if we are not pt2pt.
  14364. * The pt2pt protocol allows for discovery frames
  14365. * to be received without a registered VPI.
  14366. */
  14367. if (!(vport->fc_flag & FC_PT2PT) ||
  14368. (phba->link_state == LPFC_HBA_READY)) {
  14369. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14370. return;
  14371. }
  14372. }
  14373. /* Handle the basic abort sequence (BA_ABTS) event */
  14374. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  14375. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  14376. return;
  14377. }
  14378. /* Link this frame */
  14379. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  14380. if (!seq_dmabuf) {
  14381. /* unable to add frame to vport - throw it out */
  14382. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14383. return;
  14384. }
  14385. /* If not last frame in sequence continue processing frames. */
  14386. if (!lpfc_seq_complete(seq_dmabuf))
  14387. return;
  14388. /* Send the complete sequence to the upper layer protocol */
  14389. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  14390. }
  14391. /**
  14392. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  14393. * @phba: pointer to lpfc hba data structure.
  14394. *
  14395. * This routine is invoked to post rpi header templates to the
  14396. * HBA consistent with the SLI-4 interface spec. This routine
  14397. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  14398. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  14399. *
  14400. * This routine does not require any locks. It's usage is expected
  14401. * to be driver load or reset recovery when the driver is
  14402. * sequential.
  14403. *
  14404. * Return codes
  14405. * 0 - successful
  14406. * -EIO - The mailbox failed to complete successfully.
  14407. * When this error occurs, the driver is not guaranteed
  14408. * to have any rpi regions posted to the device and
  14409. * must either attempt to repost the regions or take a
  14410. * fatal error.
  14411. **/
  14412. int
  14413. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  14414. {
  14415. struct lpfc_rpi_hdr *rpi_page;
  14416. uint32_t rc = 0;
  14417. uint16_t lrpi = 0;
  14418. /* SLI4 ports that support extents do not require RPI headers. */
  14419. if (!phba->sli4_hba.rpi_hdrs_in_use)
  14420. goto exit;
  14421. if (phba->sli4_hba.extents_in_use)
  14422. return -EIO;
  14423. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  14424. /*
  14425. * Assign the rpi headers a physical rpi only if the driver
  14426. * has not initialized those resources. A port reset only
  14427. * needs the headers posted.
  14428. */
  14429. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  14430. LPFC_RPI_RSRC_RDY)
  14431. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  14432. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  14433. if (rc != MBX_SUCCESS) {
  14434. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14435. "2008 Error %d posting all rpi "
  14436. "headers\n", rc);
  14437. rc = -EIO;
  14438. break;
  14439. }
  14440. }
  14441. exit:
  14442. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  14443. LPFC_RPI_RSRC_RDY);
  14444. return rc;
  14445. }
  14446. /**
  14447. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  14448. * @phba: pointer to lpfc hba data structure.
  14449. * @rpi_page: pointer to the rpi memory region.
  14450. *
  14451. * This routine is invoked to post a single rpi header to the
  14452. * HBA consistent with the SLI-4 interface spec. This memory region
  14453. * maps up to 64 rpi context regions.
  14454. *
  14455. * Return codes
  14456. * 0 - successful
  14457. * -ENOMEM - No available memory
  14458. * -EIO - The mailbox failed to complete successfully.
  14459. **/
  14460. int
  14461. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  14462. {
  14463. LPFC_MBOXQ_t *mboxq;
  14464. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  14465. uint32_t rc = 0;
  14466. uint32_t shdr_status, shdr_add_status;
  14467. union lpfc_sli4_cfg_shdr *shdr;
  14468. /* SLI4 ports that support extents do not require RPI headers. */
  14469. if (!phba->sli4_hba.rpi_hdrs_in_use)
  14470. return rc;
  14471. if (phba->sli4_hba.extents_in_use)
  14472. return -EIO;
  14473. /* The port is notified of the header region via a mailbox command. */
  14474. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14475. if (!mboxq) {
  14476. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14477. "2001 Unable to allocate memory for issuing "
  14478. "SLI_CONFIG_SPECIAL mailbox command\n");
  14479. return -ENOMEM;
  14480. }
  14481. /* Post all rpi memory regions to the port. */
  14482. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  14483. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  14484. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  14485. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  14486. sizeof(struct lpfc_sli4_cfg_mhdr),
  14487. LPFC_SLI4_MBX_EMBED);
  14488. /* Post the physical rpi to the port for this rpi header. */
  14489. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  14490. rpi_page->start_rpi);
  14491. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  14492. hdr_tmpl, rpi_page->page_count);
  14493. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  14494. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  14495. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14496. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  14497. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14498. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14499. if (rc != MBX_TIMEOUT)
  14500. mempool_free(mboxq, phba->mbox_mem_pool);
  14501. if (shdr_status || shdr_add_status || rc) {
  14502. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14503. "2514 POST_RPI_HDR mailbox failed with "
  14504. "status x%x add_status x%x, mbx status x%x\n",
  14505. shdr_status, shdr_add_status, rc);
  14506. rc = -ENXIO;
  14507. }
  14508. return rc;
  14509. }
  14510. /**
  14511. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  14512. * @phba: pointer to lpfc hba data structure.
  14513. *
  14514. * This routine is invoked to post rpi header templates to the
  14515. * HBA consistent with the SLI-4 interface spec. This routine
  14516. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  14517. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  14518. *
  14519. * Returns
  14520. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  14521. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  14522. **/
  14523. int
  14524. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  14525. {
  14526. unsigned long rpi;
  14527. uint16_t max_rpi, rpi_limit;
  14528. uint16_t rpi_remaining, lrpi = 0;
  14529. struct lpfc_rpi_hdr *rpi_hdr;
  14530. unsigned long iflag;
  14531. /*
  14532. * Fetch the next logical rpi. Because this index is logical,
  14533. * the driver starts at 0 each time.
  14534. */
  14535. spin_lock_irqsave(&phba->hbalock, iflag);
  14536. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  14537. rpi_limit = phba->sli4_hba.next_rpi;
  14538. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  14539. if (rpi >= rpi_limit)
  14540. rpi = LPFC_RPI_ALLOC_ERROR;
  14541. else {
  14542. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  14543. phba->sli4_hba.max_cfg_param.rpi_used++;
  14544. phba->sli4_hba.rpi_count++;
  14545. }
  14546. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  14547. "0001 rpi:%x max:%x lim:%x\n",
  14548. (int) rpi, max_rpi, rpi_limit);
  14549. /*
  14550. * Don't try to allocate more rpi header regions if the device limit
  14551. * has been exhausted.
  14552. */
  14553. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  14554. (phba->sli4_hba.rpi_count >= max_rpi)) {
  14555. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14556. return rpi;
  14557. }
  14558. /*
  14559. * RPI header postings are not required for SLI4 ports capable of
  14560. * extents.
  14561. */
  14562. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  14563. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14564. return rpi;
  14565. }
  14566. /*
  14567. * If the driver is running low on rpi resources, allocate another
  14568. * page now. Note that the next_rpi value is used because
  14569. * it represents how many are actually in use whereas max_rpi notes
  14570. * how many are supported max by the device.
  14571. */
  14572. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  14573. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14574. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  14575. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  14576. if (!rpi_hdr) {
  14577. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14578. "2002 Error Could not grow rpi "
  14579. "count\n");
  14580. } else {
  14581. lrpi = rpi_hdr->start_rpi;
  14582. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  14583. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  14584. }
  14585. }
  14586. return rpi;
  14587. }
  14588. /**
  14589. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  14590. * @phba: pointer to lpfc hba data structure.
  14591. *
  14592. * This routine is invoked to release an rpi to the pool of
  14593. * available rpis maintained by the driver.
  14594. **/
  14595. static void
  14596. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  14597. {
  14598. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  14599. phba->sli4_hba.rpi_count--;
  14600. phba->sli4_hba.max_cfg_param.rpi_used--;
  14601. }
  14602. }
  14603. /**
  14604. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  14605. * @phba: pointer to lpfc hba data structure.
  14606. *
  14607. * This routine is invoked to release an rpi to the pool of
  14608. * available rpis maintained by the driver.
  14609. **/
  14610. void
  14611. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  14612. {
  14613. spin_lock_irq(&phba->hbalock);
  14614. __lpfc_sli4_free_rpi(phba, rpi);
  14615. spin_unlock_irq(&phba->hbalock);
  14616. }
  14617. /**
  14618. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  14619. * @phba: pointer to lpfc hba data structure.
  14620. *
  14621. * This routine is invoked to remove the memory region that
  14622. * provided rpi via a bitmask.
  14623. **/
  14624. void
  14625. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  14626. {
  14627. kfree(phba->sli4_hba.rpi_bmask);
  14628. kfree(phba->sli4_hba.rpi_ids);
  14629. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  14630. }
  14631. /**
  14632. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  14633. * @phba: pointer to lpfc hba data structure.
  14634. *
  14635. * This routine is invoked to remove the memory region that
  14636. * provided rpi via a bitmask.
  14637. **/
  14638. int
  14639. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  14640. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  14641. {
  14642. LPFC_MBOXQ_t *mboxq;
  14643. struct lpfc_hba *phba = ndlp->phba;
  14644. int rc;
  14645. /* The port is notified of the header region via a mailbox command. */
  14646. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14647. if (!mboxq)
  14648. return -ENOMEM;
  14649. /* Post all rpi memory regions to the port. */
  14650. lpfc_resume_rpi(mboxq, ndlp);
  14651. if (cmpl) {
  14652. mboxq->mbox_cmpl = cmpl;
  14653. mboxq->context1 = arg;
  14654. mboxq->context2 = ndlp;
  14655. } else
  14656. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14657. mboxq->vport = ndlp->vport;
  14658. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14659. if (rc == MBX_NOT_FINISHED) {
  14660. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14661. "2010 Resume RPI Mailbox failed "
  14662. "status %d, mbxStatus x%x\n", rc,
  14663. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  14664. mempool_free(mboxq, phba->mbox_mem_pool);
  14665. return -EIO;
  14666. }
  14667. return 0;
  14668. }
  14669. /**
  14670. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  14671. * @vport: Pointer to the vport for which the vpi is being initialized
  14672. *
  14673. * This routine is invoked to activate a vpi with the port.
  14674. *
  14675. * Returns:
  14676. * 0 success
  14677. * -Evalue otherwise
  14678. **/
  14679. int
  14680. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  14681. {
  14682. LPFC_MBOXQ_t *mboxq;
  14683. int rc = 0;
  14684. int retval = MBX_SUCCESS;
  14685. uint32_t mbox_tmo;
  14686. struct lpfc_hba *phba = vport->phba;
  14687. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14688. if (!mboxq)
  14689. return -ENOMEM;
  14690. lpfc_init_vpi(phba, mboxq, vport->vpi);
  14691. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  14692. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  14693. if (rc != MBX_SUCCESS) {
  14694. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  14695. "2022 INIT VPI Mailbox failed "
  14696. "status %d, mbxStatus x%x\n", rc,
  14697. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  14698. retval = -EIO;
  14699. }
  14700. if (rc != MBX_TIMEOUT)
  14701. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  14702. return retval;
  14703. }
  14704. /**
  14705. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  14706. * @phba: pointer to lpfc hba data structure.
  14707. * @mboxq: Pointer to mailbox object.
  14708. *
  14709. * This routine is invoked to manually add a single FCF record. The caller
  14710. * must pass a completely initialized FCF_Record. This routine takes
  14711. * care of the nonembedded mailbox operations.
  14712. **/
  14713. static void
  14714. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  14715. {
  14716. void *virt_addr;
  14717. union lpfc_sli4_cfg_shdr *shdr;
  14718. uint32_t shdr_status, shdr_add_status;
  14719. virt_addr = mboxq->sge_array->addr[0];
  14720. /* The IOCTL status is embedded in the mailbox subheader. */
  14721. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  14722. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14723. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14724. if ((shdr_status || shdr_add_status) &&
  14725. (shdr_status != STATUS_FCF_IN_USE))
  14726. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14727. "2558 ADD_FCF_RECORD mailbox failed with "
  14728. "status x%x add_status x%x\n",
  14729. shdr_status, shdr_add_status);
  14730. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14731. }
  14732. /**
  14733. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  14734. * @phba: pointer to lpfc hba data structure.
  14735. * @fcf_record: pointer to the initialized fcf record to add.
  14736. *
  14737. * This routine is invoked to manually add a single FCF record. The caller
  14738. * must pass a completely initialized FCF_Record. This routine takes
  14739. * care of the nonembedded mailbox operations.
  14740. **/
  14741. int
  14742. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  14743. {
  14744. int rc = 0;
  14745. LPFC_MBOXQ_t *mboxq;
  14746. uint8_t *bytep;
  14747. void *virt_addr;
  14748. struct lpfc_mbx_sge sge;
  14749. uint32_t alloc_len, req_len;
  14750. uint32_t fcfindex;
  14751. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14752. if (!mboxq) {
  14753. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14754. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  14755. return -ENOMEM;
  14756. }
  14757. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  14758. sizeof(uint32_t);
  14759. /* Allocate DMA memory and set up the non-embedded mailbox command */
  14760. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  14761. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  14762. req_len, LPFC_SLI4_MBX_NEMBED);
  14763. if (alloc_len < req_len) {
  14764. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14765. "2523 Allocated DMA memory size (x%x) is "
  14766. "less than the requested DMA memory "
  14767. "size (x%x)\n", alloc_len, req_len);
  14768. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14769. return -ENOMEM;
  14770. }
  14771. /*
  14772. * Get the first SGE entry from the non-embedded DMA memory. This
  14773. * routine only uses a single SGE.
  14774. */
  14775. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  14776. virt_addr = mboxq->sge_array->addr[0];
  14777. /*
  14778. * Configure the FCF record for FCFI 0. This is the driver's
  14779. * hardcoded default and gets used in nonFIP mode.
  14780. */
  14781. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  14782. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  14783. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  14784. /*
  14785. * Copy the fcf_index and the FCF Record Data. The data starts after
  14786. * the FCoE header plus word10. The data copy needs to be endian
  14787. * correct.
  14788. */
  14789. bytep += sizeof(uint32_t);
  14790. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  14791. mboxq->vport = phba->pport;
  14792. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  14793. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14794. if (rc == MBX_NOT_FINISHED) {
  14795. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14796. "2515 ADD_FCF_RECORD mailbox failed with "
  14797. "status 0x%x\n", rc);
  14798. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14799. rc = -EIO;
  14800. } else
  14801. rc = 0;
  14802. return rc;
  14803. }
  14804. /**
  14805. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  14806. * @phba: pointer to lpfc hba data structure.
  14807. * @fcf_record: pointer to the fcf record to write the default data.
  14808. * @fcf_index: FCF table entry index.
  14809. *
  14810. * This routine is invoked to build the driver's default FCF record. The
  14811. * values used are hardcoded. This routine handles memory initialization.
  14812. *
  14813. **/
  14814. void
  14815. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  14816. struct fcf_record *fcf_record,
  14817. uint16_t fcf_index)
  14818. {
  14819. memset(fcf_record, 0, sizeof(struct fcf_record));
  14820. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  14821. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  14822. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  14823. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  14824. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  14825. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  14826. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  14827. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  14828. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  14829. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  14830. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  14831. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  14832. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  14833. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  14834. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  14835. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  14836. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  14837. /* Set the VLAN bit map */
  14838. if (phba->valid_vlan) {
  14839. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  14840. = 1 << (phba->vlan_id % 8);
  14841. }
  14842. }
  14843. /**
  14844. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  14845. * @phba: pointer to lpfc hba data structure.
  14846. * @fcf_index: FCF table entry offset.
  14847. *
  14848. * This routine is invoked to scan the entire FCF table by reading FCF
  14849. * record and processing it one at a time starting from the @fcf_index
  14850. * for initial FCF discovery or fast FCF failover rediscovery.
  14851. *
  14852. * Return 0 if the mailbox command is submitted successfully, none 0
  14853. * otherwise.
  14854. **/
  14855. int
  14856. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14857. {
  14858. int rc = 0, error;
  14859. LPFC_MBOXQ_t *mboxq;
  14860. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  14861. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  14862. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14863. if (!mboxq) {
  14864. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14865. "2000 Failed to allocate mbox for "
  14866. "READ_FCF cmd\n");
  14867. error = -ENOMEM;
  14868. goto fail_fcf_scan;
  14869. }
  14870. /* Construct the read FCF record mailbox command */
  14871. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14872. if (rc) {
  14873. error = -EINVAL;
  14874. goto fail_fcf_scan;
  14875. }
  14876. /* Issue the mailbox command asynchronously */
  14877. mboxq->vport = phba->pport;
  14878. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  14879. spin_lock_irq(&phba->hbalock);
  14880. phba->hba_flag |= FCF_TS_INPROG;
  14881. spin_unlock_irq(&phba->hbalock);
  14882. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14883. if (rc == MBX_NOT_FINISHED)
  14884. error = -EIO;
  14885. else {
  14886. /* Reset eligible FCF count for new scan */
  14887. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  14888. phba->fcf.eligible_fcf_cnt = 0;
  14889. error = 0;
  14890. }
  14891. fail_fcf_scan:
  14892. if (error) {
  14893. if (mboxq)
  14894. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14895. /* FCF scan failed, clear FCF_TS_INPROG flag */
  14896. spin_lock_irq(&phba->hbalock);
  14897. phba->hba_flag &= ~FCF_TS_INPROG;
  14898. spin_unlock_irq(&phba->hbalock);
  14899. }
  14900. return error;
  14901. }
  14902. /**
  14903. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  14904. * @phba: pointer to lpfc hba data structure.
  14905. * @fcf_index: FCF table entry offset.
  14906. *
  14907. * This routine is invoked to read an FCF record indicated by @fcf_index
  14908. * and to use it for FLOGI roundrobin FCF failover.
  14909. *
  14910. * Return 0 if the mailbox command is submitted successfully, none 0
  14911. * otherwise.
  14912. **/
  14913. int
  14914. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14915. {
  14916. int rc = 0, error;
  14917. LPFC_MBOXQ_t *mboxq;
  14918. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14919. if (!mboxq) {
  14920. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14921. "2763 Failed to allocate mbox for "
  14922. "READ_FCF cmd\n");
  14923. error = -ENOMEM;
  14924. goto fail_fcf_read;
  14925. }
  14926. /* Construct the read FCF record mailbox command */
  14927. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14928. if (rc) {
  14929. error = -EINVAL;
  14930. goto fail_fcf_read;
  14931. }
  14932. /* Issue the mailbox command asynchronously */
  14933. mboxq->vport = phba->pport;
  14934. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  14935. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14936. if (rc == MBX_NOT_FINISHED)
  14937. error = -EIO;
  14938. else
  14939. error = 0;
  14940. fail_fcf_read:
  14941. if (error && mboxq)
  14942. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14943. return error;
  14944. }
  14945. /**
  14946. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  14947. * @phba: pointer to lpfc hba data structure.
  14948. * @fcf_index: FCF table entry offset.
  14949. *
  14950. * This routine is invoked to read an FCF record indicated by @fcf_index to
  14951. * determine whether it's eligible for FLOGI roundrobin failover list.
  14952. *
  14953. * Return 0 if the mailbox command is submitted successfully, none 0
  14954. * otherwise.
  14955. **/
  14956. int
  14957. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14958. {
  14959. int rc = 0, error;
  14960. LPFC_MBOXQ_t *mboxq;
  14961. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14962. if (!mboxq) {
  14963. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14964. "2758 Failed to allocate mbox for "
  14965. "READ_FCF cmd\n");
  14966. error = -ENOMEM;
  14967. goto fail_fcf_read;
  14968. }
  14969. /* Construct the read FCF record mailbox command */
  14970. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14971. if (rc) {
  14972. error = -EINVAL;
  14973. goto fail_fcf_read;
  14974. }
  14975. /* Issue the mailbox command asynchronously */
  14976. mboxq->vport = phba->pport;
  14977. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  14978. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14979. if (rc == MBX_NOT_FINISHED)
  14980. error = -EIO;
  14981. else
  14982. error = 0;
  14983. fail_fcf_read:
  14984. if (error && mboxq)
  14985. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14986. return error;
  14987. }
  14988. /**
  14989. * lpfc_check_next_fcf_pri_level
  14990. * phba pointer to the lpfc_hba struct for this port.
  14991. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  14992. * routine when the rr_bmask is empty. The FCF indecies are put into the
  14993. * rr_bmask based on their priority level. Starting from the highest priority
  14994. * to the lowest. The most likely FCF candidate will be in the highest
  14995. * priority group. When this routine is called it searches the fcf_pri list for
  14996. * next lowest priority group and repopulates the rr_bmask with only those
  14997. * fcf_indexes.
  14998. * returns:
  14999. * 1=success 0=failure
  15000. **/
  15001. static int
  15002. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  15003. {
  15004. uint16_t next_fcf_pri;
  15005. uint16_t last_index;
  15006. struct lpfc_fcf_pri *fcf_pri;
  15007. int rc;
  15008. int ret = 0;
  15009. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  15010. LPFC_SLI4_FCF_TBL_INDX_MAX);
  15011. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15012. "3060 Last IDX %d\n", last_index);
  15013. /* Verify the priority list has 2 or more entries */
  15014. spin_lock_irq(&phba->hbalock);
  15015. if (list_empty(&phba->fcf.fcf_pri_list) ||
  15016. list_is_singular(&phba->fcf.fcf_pri_list)) {
  15017. spin_unlock_irq(&phba->hbalock);
  15018. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15019. "3061 Last IDX %d\n", last_index);
  15020. return 0; /* Empty rr list */
  15021. }
  15022. spin_unlock_irq(&phba->hbalock);
  15023. next_fcf_pri = 0;
  15024. /*
  15025. * Clear the rr_bmask and set all of the bits that are at this
  15026. * priority.
  15027. */
  15028. memset(phba->fcf.fcf_rr_bmask, 0,
  15029. sizeof(*phba->fcf.fcf_rr_bmask));
  15030. spin_lock_irq(&phba->hbalock);
  15031. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  15032. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  15033. continue;
  15034. /*
  15035. * the 1st priority that has not FLOGI failed
  15036. * will be the highest.
  15037. */
  15038. if (!next_fcf_pri)
  15039. next_fcf_pri = fcf_pri->fcf_rec.priority;
  15040. spin_unlock_irq(&phba->hbalock);
  15041. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  15042. rc = lpfc_sli4_fcf_rr_index_set(phba,
  15043. fcf_pri->fcf_rec.fcf_index);
  15044. if (rc)
  15045. return 0;
  15046. }
  15047. spin_lock_irq(&phba->hbalock);
  15048. }
  15049. /*
  15050. * if next_fcf_pri was not set above and the list is not empty then
  15051. * we have failed flogis on all of them. So reset flogi failed
  15052. * and start at the beginning.
  15053. */
  15054. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  15055. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  15056. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  15057. /*
  15058. * the 1st priority that has not FLOGI failed
  15059. * will be the highest.
  15060. */
  15061. if (!next_fcf_pri)
  15062. next_fcf_pri = fcf_pri->fcf_rec.priority;
  15063. spin_unlock_irq(&phba->hbalock);
  15064. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  15065. rc = lpfc_sli4_fcf_rr_index_set(phba,
  15066. fcf_pri->fcf_rec.fcf_index);
  15067. if (rc)
  15068. return 0;
  15069. }
  15070. spin_lock_irq(&phba->hbalock);
  15071. }
  15072. } else
  15073. ret = 1;
  15074. spin_unlock_irq(&phba->hbalock);
  15075. return ret;
  15076. }
  15077. /**
  15078. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  15079. * @phba: pointer to lpfc hba data structure.
  15080. *
  15081. * This routine is to get the next eligible FCF record index in a round
  15082. * robin fashion. If the next eligible FCF record index equals to the
  15083. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  15084. * shall be returned, otherwise, the next eligible FCF record's index
  15085. * shall be returned.
  15086. **/
  15087. uint16_t
  15088. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  15089. {
  15090. uint16_t next_fcf_index;
  15091. initial_priority:
  15092. /* Search start from next bit of currently registered FCF index */
  15093. next_fcf_index = phba->fcf.current_rec.fcf_indx;
  15094. next_priority:
  15095. /* Determine the next fcf index to check */
  15096. next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
  15097. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  15098. LPFC_SLI4_FCF_TBL_INDX_MAX,
  15099. next_fcf_index);
  15100. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  15101. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  15102. /*
  15103. * If we have wrapped then we need to clear the bits that
  15104. * have been tested so that we can detect when we should
  15105. * change the priority level.
  15106. */
  15107. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  15108. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  15109. }
  15110. /* Check roundrobin failover list empty condition */
  15111. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  15112. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  15113. /*
  15114. * If next fcf index is not found check if there are lower
  15115. * Priority level fcf's in the fcf_priority list.
  15116. * Set up the rr_bmask with all of the avaiable fcf bits
  15117. * at that level and continue the selection process.
  15118. */
  15119. if (lpfc_check_next_fcf_pri_level(phba))
  15120. goto initial_priority;
  15121. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  15122. "2844 No roundrobin failover FCF available\n");
  15123. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  15124. return LPFC_FCOE_FCF_NEXT_NONE;
  15125. else {
  15126. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  15127. "3063 Only FCF available idx %d, flag %x\n",
  15128. next_fcf_index,
  15129. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  15130. return next_fcf_index;
  15131. }
  15132. }
  15133. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  15134. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  15135. LPFC_FCF_FLOGI_FAILED) {
  15136. if (list_is_singular(&phba->fcf.fcf_pri_list))
  15137. return LPFC_FCOE_FCF_NEXT_NONE;
  15138. goto next_priority;
  15139. }
  15140. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15141. "2845 Get next roundrobin failover FCF (x%x)\n",
  15142. next_fcf_index);
  15143. return next_fcf_index;
  15144. }
  15145. /**
  15146. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  15147. * @phba: pointer to lpfc hba data structure.
  15148. *
  15149. * This routine sets the FCF record index in to the eligible bmask for
  15150. * roundrobin failover search. It checks to make sure that the index
  15151. * does not go beyond the range of the driver allocated bmask dimension
  15152. * before setting the bit.
  15153. *
  15154. * Returns 0 if the index bit successfully set, otherwise, it returns
  15155. * -EINVAL.
  15156. **/
  15157. int
  15158. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  15159. {
  15160. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  15161. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15162. "2610 FCF (x%x) reached driver's book "
  15163. "keeping dimension:x%x\n",
  15164. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  15165. return -EINVAL;
  15166. }
  15167. /* Set the eligible FCF record index bmask */
  15168. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  15169. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15170. "2790 Set FCF (x%x) to roundrobin FCF failover "
  15171. "bmask\n", fcf_index);
  15172. return 0;
  15173. }
  15174. /**
  15175. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  15176. * @phba: pointer to lpfc hba data structure.
  15177. *
  15178. * This routine clears the FCF record index from the eligible bmask for
  15179. * roundrobin failover search. It checks to make sure that the index
  15180. * does not go beyond the range of the driver allocated bmask dimension
  15181. * before clearing the bit.
  15182. **/
  15183. void
  15184. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  15185. {
  15186. struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
  15187. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  15188. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15189. "2762 FCF (x%x) reached driver's book "
  15190. "keeping dimension:x%x\n",
  15191. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  15192. return;
  15193. }
  15194. /* Clear the eligible FCF record index bmask */
  15195. spin_lock_irq(&phba->hbalock);
  15196. list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
  15197. list) {
  15198. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  15199. list_del_init(&fcf_pri->list);
  15200. break;
  15201. }
  15202. }
  15203. spin_unlock_irq(&phba->hbalock);
  15204. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  15205. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15206. "2791 Clear FCF (x%x) from roundrobin failover "
  15207. "bmask\n", fcf_index);
  15208. }
  15209. /**
  15210. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  15211. * @phba: pointer to lpfc hba data structure.
  15212. *
  15213. * This routine is the completion routine for the rediscover FCF table mailbox
  15214. * command. If the mailbox command returned failure, it will try to stop the
  15215. * FCF rediscover wait timer.
  15216. **/
  15217. static void
  15218. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  15219. {
  15220. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  15221. uint32_t shdr_status, shdr_add_status;
  15222. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  15223. shdr_status = bf_get(lpfc_mbox_hdr_status,
  15224. &redisc_fcf->header.cfg_shdr.response);
  15225. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  15226. &redisc_fcf->header.cfg_shdr.response);
  15227. if (shdr_status || shdr_add_status) {
  15228. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15229. "2746 Requesting for FCF rediscovery failed "
  15230. "status x%x add_status x%x\n",
  15231. shdr_status, shdr_add_status);
  15232. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  15233. spin_lock_irq(&phba->hbalock);
  15234. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  15235. spin_unlock_irq(&phba->hbalock);
  15236. /*
  15237. * CVL event triggered FCF rediscover request failed,
  15238. * last resort to re-try current registered FCF entry.
  15239. */
  15240. lpfc_retry_pport_discovery(phba);
  15241. } else {
  15242. spin_lock_irq(&phba->hbalock);
  15243. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  15244. spin_unlock_irq(&phba->hbalock);
  15245. /*
  15246. * DEAD FCF event triggered FCF rediscover request
  15247. * failed, last resort to fail over as a link down
  15248. * to FCF registration.
  15249. */
  15250. lpfc_sli4_fcf_dead_failthrough(phba);
  15251. }
  15252. } else {
  15253. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15254. "2775 Start FCF rediscover quiescent timer\n");
  15255. /*
  15256. * Start FCF rediscovery wait timer for pending FCF
  15257. * before rescan FCF record table.
  15258. */
  15259. lpfc_fcf_redisc_wait_start_timer(phba);
  15260. }
  15261. mempool_free(mbox, phba->mbox_mem_pool);
  15262. }
  15263. /**
  15264. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  15265. * @phba: pointer to lpfc hba data structure.
  15266. *
  15267. * This routine is invoked to request for rediscovery of the entire FCF table
  15268. * by the port.
  15269. **/
  15270. int
  15271. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  15272. {
  15273. LPFC_MBOXQ_t *mbox;
  15274. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  15275. int rc, length;
  15276. /* Cancel retry delay timers to all vports before FCF rediscover */
  15277. lpfc_cancel_all_vport_retry_delay_timer(phba);
  15278. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15279. if (!mbox) {
  15280. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15281. "2745 Failed to allocate mbox for "
  15282. "requesting FCF rediscover.\n");
  15283. return -ENOMEM;
  15284. }
  15285. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  15286. sizeof(struct lpfc_sli4_cfg_mhdr));
  15287. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  15288. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  15289. length, LPFC_SLI4_MBX_EMBED);
  15290. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  15291. /* Set count to 0 for invalidating the entire FCF database */
  15292. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  15293. /* Issue the mailbox command asynchronously */
  15294. mbox->vport = phba->pport;
  15295. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  15296. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  15297. if (rc == MBX_NOT_FINISHED) {
  15298. mempool_free(mbox, phba->mbox_mem_pool);
  15299. return -EIO;
  15300. }
  15301. return 0;
  15302. }
  15303. /**
  15304. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  15305. * @phba: pointer to lpfc hba data structure.
  15306. *
  15307. * This function is the failover routine as a last resort to the FCF DEAD
  15308. * event when driver failed to perform fast FCF failover.
  15309. **/
  15310. void
  15311. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  15312. {
  15313. uint32_t link_state;
  15314. /*
  15315. * Last resort as FCF DEAD event failover will treat this as
  15316. * a link down, but save the link state because we don't want
  15317. * it to be changed to Link Down unless it is already down.
  15318. */
  15319. link_state = phba->link_state;
  15320. lpfc_linkdown(phba);
  15321. phba->link_state = link_state;
  15322. /* Unregister FCF if no devices connected to it */
  15323. lpfc_unregister_unused_fcf(phba);
  15324. }
  15325. /**
  15326. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  15327. * @phba: pointer to lpfc hba data structure.
  15328. * @rgn23_data: pointer to configure region 23 data.
  15329. *
  15330. * This function gets SLI3 port configure region 23 data through memory dump
  15331. * mailbox command. When it successfully retrieves data, the size of the data
  15332. * will be returned, otherwise, 0 will be returned.
  15333. **/
  15334. static uint32_t
  15335. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  15336. {
  15337. LPFC_MBOXQ_t *pmb = NULL;
  15338. MAILBOX_t *mb;
  15339. uint32_t offset = 0;
  15340. int rc;
  15341. if (!rgn23_data)
  15342. return 0;
  15343. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15344. if (!pmb) {
  15345. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15346. "2600 failed to allocate mailbox memory\n");
  15347. return 0;
  15348. }
  15349. mb = &pmb->u.mb;
  15350. do {
  15351. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  15352. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  15353. if (rc != MBX_SUCCESS) {
  15354. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  15355. "2601 failed to read config "
  15356. "region 23, rc 0x%x Status 0x%x\n",
  15357. rc, mb->mbxStatus);
  15358. mb->un.varDmp.word_cnt = 0;
  15359. }
  15360. /*
  15361. * dump mem may return a zero when finished or we got a
  15362. * mailbox error, either way we are done.
  15363. */
  15364. if (mb->un.varDmp.word_cnt == 0)
  15365. break;
  15366. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  15367. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  15368. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  15369. rgn23_data + offset,
  15370. mb->un.varDmp.word_cnt);
  15371. offset += mb->un.varDmp.word_cnt;
  15372. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  15373. mempool_free(pmb, phba->mbox_mem_pool);
  15374. return offset;
  15375. }
  15376. /**
  15377. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  15378. * @phba: pointer to lpfc hba data structure.
  15379. * @rgn23_data: pointer to configure region 23 data.
  15380. *
  15381. * This function gets SLI4 port configure region 23 data through memory dump
  15382. * mailbox command. When it successfully retrieves data, the size of the data
  15383. * will be returned, otherwise, 0 will be returned.
  15384. **/
  15385. static uint32_t
  15386. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  15387. {
  15388. LPFC_MBOXQ_t *mboxq = NULL;
  15389. struct lpfc_dmabuf *mp = NULL;
  15390. struct lpfc_mqe *mqe;
  15391. uint32_t data_length = 0;
  15392. int rc;
  15393. if (!rgn23_data)
  15394. return 0;
  15395. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15396. if (!mboxq) {
  15397. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15398. "3105 failed to allocate mailbox memory\n");
  15399. return 0;
  15400. }
  15401. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  15402. goto out;
  15403. mqe = &mboxq->u.mqe;
  15404. mp = (struct lpfc_dmabuf *) mboxq->context1;
  15405. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  15406. if (rc)
  15407. goto out;
  15408. data_length = mqe->un.mb_words[5];
  15409. if (data_length == 0)
  15410. goto out;
  15411. if (data_length > DMP_RGN23_SIZE) {
  15412. data_length = 0;
  15413. goto out;
  15414. }
  15415. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  15416. out:
  15417. mempool_free(mboxq, phba->mbox_mem_pool);
  15418. if (mp) {
  15419. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  15420. kfree(mp);
  15421. }
  15422. return data_length;
  15423. }
  15424. /**
  15425. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  15426. * @phba: pointer to lpfc hba data structure.
  15427. *
  15428. * This function read region 23 and parse TLV for port status to
  15429. * decide if the user disaled the port. If the TLV indicates the
  15430. * port is disabled, the hba_flag is set accordingly.
  15431. **/
  15432. void
  15433. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  15434. {
  15435. uint8_t *rgn23_data = NULL;
  15436. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  15437. uint32_t offset = 0;
  15438. /* Get adapter Region 23 data */
  15439. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  15440. if (!rgn23_data)
  15441. goto out;
  15442. if (phba->sli_rev < LPFC_SLI_REV4)
  15443. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  15444. else {
  15445. if_type = bf_get(lpfc_sli_intf_if_type,
  15446. &phba->sli4_hba.sli_intf);
  15447. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  15448. goto out;
  15449. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  15450. }
  15451. if (!data_size)
  15452. goto out;
  15453. /* Check the region signature first */
  15454. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  15455. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15456. "2619 Config region 23 has bad signature\n");
  15457. goto out;
  15458. }
  15459. offset += 4;
  15460. /* Check the data structure version */
  15461. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  15462. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15463. "2620 Config region 23 has bad version\n");
  15464. goto out;
  15465. }
  15466. offset += 4;
  15467. /* Parse TLV entries in the region */
  15468. while (offset < data_size) {
  15469. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  15470. break;
  15471. /*
  15472. * If the TLV is not driver specific TLV or driver id is
  15473. * not linux driver id, skip the record.
  15474. */
  15475. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  15476. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  15477. (rgn23_data[offset + 3] != 0)) {
  15478. offset += rgn23_data[offset + 1] * 4 + 4;
  15479. continue;
  15480. }
  15481. /* Driver found a driver specific TLV in the config region */
  15482. sub_tlv_len = rgn23_data[offset + 1] * 4;
  15483. offset += 4;
  15484. tlv_offset = 0;
  15485. /*
  15486. * Search for configured port state sub-TLV.
  15487. */
  15488. while ((offset < data_size) &&
  15489. (tlv_offset < sub_tlv_len)) {
  15490. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  15491. offset += 4;
  15492. tlv_offset += 4;
  15493. break;
  15494. }
  15495. if (rgn23_data[offset] != PORT_STE_TYPE) {
  15496. offset += rgn23_data[offset + 1] * 4 + 4;
  15497. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  15498. continue;
  15499. }
  15500. /* This HBA contains PORT_STE configured */
  15501. if (!rgn23_data[offset + 2])
  15502. phba->hba_flag |= LINK_DISABLED;
  15503. goto out;
  15504. }
  15505. }
  15506. out:
  15507. kfree(rgn23_data);
  15508. return;
  15509. }
  15510. /**
  15511. * lpfc_wr_object - write an object to the firmware
  15512. * @phba: HBA structure that indicates port to create a queue on.
  15513. * @dmabuf_list: list of dmabufs to write to the port.
  15514. * @size: the total byte value of the objects to write to the port.
  15515. * @offset: the current offset to be used to start the transfer.
  15516. *
  15517. * This routine will create a wr_object mailbox command to send to the port.
  15518. * the mailbox command will be constructed using the dma buffers described in
  15519. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  15520. * BDEs that the imbedded mailbox can support. The @offset variable will be
  15521. * used to indicate the starting offset of the transfer and will also return
  15522. * the offset after the write object mailbox has completed. @size is used to
  15523. * determine the end of the object and whether the eof bit should be set.
  15524. *
  15525. * Return 0 is successful and offset will contain the the new offset to use
  15526. * for the next write.
  15527. * Return negative value for error cases.
  15528. **/
  15529. int
  15530. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  15531. uint32_t size, uint32_t *offset)
  15532. {
  15533. struct lpfc_mbx_wr_object *wr_object;
  15534. LPFC_MBOXQ_t *mbox;
  15535. int rc = 0, i = 0;
  15536. uint32_t shdr_status, shdr_add_status;
  15537. uint32_t mbox_tmo;
  15538. union lpfc_sli4_cfg_shdr *shdr;
  15539. struct lpfc_dmabuf *dmabuf;
  15540. uint32_t written = 0;
  15541. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15542. if (!mbox)
  15543. return -ENOMEM;
  15544. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  15545. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  15546. sizeof(struct lpfc_mbx_wr_object) -
  15547. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  15548. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  15549. wr_object->u.request.write_offset = *offset;
  15550. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  15551. wr_object->u.request.object_name[0] =
  15552. cpu_to_le32(wr_object->u.request.object_name[0]);
  15553. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  15554. list_for_each_entry(dmabuf, dmabuf_list, list) {
  15555. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  15556. break;
  15557. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  15558. wr_object->u.request.bde[i].addrHigh =
  15559. putPaddrHigh(dmabuf->phys);
  15560. if (written + SLI4_PAGE_SIZE >= size) {
  15561. wr_object->u.request.bde[i].tus.f.bdeSize =
  15562. (size - written);
  15563. written += (size - written);
  15564. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  15565. } else {
  15566. wr_object->u.request.bde[i].tus.f.bdeSize =
  15567. SLI4_PAGE_SIZE;
  15568. written += SLI4_PAGE_SIZE;
  15569. }
  15570. i++;
  15571. }
  15572. wr_object->u.request.bde_count = i;
  15573. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  15574. if (!phba->sli4_hba.intr_enable)
  15575. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15576. else {
  15577. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  15578. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  15579. }
  15580. /* The IOCTL status is embedded in the mailbox subheader. */
  15581. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  15582. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15583. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15584. if (rc != MBX_TIMEOUT)
  15585. mempool_free(mbox, phba->mbox_mem_pool);
  15586. if (shdr_status || shdr_add_status || rc) {
  15587. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15588. "3025 Write Object mailbox failed with "
  15589. "status x%x add_status x%x, mbx status x%x\n",
  15590. shdr_status, shdr_add_status, rc);
  15591. rc = -ENXIO;
  15592. } else
  15593. *offset += wr_object->u.response.actual_write_length;
  15594. return rc;
  15595. }
  15596. /**
  15597. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  15598. * @vport: pointer to vport data structure.
  15599. *
  15600. * This function iterate through the mailboxq and clean up all REG_LOGIN
  15601. * and REG_VPI mailbox commands associated with the vport. This function
  15602. * is called when driver want to restart discovery of the vport due to
  15603. * a Clear Virtual Link event.
  15604. **/
  15605. void
  15606. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  15607. {
  15608. struct lpfc_hba *phba = vport->phba;
  15609. LPFC_MBOXQ_t *mb, *nextmb;
  15610. struct lpfc_dmabuf *mp;
  15611. struct lpfc_nodelist *ndlp;
  15612. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  15613. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  15614. LIST_HEAD(mbox_cmd_list);
  15615. uint8_t restart_loop;
  15616. /* Clean up internally queued mailbox commands with the vport */
  15617. spin_lock_irq(&phba->hbalock);
  15618. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  15619. if (mb->vport != vport)
  15620. continue;
  15621. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  15622. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  15623. continue;
  15624. list_del(&mb->list);
  15625. list_add_tail(&mb->list, &mbox_cmd_list);
  15626. }
  15627. /* Clean up active mailbox command with the vport */
  15628. mb = phba->sli.mbox_active;
  15629. if (mb && (mb->vport == vport)) {
  15630. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  15631. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  15632. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15633. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15634. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  15635. /* Put reference count for delayed processing */
  15636. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  15637. /* Unregister the RPI when mailbox complete */
  15638. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  15639. }
  15640. }
  15641. /* Cleanup any mailbox completions which are not yet processed */
  15642. do {
  15643. restart_loop = 0;
  15644. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  15645. /*
  15646. * If this mailox is already processed or it is
  15647. * for another vport ignore it.
  15648. */
  15649. if ((mb->vport != vport) ||
  15650. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  15651. continue;
  15652. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  15653. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  15654. continue;
  15655. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15656. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15657. ndlp = (struct lpfc_nodelist *)mb->context2;
  15658. /* Unregister the RPI when mailbox complete */
  15659. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  15660. restart_loop = 1;
  15661. spin_unlock_irq(&phba->hbalock);
  15662. spin_lock(shost->host_lock);
  15663. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15664. spin_unlock(shost->host_lock);
  15665. spin_lock_irq(&phba->hbalock);
  15666. break;
  15667. }
  15668. }
  15669. } while (restart_loop);
  15670. spin_unlock_irq(&phba->hbalock);
  15671. /* Release the cleaned-up mailbox commands */
  15672. while (!list_empty(&mbox_cmd_list)) {
  15673. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  15674. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15675. mp = (struct lpfc_dmabuf *) (mb->context1);
  15676. if (mp) {
  15677. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  15678. kfree(mp);
  15679. }
  15680. ndlp = (struct lpfc_nodelist *) mb->context2;
  15681. mb->context2 = NULL;
  15682. if (ndlp) {
  15683. spin_lock(shost->host_lock);
  15684. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15685. spin_unlock(shost->host_lock);
  15686. lpfc_nlp_put(ndlp);
  15687. }
  15688. }
  15689. mempool_free(mb, phba->mbox_mem_pool);
  15690. }
  15691. /* Release the ndlp with the cleaned-up active mailbox command */
  15692. if (act_mbx_ndlp) {
  15693. spin_lock(shost->host_lock);
  15694. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15695. spin_unlock(shost->host_lock);
  15696. lpfc_nlp_put(act_mbx_ndlp);
  15697. }
  15698. }
  15699. /**
  15700. * lpfc_drain_txq - Drain the txq
  15701. * @phba: Pointer to HBA context object.
  15702. *
  15703. * This function attempt to submit IOCBs on the txq
  15704. * to the adapter. For SLI4 adapters, the txq contains
  15705. * ELS IOCBs that have been deferred because the there
  15706. * are no SGLs. This congestion can occur with large
  15707. * vport counts during node discovery.
  15708. **/
  15709. uint32_t
  15710. lpfc_drain_txq(struct lpfc_hba *phba)
  15711. {
  15712. LIST_HEAD(completions);
  15713. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  15714. struct lpfc_iocbq *piocbq = NULL;
  15715. unsigned long iflags = 0;
  15716. char *fail_msg = NULL;
  15717. struct lpfc_sglq *sglq;
  15718. union lpfc_wqe wqe;
  15719. uint32_t txq_cnt = 0;
  15720. spin_lock_irqsave(&pring->ring_lock, iflags);
  15721. list_for_each_entry(piocbq, &pring->txq, list) {
  15722. txq_cnt++;
  15723. }
  15724. if (txq_cnt > pring->txq_max)
  15725. pring->txq_max = txq_cnt;
  15726. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15727. while (!list_empty(&pring->txq)) {
  15728. spin_lock_irqsave(&pring->ring_lock, iflags);
  15729. piocbq = lpfc_sli_ringtx_get(phba, pring);
  15730. if (!piocbq) {
  15731. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15732. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15733. "2823 txq empty and txq_cnt is %d\n ",
  15734. txq_cnt);
  15735. break;
  15736. }
  15737. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  15738. if (!sglq) {
  15739. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  15740. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15741. break;
  15742. }
  15743. txq_cnt--;
  15744. /* The xri and iocb resources secured,
  15745. * attempt to issue request
  15746. */
  15747. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  15748. piocbq->sli4_xritag = sglq->sli4_xritag;
  15749. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  15750. fail_msg = "to convert bpl to sgl";
  15751. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  15752. fail_msg = "to convert iocb to wqe";
  15753. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  15754. fail_msg = " - Wq is full";
  15755. else
  15756. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  15757. if (fail_msg) {
  15758. /* Failed means we can't issue and need to cancel */
  15759. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15760. "2822 IOCB failed %s iotag 0x%x "
  15761. "xri 0x%x\n",
  15762. fail_msg,
  15763. piocbq->iotag, piocbq->sli4_xritag);
  15764. list_add_tail(&piocbq->list, &completions);
  15765. }
  15766. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15767. }
  15768. /* Cancel all the IOCBs that cannot be issued */
  15769. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  15770. IOERR_SLI_ABORTED);
  15771. return txq_cnt;
  15772. }