lpfc_sli.c 527 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269
  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. else
  110. bf_set(wqe_wqec, &wqe->generic.wqe_com, 0);
  111. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  112. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  113. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  114. /* ensure WQE bcopy flushed before doorbell write */
  115. wmb();
  116. /* Update the host index before invoking device */
  117. host_index = q->host_index;
  118. q->host_index = idx;
  119. /* Ring Doorbell */
  120. doorbell.word0 = 0;
  121. if (q->db_format == LPFC_DB_LIST_FORMAT) {
  122. bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
  123. bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index);
  124. bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
  125. } else if (q->db_format == LPFC_DB_RING_FORMAT) {
  126. bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
  127. bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
  128. } else {
  129. return -EINVAL;
  130. }
  131. writel(doorbell.word0, q->db_regaddr);
  132. return 0;
  133. }
  134. /**
  135. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  136. * @q: The Work Queue to operate on.
  137. * @index: The index to advance the hba index to.
  138. *
  139. * This routine will update the HBA index of a queue to reflect consumption of
  140. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  141. * an entry the host calls this function to update the queue's internal
  142. * pointers. This routine returns the number of entries that were consumed by
  143. * the HBA.
  144. **/
  145. static uint32_t
  146. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  147. {
  148. uint32_t released = 0;
  149. /* sanity check on queue memory */
  150. if (unlikely(!q))
  151. return 0;
  152. if (q->hba_index == index)
  153. return 0;
  154. do {
  155. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  156. released++;
  157. } while (q->hba_index != index);
  158. return released;
  159. }
  160. /**
  161. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  162. * @q: The Mailbox Queue to operate on.
  163. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  164. *
  165. * This routine will copy the contents of @mqe to the next available entry on
  166. * the @q. This function will then ring the Work Queue Doorbell to signal the
  167. * HBA to start processing the Work Queue Entry. This function returns 0 if
  168. * successful. If no entries are available on @q then this function will return
  169. * -ENOMEM.
  170. * The caller is expected to hold the hbalock when calling this routine.
  171. **/
  172. static uint32_t
  173. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  174. {
  175. struct lpfc_mqe *temp_mqe;
  176. struct lpfc_register doorbell;
  177. /* sanity check on queue memory */
  178. if (unlikely(!q))
  179. return -ENOMEM;
  180. temp_mqe = q->qe[q->host_index].mqe;
  181. /* If the host has not yet processed the next entry then we are done */
  182. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  183. return -ENOMEM;
  184. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  185. /* Save off the mailbox pointer for completion */
  186. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  187. /* Update the host index before invoking device */
  188. q->host_index = ((q->host_index + 1) % q->entry_count);
  189. /* Ring Doorbell */
  190. doorbell.word0 = 0;
  191. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  192. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  193. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  194. return 0;
  195. }
  196. /**
  197. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  198. * @q: The Mailbox Queue to operate on.
  199. *
  200. * This routine will update the HBA index of a queue to reflect consumption of
  201. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  202. * an entry the host calls this function to update the queue's internal
  203. * pointers. This routine returns the number of entries that were consumed by
  204. * the HBA.
  205. **/
  206. static uint32_t
  207. lpfc_sli4_mq_release(struct lpfc_queue *q)
  208. {
  209. /* sanity check on queue memory */
  210. if (unlikely(!q))
  211. return 0;
  212. /* Clear the mailbox pointer for completion */
  213. q->phba->mbox = NULL;
  214. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  215. return 1;
  216. }
  217. /**
  218. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  219. * @q: The Event Queue to get the first valid EQE from
  220. *
  221. * This routine will get the first valid Event Queue Entry from @q, update
  222. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  223. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  224. * processed, but not popped back to the HBA then this routine will return NULL.
  225. **/
  226. static struct lpfc_eqe *
  227. lpfc_sli4_eq_get(struct lpfc_queue *q)
  228. {
  229. struct lpfc_eqe *eqe;
  230. uint32_t idx;
  231. /* sanity check on queue memory */
  232. if (unlikely(!q))
  233. return NULL;
  234. eqe = q->qe[q->hba_index].eqe;
  235. /* If the next EQE is not valid then we are done */
  236. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  237. return NULL;
  238. /* If the host has not yet processed the next entry then we are done */
  239. idx = ((q->hba_index + 1) % q->entry_count);
  240. if (idx == q->host_index)
  241. return NULL;
  242. q->hba_index = idx;
  243. /*
  244. * insert barrier for instruction interlock : data from the hardware
  245. * must have the valid bit checked before it can be copied and acted
  246. * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
  247. * instructions allowing action on content before valid bit checked,
  248. * add barrier here as well. May not be needed as "content" is a
  249. * single 32-bit entity here (vs multi word structure for cq's).
  250. */
  251. mb();
  252. return eqe;
  253. }
  254. /**
  255. * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
  256. * @q: The Event Queue to disable interrupts
  257. *
  258. **/
  259. static inline void
  260. lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
  261. {
  262. struct lpfc_register doorbell;
  263. doorbell.word0 = 0;
  264. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  265. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  266. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  267. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  268. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  269. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  270. }
  271. /**
  272. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  273. * @q: The Event Queue that the host has completed processing for.
  274. * @arm: Indicates whether the host wants to arms this CQ.
  275. *
  276. * This routine will mark all Event Queue Entries on @q, from the last
  277. * known completed entry to the last entry that was processed, as completed
  278. * by clearing the valid bit for each completion queue entry. Then it will
  279. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  280. * The internal host index in the @q will be updated by this routine to indicate
  281. * that the host has finished processing the entries. The @arm parameter
  282. * indicates that the queue should be rearmed when ringing the doorbell.
  283. *
  284. * This function will return the number of EQEs that were popped.
  285. **/
  286. uint32_t
  287. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  288. {
  289. uint32_t released = 0;
  290. struct lpfc_eqe *temp_eqe;
  291. struct lpfc_register doorbell;
  292. /* sanity check on queue memory */
  293. if (unlikely(!q))
  294. return 0;
  295. /* while there are valid entries */
  296. while (q->hba_index != q->host_index) {
  297. temp_eqe = q->qe[q->host_index].eqe;
  298. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  299. released++;
  300. q->host_index = ((q->host_index + 1) % q->entry_count);
  301. }
  302. if (unlikely(released == 0 && !arm))
  303. return 0;
  304. /* ring doorbell for number popped */
  305. doorbell.word0 = 0;
  306. if (arm) {
  307. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  308. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  309. }
  310. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  311. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  312. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  313. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  314. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  315. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  316. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  317. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  318. readl(q->phba->sli4_hba.EQCQDBregaddr);
  319. return released;
  320. }
  321. /**
  322. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  323. * @q: The Completion Queue to get the first valid CQE from
  324. *
  325. * This routine will get the first valid Completion Queue Entry from @q, update
  326. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  327. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  328. * processed, but not popped back to the HBA then this routine will return NULL.
  329. **/
  330. static struct lpfc_cqe *
  331. lpfc_sli4_cq_get(struct lpfc_queue *q)
  332. {
  333. struct lpfc_cqe *cqe;
  334. uint32_t idx;
  335. /* sanity check on queue memory */
  336. if (unlikely(!q))
  337. return NULL;
  338. /* If the next CQE is not valid then we are done */
  339. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  340. return NULL;
  341. /* If the host has not yet processed the next entry then we are done */
  342. idx = ((q->hba_index + 1) % q->entry_count);
  343. if (idx == q->host_index)
  344. return NULL;
  345. cqe = q->qe[q->hba_index].cqe;
  346. q->hba_index = idx;
  347. /*
  348. * insert barrier for instruction interlock : data from the hardware
  349. * must have the valid bit checked before it can be copied and acted
  350. * upon. Speculative instructions were allowing a bcopy at the start
  351. * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
  352. * after our return, to copy data before the valid bit check above
  353. * was done. As such, some of the copied data was stale. The barrier
  354. * ensures the check is before any data is copied.
  355. */
  356. mb();
  357. return cqe;
  358. }
  359. /**
  360. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  361. * @q: The Completion Queue that the host has completed processing for.
  362. * @arm: Indicates whether the host wants to arms this CQ.
  363. *
  364. * This routine will mark all Completion queue entries on @q, from the last
  365. * known completed entry to the last entry that was processed, as completed
  366. * by clearing the valid bit for each completion queue entry. Then it will
  367. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  368. * The internal host index in the @q will be updated by this routine to indicate
  369. * that the host has finished processing the entries. The @arm parameter
  370. * indicates that the queue should be rearmed when ringing the doorbell.
  371. *
  372. * This function will return the number of CQEs that were released.
  373. **/
  374. uint32_t
  375. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  376. {
  377. uint32_t released = 0;
  378. struct lpfc_cqe *temp_qe;
  379. struct lpfc_register doorbell;
  380. /* sanity check on queue memory */
  381. if (unlikely(!q))
  382. return 0;
  383. /* while there are valid entries */
  384. while (q->hba_index != q->host_index) {
  385. temp_qe = q->qe[q->host_index].cqe;
  386. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  387. released++;
  388. q->host_index = ((q->host_index + 1) % q->entry_count);
  389. }
  390. if (unlikely(released == 0 && !arm))
  391. return 0;
  392. /* ring doorbell for number popped */
  393. doorbell.word0 = 0;
  394. if (arm)
  395. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  396. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  397. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  398. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  399. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  400. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  401. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  402. return released;
  403. }
  404. /**
  405. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  406. * @q: The Header Receive Queue to operate on.
  407. * @wqe: The Receive Queue Entry to put on the Receive queue.
  408. *
  409. * This routine will copy the contents of @wqe to the next available entry on
  410. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  411. * HBA to start processing the Receive Queue Entry. This function returns the
  412. * index that the rqe was copied to if successful. If no entries are available
  413. * on @q then this function will return -ENOMEM.
  414. * The caller is expected to hold the hbalock when calling this routine.
  415. **/
  416. static int
  417. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  418. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  419. {
  420. struct lpfc_rqe *temp_hrqe;
  421. struct lpfc_rqe *temp_drqe;
  422. struct lpfc_register doorbell;
  423. int put_index;
  424. /* sanity check on queue memory */
  425. if (unlikely(!hq) || unlikely(!dq))
  426. return -ENOMEM;
  427. put_index = hq->host_index;
  428. temp_hrqe = hq->qe[hq->host_index].rqe;
  429. temp_drqe = dq->qe[dq->host_index].rqe;
  430. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  431. return -EINVAL;
  432. if (hq->host_index != dq->host_index)
  433. return -EINVAL;
  434. /* If the host has not yet processed the next entry then we are done */
  435. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  436. return -EBUSY;
  437. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  438. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  439. /* Update the host index to point to the next slot */
  440. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  441. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  442. /* Ring The Header Receive Queue Doorbell */
  443. if (!(hq->host_index % hq->entry_repost)) {
  444. doorbell.word0 = 0;
  445. if (hq->db_format == LPFC_DB_RING_FORMAT) {
  446. bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
  447. hq->entry_repost);
  448. bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
  449. } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
  450. bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
  451. hq->entry_repost);
  452. bf_set(lpfc_rq_db_list_fm_index, &doorbell,
  453. hq->host_index);
  454. bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
  455. } else {
  456. return -EINVAL;
  457. }
  458. writel(doorbell.word0, hq->db_regaddr);
  459. }
  460. return put_index;
  461. }
  462. /**
  463. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  464. * @q: The Header Receive Queue to operate on.
  465. *
  466. * This routine will update the HBA index of a queue to reflect consumption of
  467. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  468. * consumed an entry the host calls this function to update the queue's
  469. * internal pointers. This routine returns the number of entries that were
  470. * consumed by the HBA.
  471. **/
  472. static uint32_t
  473. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  474. {
  475. /* sanity check on queue memory */
  476. if (unlikely(!hq) || unlikely(!dq))
  477. return 0;
  478. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  479. return 0;
  480. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  481. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  482. return 1;
  483. }
  484. /**
  485. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  486. * @phba: Pointer to HBA context object.
  487. * @pring: Pointer to driver SLI ring object.
  488. *
  489. * This function returns pointer to next command iocb entry
  490. * in the command ring. The caller must hold hbalock to prevent
  491. * other threads consume the next command iocb.
  492. * SLI-2/SLI-3 provide different sized iocbs.
  493. **/
  494. static inline IOCB_t *
  495. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  496. {
  497. return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
  498. pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
  499. }
  500. /**
  501. * lpfc_resp_iocb - Get next response iocb entry in the ring
  502. * @phba: Pointer to HBA context object.
  503. * @pring: Pointer to driver SLI ring object.
  504. *
  505. * This function returns pointer to next response iocb entry
  506. * in the response ring. The caller must hold hbalock to make sure
  507. * that no other thread consume the next response iocb.
  508. * SLI-2/SLI-3 provide different sized iocbs.
  509. **/
  510. static inline IOCB_t *
  511. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  512. {
  513. return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
  514. pring->sli.sli3.rspidx * phba->iocb_rsp_size);
  515. }
  516. /**
  517. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  518. * @phba: Pointer to HBA context object.
  519. *
  520. * This function is called with hbalock held. This function
  521. * allocates a new driver iocb object from the iocb pool. If the
  522. * allocation is successful, it returns pointer to the newly
  523. * allocated iocb object else it returns NULL.
  524. **/
  525. struct lpfc_iocbq *
  526. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  527. {
  528. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  529. struct lpfc_iocbq * iocbq = NULL;
  530. lockdep_assert_held(&phba->hbalock);
  531. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  532. if (iocbq)
  533. phba->iocb_cnt++;
  534. if (phba->iocb_cnt > phba->iocb_max)
  535. phba->iocb_max = phba->iocb_cnt;
  536. return iocbq;
  537. }
  538. /**
  539. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  540. * @phba: Pointer to HBA context object.
  541. * @xritag: XRI value.
  542. *
  543. * This function clears the sglq pointer from the array of acive
  544. * sglq's. The xritag that is passed in is used to index into the
  545. * array. Before the xritag can be used it needs to be adjusted
  546. * by subtracting the xribase.
  547. *
  548. * Returns sglq ponter = success, NULL = Failure.
  549. **/
  550. static struct lpfc_sglq *
  551. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  552. {
  553. struct lpfc_sglq *sglq;
  554. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  555. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  556. return sglq;
  557. }
  558. /**
  559. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  560. * @phba: Pointer to HBA context object.
  561. * @xritag: XRI value.
  562. *
  563. * This function returns the sglq pointer from the array of acive
  564. * sglq's. The xritag that is passed in is used to index into the
  565. * array. Before the xritag can be used it needs to be adjusted
  566. * by subtracting the xribase.
  567. *
  568. * Returns sglq ponter = success, NULL = Failure.
  569. **/
  570. struct lpfc_sglq *
  571. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  572. {
  573. struct lpfc_sglq *sglq;
  574. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  575. return sglq;
  576. }
  577. /**
  578. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  579. * @phba: Pointer to HBA context object.
  580. * @xritag: xri used in this exchange.
  581. * @rrq: The RRQ to be cleared.
  582. *
  583. **/
  584. void
  585. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  586. uint16_t xritag,
  587. struct lpfc_node_rrq *rrq)
  588. {
  589. struct lpfc_nodelist *ndlp = NULL;
  590. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  591. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  592. /* The target DID could have been swapped (cable swap)
  593. * we should use the ndlp from the findnode if it is
  594. * available.
  595. */
  596. if ((!ndlp) && rrq->ndlp)
  597. ndlp = rrq->ndlp;
  598. if (!ndlp)
  599. goto out;
  600. if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
  601. rrq->send_rrq = 0;
  602. rrq->xritag = 0;
  603. rrq->rrq_stop_time = 0;
  604. }
  605. out:
  606. mempool_free(rrq, phba->rrq_pool);
  607. }
  608. /**
  609. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  610. * @phba: Pointer to HBA context object.
  611. *
  612. * This function is called with hbalock held. This function
  613. * Checks if stop_time (ratov from setting rrq active) has
  614. * been reached, if it has and the send_rrq flag is set then
  615. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  616. * then it will just call the routine to clear the rrq and
  617. * free the rrq resource.
  618. * The timer is set to the next rrq that is going to expire before
  619. * leaving the routine.
  620. *
  621. **/
  622. void
  623. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  624. {
  625. struct lpfc_node_rrq *rrq;
  626. struct lpfc_node_rrq *nextrrq;
  627. unsigned long next_time;
  628. unsigned long iflags;
  629. LIST_HEAD(send_rrq);
  630. spin_lock_irqsave(&phba->hbalock, iflags);
  631. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  632. next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  633. list_for_each_entry_safe(rrq, nextrrq,
  634. &phba->active_rrq_list, list) {
  635. if (time_after(jiffies, rrq->rrq_stop_time))
  636. list_move(&rrq->list, &send_rrq);
  637. else if (time_before(rrq->rrq_stop_time, next_time))
  638. next_time = rrq->rrq_stop_time;
  639. }
  640. spin_unlock_irqrestore(&phba->hbalock, iflags);
  641. if ((!list_empty(&phba->active_rrq_list)) &&
  642. (!(phba->pport->load_flag & FC_UNLOADING)))
  643. mod_timer(&phba->rrq_tmr, next_time);
  644. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  645. list_del(&rrq->list);
  646. if (!rrq->send_rrq)
  647. /* this call will free the rrq */
  648. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  649. else if (lpfc_send_rrq(phba, rrq)) {
  650. /* if we send the rrq then the completion handler
  651. * will clear the bit in the xribitmap.
  652. */
  653. lpfc_clr_rrq_active(phba, rrq->xritag,
  654. rrq);
  655. }
  656. }
  657. }
  658. /**
  659. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  660. * @vport: Pointer to vport context object.
  661. * @xri: The xri used in the exchange.
  662. * @did: The targets DID for this exchange.
  663. *
  664. * returns NULL = rrq not found in the phba->active_rrq_list.
  665. * rrq = rrq for this xri and target.
  666. **/
  667. struct lpfc_node_rrq *
  668. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  669. {
  670. struct lpfc_hba *phba = vport->phba;
  671. struct lpfc_node_rrq *rrq;
  672. struct lpfc_node_rrq *nextrrq;
  673. unsigned long iflags;
  674. if (phba->sli_rev != LPFC_SLI_REV4)
  675. return NULL;
  676. spin_lock_irqsave(&phba->hbalock, iflags);
  677. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  678. if (rrq->vport == vport && rrq->xritag == xri &&
  679. rrq->nlp_DID == did){
  680. list_del(&rrq->list);
  681. spin_unlock_irqrestore(&phba->hbalock, iflags);
  682. return rrq;
  683. }
  684. }
  685. spin_unlock_irqrestore(&phba->hbalock, iflags);
  686. return NULL;
  687. }
  688. /**
  689. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  690. * @vport: Pointer to vport context object.
  691. * @ndlp: Pointer to the lpfc_node_list structure.
  692. * If ndlp is NULL Remove all active RRQs for this vport from the
  693. * phba->active_rrq_list and clear the rrq.
  694. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  695. **/
  696. void
  697. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  698. {
  699. struct lpfc_hba *phba = vport->phba;
  700. struct lpfc_node_rrq *rrq;
  701. struct lpfc_node_rrq *nextrrq;
  702. unsigned long iflags;
  703. LIST_HEAD(rrq_list);
  704. if (phba->sli_rev != LPFC_SLI_REV4)
  705. return;
  706. if (!ndlp) {
  707. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  708. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  709. }
  710. spin_lock_irqsave(&phba->hbalock, iflags);
  711. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  712. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  713. list_move(&rrq->list, &rrq_list);
  714. spin_unlock_irqrestore(&phba->hbalock, iflags);
  715. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  716. list_del(&rrq->list);
  717. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  718. }
  719. }
  720. /**
  721. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  722. * @phba: Pointer to HBA context object.
  723. * @ndlp: Targets nodelist pointer for this exchange.
  724. * @xritag the xri in the bitmap to test.
  725. *
  726. * This function is called with hbalock held. This function
  727. * returns 0 = rrq not active for this xri
  728. * 1 = rrq is valid for this xri.
  729. **/
  730. int
  731. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  732. uint16_t xritag)
  733. {
  734. lockdep_assert_held(&phba->hbalock);
  735. if (!ndlp)
  736. return 0;
  737. if (!ndlp->active_rrqs_xri_bitmap)
  738. return 0;
  739. if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
  740. return 1;
  741. else
  742. return 0;
  743. }
  744. /**
  745. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  746. * @phba: Pointer to HBA context object.
  747. * @ndlp: nodelist pointer for this target.
  748. * @xritag: xri used in this exchange.
  749. * @rxid: Remote Exchange ID.
  750. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  751. *
  752. * This function takes the hbalock.
  753. * The active bit is always set in the active rrq xri_bitmap even
  754. * if there is no slot avaiable for the other rrq information.
  755. *
  756. * returns 0 rrq actived for this xri
  757. * < 0 No memory or invalid ndlp.
  758. **/
  759. int
  760. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  761. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  762. {
  763. unsigned long iflags;
  764. struct lpfc_node_rrq *rrq;
  765. int empty;
  766. if (!ndlp)
  767. return -EINVAL;
  768. if (!phba->cfg_enable_rrq)
  769. return -EINVAL;
  770. spin_lock_irqsave(&phba->hbalock, iflags);
  771. if (phba->pport->load_flag & FC_UNLOADING) {
  772. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  773. goto out;
  774. }
  775. /*
  776. * set the active bit even if there is no mem available.
  777. */
  778. if (NLP_CHK_FREE_REQ(ndlp))
  779. goto out;
  780. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  781. goto out;
  782. if (!ndlp->active_rrqs_xri_bitmap)
  783. goto out;
  784. if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
  785. goto out;
  786. spin_unlock_irqrestore(&phba->hbalock, iflags);
  787. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  788. if (!rrq) {
  789. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  790. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  791. " DID:0x%x Send:%d\n",
  792. xritag, rxid, ndlp->nlp_DID, send_rrq);
  793. return -EINVAL;
  794. }
  795. if (phba->cfg_enable_rrq == 1)
  796. rrq->send_rrq = send_rrq;
  797. else
  798. rrq->send_rrq = 0;
  799. rrq->xritag = xritag;
  800. rrq->rrq_stop_time = jiffies +
  801. msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  802. rrq->ndlp = ndlp;
  803. rrq->nlp_DID = ndlp->nlp_DID;
  804. rrq->vport = ndlp->vport;
  805. rrq->rxid = rxid;
  806. spin_lock_irqsave(&phba->hbalock, iflags);
  807. empty = list_empty(&phba->active_rrq_list);
  808. list_add_tail(&rrq->list, &phba->active_rrq_list);
  809. phba->hba_flag |= HBA_RRQ_ACTIVE;
  810. if (empty)
  811. lpfc_worker_wake_up(phba);
  812. spin_unlock_irqrestore(&phba->hbalock, iflags);
  813. return 0;
  814. out:
  815. spin_unlock_irqrestore(&phba->hbalock, iflags);
  816. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  817. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  818. " DID:0x%x Send:%d\n",
  819. xritag, rxid, ndlp->nlp_DID, send_rrq);
  820. return -EINVAL;
  821. }
  822. /**
  823. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  824. * @phba: Pointer to HBA context object.
  825. * @piocb: Pointer to the iocbq.
  826. *
  827. * This function is called with the ring lock held. This function
  828. * gets a new driver sglq object from the sglq list. If the
  829. * list is not empty then it is successful, it returns pointer to the newly
  830. * allocated sglq object else it returns NULL.
  831. **/
  832. static struct lpfc_sglq *
  833. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  834. {
  835. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  836. struct lpfc_sglq *sglq = NULL;
  837. struct lpfc_sglq *start_sglq = NULL;
  838. struct lpfc_scsi_buf *lpfc_cmd;
  839. struct lpfc_nodelist *ndlp;
  840. int found = 0;
  841. lockdep_assert_held(&phba->hbalock);
  842. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  843. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  844. ndlp = lpfc_cmd->rdata->pnode;
  845. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  846. !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  847. ndlp = piocbq->context_un.ndlp;
  848. } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) {
  849. if (piocbq->iocb_flag & LPFC_IO_LOOPBACK)
  850. ndlp = NULL;
  851. else
  852. ndlp = piocbq->context_un.ndlp;
  853. } else {
  854. ndlp = piocbq->context1;
  855. }
  856. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  857. start_sglq = sglq;
  858. while (!found) {
  859. if (!sglq)
  860. return NULL;
  861. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
  862. /* This xri has an rrq outstanding for this DID.
  863. * put it back in the list and get another xri.
  864. */
  865. list_add_tail(&sglq->list, lpfc_sgl_list);
  866. sglq = NULL;
  867. list_remove_head(lpfc_sgl_list, sglq,
  868. struct lpfc_sglq, list);
  869. if (sglq == start_sglq) {
  870. sglq = NULL;
  871. break;
  872. } else
  873. continue;
  874. }
  875. sglq->ndlp = ndlp;
  876. found = 1;
  877. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  878. sglq->state = SGL_ALLOCATED;
  879. }
  880. return sglq;
  881. }
  882. /**
  883. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  884. * @phba: Pointer to HBA context object.
  885. *
  886. * This function is called with no lock held. This function
  887. * allocates a new driver iocb object from the iocb pool. If the
  888. * allocation is successful, it returns pointer to the newly
  889. * allocated iocb object else it returns NULL.
  890. **/
  891. struct lpfc_iocbq *
  892. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  893. {
  894. struct lpfc_iocbq * iocbq = NULL;
  895. unsigned long iflags;
  896. spin_lock_irqsave(&phba->hbalock, iflags);
  897. iocbq = __lpfc_sli_get_iocbq(phba);
  898. spin_unlock_irqrestore(&phba->hbalock, iflags);
  899. return iocbq;
  900. }
  901. /**
  902. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  903. * @phba: Pointer to HBA context object.
  904. * @iocbq: Pointer to driver iocb object.
  905. *
  906. * This function is called with hbalock held to release driver
  907. * iocb object to the iocb pool. The iotag in the iocb object
  908. * does not change for each use of the iocb object. This function
  909. * clears all other fields of the iocb object when it is freed.
  910. * The sqlq structure that holds the xritag and phys and virtual
  911. * mappings for the scatter gather list is retrieved from the
  912. * active array of sglq. The get of the sglq pointer also clears
  913. * the entry in the array. If the status of the IO indiactes that
  914. * this IO was aborted then the sglq entry it put on the
  915. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  916. * IO has good status or fails for any other reason then the sglq
  917. * entry is added to the free list (lpfc_sgl_list).
  918. **/
  919. static void
  920. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  921. {
  922. struct lpfc_sglq *sglq;
  923. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  924. unsigned long iflag = 0;
  925. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  926. lockdep_assert_held(&phba->hbalock);
  927. if (iocbq->sli4_xritag == NO_XRI)
  928. sglq = NULL;
  929. else
  930. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  931. if (sglq) {
  932. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  933. (sglq->state != SGL_XRI_ABORTED)) {
  934. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  935. iflag);
  936. list_add(&sglq->list,
  937. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  938. spin_unlock_irqrestore(
  939. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  940. } else {
  941. spin_lock_irqsave(&pring->ring_lock, iflag);
  942. sglq->state = SGL_FREED;
  943. sglq->ndlp = NULL;
  944. list_add_tail(&sglq->list,
  945. &phba->sli4_hba.lpfc_sgl_list);
  946. spin_unlock_irqrestore(&pring->ring_lock, iflag);
  947. /* Check if TXQ queue needs to be serviced */
  948. if (!list_empty(&pring->txq))
  949. lpfc_worker_wake_up(phba);
  950. }
  951. }
  952. /*
  953. * Clean all volatile data fields, preserve iotag and node struct.
  954. */
  955. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  956. iocbq->sli4_lxritag = NO_XRI;
  957. iocbq->sli4_xritag = NO_XRI;
  958. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  959. }
  960. /**
  961. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  962. * @phba: Pointer to HBA context object.
  963. * @iocbq: Pointer to driver iocb object.
  964. *
  965. * This function is called with hbalock held to release driver
  966. * iocb object to the iocb pool. The iotag in the iocb object
  967. * does not change for each use of the iocb object. This function
  968. * clears all other fields of the iocb object when it is freed.
  969. **/
  970. static void
  971. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  972. {
  973. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  974. lockdep_assert_held(&phba->hbalock);
  975. /*
  976. * Clean all volatile data fields, preserve iotag and node struct.
  977. */
  978. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  979. iocbq->sli4_xritag = NO_XRI;
  980. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  981. }
  982. /**
  983. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  984. * @phba: Pointer to HBA context object.
  985. * @iocbq: Pointer to driver iocb object.
  986. *
  987. * This function is called with hbalock held to release driver
  988. * iocb object to the iocb pool. The iotag in the iocb object
  989. * does not change for each use of the iocb object. This function
  990. * clears all other fields of the iocb object when it is freed.
  991. **/
  992. static void
  993. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  994. {
  995. lockdep_assert_held(&phba->hbalock);
  996. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  997. phba->iocb_cnt--;
  998. }
  999. /**
  1000. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  1001. * @phba: Pointer to HBA context object.
  1002. * @iocbq: Pointer to driver iocb object.
  1003. *
  1004. * This function is called with no lock held to release the iocb to
  1005. * iocb pool.
  1006. **/
  1007. void
  1008. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1009. {
  1010. unsigned long iflags;
  1011. /*
  1012. * Clean all volatile data fields, preserve iotag and node struct.
  1013. */
  1014. spin_lock_irqsave(&phba->hbalock, iflags);
  1015. __lpfc_sli_release_iocbq(phba, iocbq);
  1016. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1017. }
  1018. /**
  1019. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  1020. * @phba: Pointer to HBA context object.
  1021. * @iocblist: List of IOCBs.
  1022. * @ulpstatus: ULP status in IOCB command field.
  1023. * @ulpWord4: ULP word-4 in IOCB command field.
  1024. *
  1025. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  1026. * on the list by invoking the complete callback function associated with the
  1027. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  1028. * fields.
  1029. **/
  1030. void
  1031. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  1032. uint32_t ulpstatus, uint32_t ulpWord4)
  1033. {
  1034. struct lpfc_iocbq *piocb;
  1035. while (!list_empty(iocblist)) {
  1036. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  1037. if (!piocb->iocb_cmpl)
  1038. lpfc_sli_release_iocbq(phba, piocb);
  1039. else {
  1040. piocb->iocb.ulpStatus = ulpstatus;
  1041. piocb->iocb.un.ulpWord[4] = ulpWord4;
  1042. (piocb->iocb_cmpl) (phba, piocb, piocb);
  1043. }
  1044. }
  1045. return;
  1046. }
  1047. /**
  1048. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1049. * @iocb_cmnd: iocb command code.
  1050. *
  1051. * This function is called by ring event handler function to get the iocb type.
  1052. * This function translates the iocb command to an iocb command type used to
  1053. * decide the final disposition of each completed IOCB.
  1054. * The function returns
  1055. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1056. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1057. * LPFC_ABORT_IOCB if it is an abort iocb
  1058. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1059. *
  1060. * The caller is not required to hold any lock.
  1061. **/
  1062. static lpfc_iocb_type
  1063. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1064. {
  1065. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1066. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1067. return 0;
  1068. switch (iocb_cmnd) {
  1069. case CMD_XMIT_SEQUENCE_CR:
  1070. case CMD_XMIT_SEQUENCE_CX:
  1071. case CMD_XMIT_BCAST_CN:
  1072. case CMD_XMIT_BCAST_CX:
  1073. case CMD_ELS_REQUEST_CR:
  1074. case CMD_ELS_REQUEST_CX:
  1075. case CMD_CREATE_XRI_CR:
  1076. case CMD_CREATE_XRI_CX:
  1077. case CMD_GET_RPI_CN:
  1078. case CMD_XMIT_ELS_RSP_CX:
  1079. case CMD_GET_RPI_CR:
  1080. case CMD_FCP_IWRITE_CR:
  1081. case CMD_FCP_IWRITE_CX:
  1082. case CMD_FCP_IREAD_CR:
  1083. case CMD_FCP_IREAD_CX:
  1084. case CMD_FCP_ICMND_CR:
  1085. case CMD_FCP_ICMND_CX:
  1086. case CMD_FCP_TSEND_CX:
  1087. case CMD_FCP_TRSP_CX:
  1088. case CMD_FCP_TRECEIVE_CX:
  1089. case CMD_FCP_AUTO_TRSP_CX:
  1090. case CMD_ADAPTER_MSG:
  1091. case CMD_ADAPTER_DUMP:
  1092. case CMD_XMIT_SEQUENCE64_CR:
  1093. case CMD_XMIT_SEQUENCE64_CX:
  1094. case CMD_XMIT_BCAST64_CN:
  1095. case CMD_XMIT_BCAST64_CX:
  1096. case CMD_ELS_REQUEST64_CR:
  1097. case CMD_ELS_REQUEST64_CX:
  1098. case CMD_FCP_IWRITE64_CR:
  1099. case CMD_FCP_IWRITE64_CX:
  1100. case CMD_FCP_IREAD64_CR:
  1101. case CMD_FCP_IREAD64_CX:
  1102. case CMD_FCP_ICMND64_CR:
  1103. case CMD_FCP_ICMND64_CX:
  1104. case CMD_FCP_TSEND64_CX:
  1105. case CMD_FCP_TRSP64_CX:
  1106. case CMD_FCP_TRECEIVE64_CX:
  1107. case CMD_GEN_REQUEST64_CR:
  1108. case CMD_GEN_REQUEST64_CX:
  1109. case CMD_XMIT_ELS_RSP64_CX:
  1110. case DSSCMD_IWRITE64_CR:
  1111. case DSSCMD_IWRITE64_CX:
  1112. case DSSCMD_IREAD64_CR:
  1113. case DSSCMD_IREAD64_CX:
  1114. type = LPFC_SOL_IOCB;
  1115. break;
  1116. case CMD_ABORT_XRI_CN:
  1117. case CMD_ABORT_XRI_CX:
  1118. case CMD_CLOSE_XRI_CN:
  1119. case CMD_CLOSE_XRI_CX:
  1120. case CMD_XRI_ABORTED_CX:
  1121. case CMD_ABORT_MXRI64_CN:
  1122. case CMD_XMIT_BLS_RSP64_CX:
  1123. type = LPFC_ABORT_IOCB;
  1124. break;
  1125. case CMD_RCV_SEQUENCE_CX:
  1126. case CMD_RCV_ELS_REQ_CX:
  1127. case CMD_RCV_SEQUENCE64_CX:
  1128. case CMD_RCV_ELS_REQ64_CX:
  1129. case CMD_ASYNC_STATUS:
  1130. case CMD_IOCB_RCV_SEQ64_CX:
  1131. case CMD_IOCB_RCV_ELS64_CX:
  1132. case CMD_IOCB_RCV_CONT64_CX:
  1133. case CMD_IOCB_RET_XRI64_CX:
  1134. type = LPFC_UNSOL_IOCB;
  1135. break;
  1136. case CMD_IOCB_XMIT_MSEQ64_CR:
  1137. case CMD_IOCB_XMIT_MSEQ64_CX:
  1138. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1139. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1140. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1141. case CMD_IOCB_ABORT_EXTENDED_CN:
  1142. case CMD_IOCB_RET_HBQE64_CN:
  1143. case CMD_IOCB_FCP_IBIDIR64_CR:
  1144. case CMD_IOCB_FCP_IBIDIR64_CX:
  1145. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1146. case CMD_IOCB_LOGENTRY_CN:
  1147. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1148. printk("%s - Unhandled SLI-3 Command x%x\n",
  1149. __func__, iocb_cmnd);
  1150. type = LPFC_UNKNOWN_IOCB;
  1151. break;
  1152. default:
  1153. type = LPFC_UNKNOWN_IOCB;
  1154. break;
  1155. }
  1156. return type;
  1157. }
  1158. /**
  1159. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1160. * @phba: Pointer to HBA context object.
  1161. *
  1162. * This function is called from SLI initialization code
  1163. * to configure every ring of the HBA's SLI interface. The
  1164. * caller is not required to hold any lock. This function issues
  1165. * a config_ring mailbox command for each ring.
  1166. * This function returns zero if successful else returns a negative
  1167. * error code.
  1168. **/
  1169. static int
  1170. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1171. {
  1172. struct lpfc_sli *psli = &phba->sli;
  1173. LPFC_MBOXQ_t *pmb;
  1174. MAILBOX_t *pmbox;
  1175. int i, rc, ret = 0;
  1176. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1177. if (!pmb)
  1178. return -ENOMEM;
  1179. pmbox = &pmb->u.mb;
  1180. phba->link_state = LPFC_INIT_MBX_CMDS;
  1181. for (i = 0; i < psli->num_rings; i++) {
  1182. lpfc_config_ring(phba, i, pmb);
  1183. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1184. if (rc != MBX_SUCCESS) {
  1185. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1186. "0446 Adapter failed to init (%d), "
  1187. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1188. "ring %d\n",
  1189. rc, pmbox->mbxCommand,
  1190. pmbox->mbxStatus, i);
  1191. phba->link_state = LPFC_HBA_ERROR;
  1192. ret = -ENXIO;
  1193. break;
  1194. }
  1195. }
  1196. mempool_free(pmb, phba->mbox_mem_pool);
  1197. return ret;
  1198. }
  1199. /**
  1200. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1201. * @phba: Pointer to HBA context object.
  1202. * @pring: Pointer to driver SLI ring object.
  1203. * @piocb: Pointer to the driver iocb object.
  1204. *
  1205. * This function is called with hbalock held. The function adds the
  1206. * new iocb to txcmplq of the given ring. This function always returns
  1207. * 0. If this function is called for ELS ring, this function checks if
  1208. * there is a vport associated with the ELS command. This function also
  1209. * starts els_tmofunc timer if this is an ELS command.
  1210. **/
  1211. static int
  1212. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1213. struct lpfc_iocbq *piocb)
  1214. {
  1215. lockdep_assert_held(&phba->hbalock);
  1216. BUG_ON(!piocb);
  1217. list_add_tail(&piocb->list, &pring->txcmplq);
  1218. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1219. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1220. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1221. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1222. BUG_ON(!piocb->vport);
  1223. if (!(piocb->vport->load_flag & FC_UNLOADING))
  1224. mod_timer(&piocb->vport->els_tmofunc,
  1225. jiffies +
  1226. msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
  1227. }
  1228. return 0;
  1229. }
  1230. /**
  1231. * lpfc_sli_ringtx_get - Get first element of the txq
  1232. * @phba: Pointer to HBA context object.
  1233. * @pring: Pointer to driver SLI ring object.
  1234. *
  1235. * This function is called with hbalock held to get next
  1236. * iocb in txq of the given ring. If there is any iocb in
  1237. * the txq, the function returns first iocb in the list after
  1238. * removing the iocb from the list, else it returns NULL.
  1239. **/
  1240. struct lpfc_iocbq *
  1241. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1242. {
  1243. struct lpfc_iocbq *cmd_iocb;
  1244. lockdep_assert_held(&phba->hbalock);
  1245. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1246. return cmd_iocb;
  1247. }
  1248. /**
  1249. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1250. * @phba: Pointer to HBA context object.
  1251. * @pring: Pointer to driver SLI ring object.
  1252. *
  1253. * This function is called with hbalock held and the caller must post the
  1254. * iocb without releasing the lock. If the caller releases the lock,
  1255. * iocb slot returned by the function is not guaranteed to be available.
  1256. * The function returns pointer to the next available iocb slot if there
  1257. * is available slot in the ring, else it returns NULL.
  1258. * If the get index of the ring is ahead of the put index, the function
  1259. * will post an error attention event to the worker thread to take the
  1260. * HBA to offline state.
  1261. **/
  1262. static IOCB_t *
  1263. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1264. {
  1265. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1266. uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
  1267. lockdep_assert_held(&phba->hbalock);
  1268. if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
  1269. (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
  1270. pring->sli.sli3.next_cmdidx = 0;
  1271. if (unlikely(pring->sli.sli3.local_getidx ==
  1272. pring->sli.sli3.next_cmdidx)) {
  1273. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1274. if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
  1275. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1276. "0315 Ring %d issue: portCmdGet %d "
  1277. "is bigger than cmd ring %d\n",
  1278. pring->ringno,
  1279. pring->sli.sli3.local_getidx,
  1280. max_cmd_idx);
  1281. phba->link_state = LPFC_HBA_ERROR;
  1282. /*
  1283. * All error attention handlers are posted to
  1284. * worker thread
  1285. */
  1286. phba->work_ha |= HA_ERATT;
  1287. phba->work_hs = HS_FFER3;
  1288. lpfc_worker_wake_up(phba);
  1289. return NULL;
  1290. }
  1291. if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
  1292. return NULL;
  1293. }
  1294. return lpfc_cmd_iocb(phba, pring);
  1295. }
  1296. /**
  1297. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1298. * @phba: Pointer to HBA context object.
  1299. * @iocbq: Pointer to driver iocb object.
  1300. *
  1301. * This function gets an iotag for the iocb. If there is no unused iotag and
  1302. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1303. * array and assigns a new iotag.
  1304. * The function returns the allocated iotag if successful, else returns zero.
  1305. * Zero is not a valid iotag.
  1306. * The caller is not required to hold any lock.
  1307. **/
  1308. uint16_t
  1309. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1310. {
  1311. struct lpfc_iocbq **new_arr;
  1312. struct lpfc_iocbq **old_arr;
  1313. size_t new_len;
  1314. struct lpfc_sli *psli = &phba->sli;
  1315. uint16_t iotag;
  1316. spin_lock_irq(&phba->hbalock);
  1317. iotag = psli->last_iotag;
  1318. if(++iotag < psli->iocbq_lookup_len) {
  1319. psli->last_iotag = iotag;
  1320. psli->iocbq_lookup[iotag] = iocbq;
  1321. spin_unlock_irq(&phba->hbalock);
  1322. iocbq->iotag = iotag;
  1323. return iotag;
  1324. } else if (psli->iocbq_lookup_len < (0xffff
  1325. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1326. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1327. spin_unlock_irq(&phba->hbalock);
  1328. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1329. GFP_KERNEL);
  1330. if (new_arr) {
  1331. spin_lock_irq(&phba->hbalock);
  1332. old_arr = psli->iocbq_lookup;
  1333. if (new_len <= psli->iocbq_lookup_len) {
  1334. /* highly unprobable case */
  1335. kfree(new_arr);
  1336. iotag = psli->last_iotag;
  1337. if(++iotag < psli->iocbq_lookup_len) {
  1338. psli->last_iotag = iotag;
  1339. psli->iocbq_lookup[iotag] = iocbq;
  1340. spin_unlock_irq(&phba->hbalock);
  1341. iocbq->iotag = iotag;
  1342. return iotag;
  1343. }
  1344. spin_unlock_irq(&phba->hbalock);
  1345. return 0;
  1346. }
  1347. if (psli->iocbq_lookup)
  1348. memcpy(new_arr, old_arr,
  1349. ((psli->last_iotag + 1) *
  1350. sizeof (struct lpfc_iocbq *)));
  1351. psli->iocbq_lookup = new_arr;
  1352. psli->iocbq_lookup_len = new_len;
  1353. psli->last_iotag = iotag;
  1354. psli->iocbq_lookup[iotag] = iocbq;
  1355. spin_unlock_irq(&phba->hbalock);
  1356. iocbq->iotag = iotag;
  1357. kfree(old_arr);
  1358. return iotag;
  1359. }
  1360. } else
  1361. spin_unlock_irq(&phba->hbalock);
  1362. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1363. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1364. psli->last_iotag);
  1365. return 0;
  1366. }
  1367. /**
  1368. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1369. * @phba: Pointer to HBA context object.
  1370. * @pring: Pointer to driver SLI ring object.
  1371. * @iocb: Pointer to iocb slot in the ring.
  1372. * @nextiocb: Pointer to driver iocb object which need to be
  1373. * posted to firmware.
  1374. *
  1375. * This function is called with hbalock held to post a new iocb to
  1376. * the firmware. This function copies the new iocb to ring iocb slot and
  1377. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1378. * a completion call back for this iocb else the function will free the
  1379. * iocb object.
  1380. **/
  1381. static void
  1382. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1383. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1384. {
  1385. lockdep_assert_held(&phba->hbalock);
  1386. /*
  1387. * Set up an iotag
  1388. */
  1389. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1390. if (pring->ringno == LPFC_ELS_RING) {
  1391. lpfc_debugfs_slow_ring_trc(phba,
  1392. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1393. *(((uint32_t *) &nextiocb->iocb) + 4),
  1394. *(((uint32_t *) &nextiocb->iocb) + 6),
  1395. *(((uint32_t *) &nextiocb->iocb) + 7));
  1396. }
  1397. /*
  1398. * Issue iocb command to adapter
  1399. */
  1400. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1401. wmb();
  1402. pring->stats.iocb_cmd++;
  1403. /*
  1404. * If there is no completion routine to call, we can release the
  1405. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1406. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1407. */
  1408. if (nextiocb->iocb_cmpl)
  1409. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1410. else
  1411. __lpfc_sli_release_iocbq(phba, nextiocb);
  1412. /*
  1413. * Let the HBA know what IOCB slot will be the next one the
  1414. * driver will put a command into.
  1415. */
  1416. pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
  1417. writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1418. }
  1419. /**
  1420. * lpfc_sli_update_full_ring - Update the chip attention register
  1421. * @phba: Pointer to HBA context object.
  1422. * @pring: Pointer to driver SLI ring object.
  1423. *
  1424. * The caller is not required to hold any lock for calling this function.
  1425. * This function updates the chip attention bits for the ring to inform firmware
  1426. * that there are pending work to be done for this ring and requests an
  1427. * interrupt when there is space available in the ring. This function is
  1428. * called when the driver is unable to post more iocbs to the ring due
  1429. * to unavailability of space in the ring.
  1430. **/
  1431. static void
  1432. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1433. {
  1434. int ringno = pring->ringno;
  1435. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1436. wmb();
  1437. /*
  1438. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1439. * The HBA will tell us when an IOCB entry is available.
  1440. */
  1441. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1442. readl(phba->CAregaddr); /* flush */
  1443. pring->stats.iocb_cmd_full++;
  1444. }
  1445. /**
  1446. * lpfc_sli_update_ring - Update chip attention register
  1447. * @phba: Pointer to HBA context object.
  1448. * @pring: Pointer to driver SLI ring object.
  1449. *
  1450. * This function updates the chip attention register bit for the
  1451. * given ring to inform HBA that there is more work to be done
  1452. * in this ring. The caller is not required to hold any lock.
  1453. **/
  1454. static void
  1455. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1456. {
  1457. int ringno = pring->ringno;
  1458. /*
  1459. * Tell the HBA that there is work to do in this ring.
  1460. */
  1461. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1462. wmb();
  1463. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1464. readl(phba->CAregaddr); /* flush */
  1465. }
  1466. }
  1467. /**
  1468. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1469. * @phba: Pointer to HBA context object.
  1470. * @pring: Pointer to driver SLI ring object.
  1471. *
  1472. * This function is called with hbalock held to post pending iocbs
  1473. * in the txq to the firmware. This function is called when driver
  1474. * detects space available in the ring.
  1475. **/
  1476. static void
  1477. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1478. {
  1479. IOCB_t *iocb;
  1480. struct lpfc_iocbq *nextiocb;
  1481. lockdep_assert_held(&phba->hbalock);
  1482. /*
  1483. * Check to see if:
  1484. * (a) there is anything on the txq to send
  1485. * (b) link is up
  1486. * (c) link attention events can be processed (fcp ring only)
  1487. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1488. */
  1489. if (lpfc_is_link_up(phba) &&
  1490. (!list_empty(&pring->txq)) &&
  1491. (pring->ringno != phba->sli.fcp_ring ||
  1492. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1493. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1494. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1495. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1496. if (iocb)
  1497. lpfc_sli_update_ring(phba, pring);
  1498. else
  1499. lpfc_sli_update_full_ring(phba, pring);
  1500. }
  1501. return;
  1502. }
  1503. /**
  1504. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1505. * @phba: Pointer to HBA context object.
  1506. * @hbqno: HBQ number.
  1507. *
  1508. * This function is called with hbalock held to get the next
  1509. * available slot for the given HBQ. If there is free slot
  1510. * available for the HBQ it will return pointer to the next available
  1511. * HBQ entry else it will return NULL.
  1512. **/
  1513. static struct lpfc_hbq_entry *
  1514. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1515. {
  1516. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1517. lockdep_assert_held(&phba->hbalock);
  1518. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1519. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1520. hbqp->next_hbqPutIdx = 0;
  1521. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1522. uint32_t raw_index = phba->hbq_get[hbqno];
  1523. uint32_t getidx = le32_to_cpu(raw_index);
  1524. hbqp->local_hbqGetIdx = getidx;
  1525. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1526. lpfc_printf_log(phba, KERN_ERR,
  1527. LOG_SLI | LOG_VPORT,
  1528. "1802 HBQ %d: local_hbqGetIdx "
  1529. "%u is > than hbqp->entry_count %u\n",
  1530. hbqno, hbqp->local_hbqGetIdx,
  1531. hbqp->entry_count);
  1532. phba->link_state = LPFC_HBA_ERROR;
  1533. return NULL;
  1534. }
  1535. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1536. return NULL;
  1537. }
  1538. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1539. hbqp->hbqPutIdx;
  1540. }
  1541. /**
  1542. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1543. * @phba: Pointer to HBA context object.
  1544. *
  1545. * This function is called with no lock held to free all the
  1546. * hbq buffers while uninitializing the SLI interface. It also
  1547. * frees the HBQ buffers returned by the firmware but not yet
  1548. * processed by the upper layers.
  1549. **/
  1550. void
  1551. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1552. {
  1553. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1554. struct hbq_dmabuf *hbq_buf;
  1555. unsigned long flags;
  1556. int i, hbq_count;
  1557. uint32_t hbqno;
  1558. hbq_count = lpfc_sli_hbq_count();
  1559. /* Return all memory used by all HBQs */
  1560. spin_lock_irqsave(&phba->hbalock, flags);
  1561. for (i = 0; i < hbq_count; ++i) {
  1562. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1563. &phba->hbqs[i].hbq_buffer_list, list) {
  1564. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1565. list_del(&hbq_buf->dbuf.list);
  1566. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1567. }
  1568. phba->hbqs[i].buffer_count = 0;
  1569. }
  1570. /* Return all HBQ buffer that are in-fly */
  1571. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1572. list) {
  1573. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1574. list_del(&hbq_buf->dbuf.list);
  1575. if (hbq_buf->tag == -1) {
  1576. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1577. (phba, hbq_buf);
  1578. } else {
  1579. hbqno = hbq_buf->tag >> 16;
  1580. if (hbqno >= LPFC_MAX_HBQS)
  1581. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1582. (phba, hbq_buf);
  1583. else
  1584. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1585. hbq_buf);
  1586. }
  1587. }
  1588. /* Mark the HBQs not in use */
  1589. phba->hbq_in_use = 0;
  1590. spin_unlock_irqrestore(&phba->hbalock, flags);
  1591. }
  1592. /**
  1593. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1594. * @phba: Pointer to HBA context object.
  1595. * @hbqno: HBQ number.
  1596. * @hbq_buf: Pointer to HBQ buffer.
  1597. *
  1598. * This function is called with the hbalock held to post a
  1599. * hbq buffer to the firmware. If the function finds an empty
  1600. * slot in the HBQ, it will post the buffer. The function will return
  1601. * pointer to the hbq entry if it successfully post the buffer
  1602. * else it will return NULL.
  1603. **/
  1604. static int
  1605. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1606. struct hbq_dmabuf *hbq_buf)
  1607. {
  1608. lockdep_assert_held(&phba->hbalock);
  1609. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1610. }
  1611. /**
  1612. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1613. * @phba: Pointer to HBA context object.
  1614. * @hbqno: HBQ number.
  1615. * @hbq_buf: Pointer to HBQ buffer.
  1616. *
  1617. * This function is called with the hbalock held to post a hbq buffer to the
  1618. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1619. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1620. * it successfully post the buffer else it will return an error.
  1621. **/
  1622. static int
  1623. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1624. struct hbq_dmabuf *hbq_buf)
  1625. {
  1626. struct lpfc_hbq_entry *hbqe;
  1627. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1628. lockdep_assert_held(&phba->hbalock);
  1629. /* Get next HBQ entry slot to use */
  1630. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1631. if (hbqe) {
  1632. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1633. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1634. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1635. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1636. hbqe->bde.tus.f.bdeFlags = 0;
  1637. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1638. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1639. /* Sync SLIM */
  1640. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1641. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1642. /* flush */
  1643. readl(phba->hbq_put + hbqno);
  1644. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1645. return 0;
  1646. } else
  1647. return -ENOMEM;
  1648. }
  1649. /**
  1650. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1651. * @phba: Pointer to HBA context object.
  1652. * @hbqno: HBQ number.
  1653. * @hbq_buf: Pointer to HBQ buffer.
  1654. *
  1655. * This function is called with the hbalock held to post an RQE to the SLI4
  1656. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1657. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1658. **/
  1659. static int
  1660. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1661. struct hbq_dmabuf *hbq_buf)
  1662. {
  1663. int rc;
  1664. struct lpfc_rqe hrqe;
  1665. struct lpfc_rqe drqe;
  1666. lockdep_assert_held(&phba->hbalock);
  1667. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1668. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1669. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1670. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1671. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1672. &hrqe, &drqe);
  1673. if (rc < 0)
  1674. return rc;
  1675. hbq_buf->tag = rc;
  1676. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1677. return 0;
  1678. }
  1679. /* HBQ for ELS and CT traffic. */
  1680. static struct lpfc_hbq_init lpfc_els_hbq = {
  1681. .rn = 1,
  1682. .entry_count = 256,
  1683. .mask_count = 0,
  1684. .profile = 0,
  1685. .ring_mask = (1 << LPFC_ELS_RING),
  1686. .buffer_count = 0,
  1687. .init_count = 40,
  1688. .add_count = 40,
  1689. };
  1690. /* HBQ for the extra ring if needed */
  1691. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1692. .rn = 1,
  1693. .entry_count = 200,
  1694. .mask_count = 0,
  1695. .profile = 0,
  1696. .ring_mask = (1 << LPFC_EXTRA_RING),
  1697. .buffer_count = 0,
  1698. .init_count = 0,
  1699. .add_count = 5,
  1700. };
  1701. /* Array of HBQs */
  1702. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1703. &lpfc_els_hbq,
  1704. &lpfc_extra_hbq,
  1705. };
  1706. /**
  1707. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1708. * @phba: Pointer to HBA context object.
  1709. * @hbqno: HBQ number.
  1710. * @count: Number of HBQ buffers to be posted.
  1711. *
  1712. * This function is called with no lock held to post more hbq buffers to the
  1713. * given HBQ. The function returns the number of HBQ buffers successfully
  1714. * posted.
  1715. **/
  1716. static int
  1717. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1718. {
  1719. uint32_t i, posted = 0;
  1720. unsigned long flags;
  1721. struct hbq_dmabuf *hbq_buffer;
  1722. LIST_HEAD(hbq_buf_list);
  1723. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1724. return 0;
  1725. if ((phba->hbqs[hbqno].buffer_count + count) >
  1726. lpfc_hbq_defs[hbqno]->entry_count)
  1727. count = lpfc_hbq_defs[hbqno]->entry_count -
  1728. phba->hbqs[hbqno].buffer_count;
  1729. if (!count)
  1730. return 0;
  1731. /* Allocate HBQ entries */
  1732. for (i = 0; i < count; i++) {
  1733. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1734. if (!hbq_buffer)
  1735. break;
  1736. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1737. }
  1738. /* Check whether HBQ is still in use */
  1739. spin_lock_irqsave(&phba->hbalock, flags);
  1740. if (!phba->hbq_in_use)
  1741. goto err;
  1742. while (!list_empty(&hbq_buf_list)) {
  1743. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1744. dbuf.list);
  1745. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1746. (hbqno << 16));
  1747. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1748. phba->hbqs[hbqno].buffer_count++;
  1749. posted++;
  1750. } else
  1751. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1752. }
  1753. spin_unlock_irqrestore(&phba->hbalock, flags);
  1754. return posted;
  1755. err:
  1756. spin_unlock_irqrestore(&phba->hbalock, flags);
  1757. while (!list_empty(&hbq_buf_list)) {
  1758. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1759. dbuf.list);
  1760. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1761. }
  1762. return 0;
  1763. }
  1764. /**
  1765. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1766. * @phba: Pointer to HBA context object.
  1767. * @qno: HBQ number.
  1768. *
  1769. * This function posts more buffers to the HBQ. This function
  1770. * is called with no lock held. The function returns the number of HBQ entries
  1771. * successfully allocated.
  1772. **/
  1773. int
  1774. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1775. {
  1776. if (phba->sli_rev == LPFC_SLI_REV4)
  1777. return 0;
  1778. else
  1779. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1780. lpfc_hbq_defs[qno]->add_count);
  1781. }
  1782. /**
  1783. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1784. * @phba: Pointer to HBA context object.
  1785. * @qno: HBQ queue number.
  1786. *
  1787. * This function is called from SLI initialization code path with
  1788. * no lock held to post initial HBQ buffers to firmware. The
  1789. * function returns the number of HBQ entries successfully allocated.
  1790. **/
  1791. static int
  1792. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1793. {
  1794. if (phba->sli_rev == LPFC_SLI_REV4)
  1795. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1796. lpfc_hbq_defs[qno]->entry_count);
  1797. else
  1798. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1799. lpfc_hbq_defs[qno]->init_count);
  1800. }
  1801. /**
  1802. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1803. * @phba: Pointer to HBA context object.
  1804. * @hbqno: HBQ number.
  1805. *
  1806. * This function removes the first hbq buffer on an hbq list and returns a
  1807. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1808. **/
  1809. static struct hbq_dmabuf *
  1810. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1811. {
  1812. struct lpfc_dmabuf *d_buf;
  1813. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1814. if (!d_buf)
  1815. return NULL;
  1816. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1817. }
  1818. /**
  1819. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1820. * @phba: Pointer to HBA context object.
  1821. * @tag: Tag of the hbq buffer.
  1822. *
  1823. * This function searches for the hbq buffer associated with the given tag in
  1824. * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
  1825. * otherwise it returns NULL.
  1826. **/
  1827. static struct hbq_dmabuf *
  1828. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1829. {
  1830. struct lpfc_dmabuf *d_buf;
  1831. struct hbq_dmabuf *hbq_buf;
  1832. uint32_t hbqno;
  1833. hbqno = tag >> 16;
  1834. if (hbqno >= LPFC_MAX_HBQS)
  1835. return NULL;
  1836. spin_lock_irq(&phba->hbalock);
  1837. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1838. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1839. if (hbq_buf->tag == tag) {
  1840. spin_unlock_irq(&phba->hbalock);
  1841. return hbq_buf;
  1842. }
  1843. }
  1844. spin_unlock_irq(&phba->hbalock);
  1845. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1846. "1803 Bad hbq tag. Data: x%x x%x\n",
  1847. tag, phba->hbqs[tag >> 16].buffer_count);
  1848. return NULL;
  1849. }
  1850. /**
  1851. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1852. * @phba: Pointer to HBA context object.
  1853. * @hbq_buffer: Pointer to HBQ buffer.
  1854. *
  1855. * This function is called with hbalock. This function gives back
  1856. * the hbq buffer to firmware. If the HBQ does not have space to
  1857. * post the buffer, it will free the buffer.
  1858. **/
  1859. void
  1860. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1861. {
  1862. uint32_t hbqno;
  1863. if (hbq_buffer) {
  1864. hbqno = hbq_buffer->tag >> 16;
  1865. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1866. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1867. }
  1868. }
  1869. /**
  1870. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1871. * @mbxCommand: mailbox command code.
  1872. *
  1873. * This function is called by the mailbox event handler function to verify
  1874. * that the completed mailbox command is a legitimate mailbox command. If the
  1875. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1876. * and the mailbox event handler will take the HBA offline.
  1877. **/
  1878. static int
  1879. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1880. {
  1881. uint8_t ret;
  1882. switch (mbxCommand) {
  1883. case MBX_LOAD_SM:
  1884. case MBX_READ_NV:
  1885. case MBX_WRITE_NV:
  1886. case MBX_WRITE_VPARMS:
  1887. case MBX_RUN_BIU_DIAG:
  1888. case MBX_INIT_LINK:
  1889. case MBX_DOWN_LINK:
  1890. case MBX_CONFIG_LINK:
  1891. case MBX_CONFIG_RING:
  1892. case MBX_RESET_RING:
  1893. case MBX_READ_CONFIG:
  1894. case MBX_READ_RCONFIG:
  1895. case MBX_READ_SPARM:
  1896. case MBX_READ_STATUS:
  1897. case MBX_READ_RPI:
  1898. case MBX_READ_XRI:
  1899. case MBX_READ_REV:
  1900. case MBX_READ_LNK_STAT:
  1901. case MBX_REG_LOGIN:
  1902. case MBX_UNREG_LOGIN:
  1903. case MBX_CLEAR_LA:
  1904. case MBX_DUMP_MEMORY:
  1905. case MBX_DUMP_CONTEXT:
  1906. case MBX_RUN_DIAGS:
  1907. case MBX_RESTART:
  1908. case MBX_UPDATE_CFG:
  1909. case MBX_DOWN_LOAD:
  1910. case MBX_DEL_LD_ENTRY:
  1911. case MBX_RUN_PROGRAM:
  1912. case MBX_SET_MASK:
  1913. case MBX_SET_VARIABLE:
  1914. case MBX_UNREG_D_ID:
  1915. case MBX_KILL_BOARD:
  1916. case MBX_CONFIG_FARP:
  1917. case MBX_BEACON:
  1918. case MBX_LOAD_AREA:
  1919. case MBX_RUN_BIU_DIAG64:
  1920. case MBX_CONFIG_PORT:
  1921. case MBX_READ_SPARM64:
  1922. case MBX_READ_RPI64:
  1923. case MBX_REG_LOGIN64:
  1924. case MBX_READ_TOPOLOGY:
  1925. case MBX_WRITE_WWN:
  1926. case MBX_SET_DEBUG:
  1927. case MBX_LOAD_EXP_ROM:
  1928. case MBX_ASYNCEVT_ENABLE:
  1929. case MBX_REG_VPI:
  1930. case MBX_UNREG_VPI:
  1931. case MBX_HEARTBEAT:
  1932. case MBX_PORT_CAPABILITIES:
  1933. case MBX_PORT_IOV_CONTROL:
  1934. case MBX_SLI4_CONFIG:
  1935. case MBX_SLI4_REQ_FTRS:
  1936. case MBX_REG_FCFI:
  1937. case MBX_UNREG_FCFI:
  1938. case MBX_REG_VFI:
  1939. case MBX_UNREG_VFI:
  1940. case MBX_INIT_VPI:
  1941. case MBX_INIT_VFI:
  1942. case MBX_RESUME_RPI:
  1943. case MBX_READ_EVENT_LOG_STATUS:
  1944. case MBX_READ_EVENT_LOG:
  1945. case MBX_SECURITY_MGMT:
  1946. case MBX_AUTH_PORT:
  1947. case MBX_ACCESS_VDATA:
  1948. ret = mbxCommand;
  1949. break;
  1950. default:
  1951. ret = MBX_SHUTDOWN;
  1952. break;
  1953. }
  1954. return ret;
  1955. }
  1956. /**
  1957. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1958. * @phba: Pointer to HBA context object.
  1959. * @pmboxq: Pointer to mailbox command.
  1960. *
  1961. * This is completion handler function for mailbox commands issued from
  1962. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1963. * mailbox event handler function with no lock held. This function
  1964. * will wake up thread waiting on the wait queue pointed by context1
  1965. * of the mailbox.
  1966. **/
  1967. void
  1968. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1969. {
  1970. wait_queue_head_t *pdone_q;
  1971. unsigned long drvr_flag;
  1972. /*
  1973. * If pdone_q is empty, the driver thread gave up waiting and
  1974. * continued running.
  1975. */
  1976. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1977. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1978. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1979. if (pdone_q)
  1980. wake_up_interruptible(pdone_q);
  1981. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1982. return;
  1983. }
  1984. /**
  1985. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1986. * @phba: Pointer to HBA context object.
  1987. * @pmb: Pointer to mailbox object.
  1988. *
  1989. * This function is the default mailbox completion handler. It
  1990. * frees the memory resources associated with the completed mailbox
  1991. * command. If the completed command is a REG_LOGIN mailbox command,
  1992. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1993. **/
  1994. void
  1995. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1996. {
  1997. struct lpfc_vport *vport = pmb->vport;
  1998. struct lpfc_dmabuf *mp;
  1999. struct lpfc_nodelist *ndlp;
  2000. struct Scsi_Host *shost;
  2001. uint16_t rpi, vpi;
  2002. int rc;
  2003. mp = (struct lpfc_dmabuf *) (pmb->context1);
  2004. if (mp) {
  2005. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2006. kfree(mp);
  2007. }
  2008. /*
  2009. * If a REG_LOGIN succeeded after node is destroyed or node
  2010. * is in re-discovery driver need to cleanup the RPI.
  2011. */
  2012. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  2013. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  2014. !pmb->u.mb.mbxStatus) {
  2015. rpi = pmb->u.mb.un.varWords[0];
  2016. vpi = pmb->u.mb.un.varRegLogin.vpi;
  2017. lpfc_unreg_login(phba, vpi, rpi, pmb);
  2018. pmb->vport = vport;
  2019. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2020. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2021. if (rc != MBX_NOT_FINISHED)
  2022. return;
  2023. }
  2024. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  2025. !(phba->pport->load_flag & FC_UNLOADING) &&
  2026. !pmb->u.mb.mbxStatus) {
  2027. shost = lpfc_shost_from_vport(vport);
  2028. spin_lock_irq(shost->host_lock);
  2029. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2030. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2031. spin_unlock_irq(shost->host_lock);
  2032. }
  2033. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  2034. ndlp = (struct lpfc_nodelist *)pmb->context2;
  2035. lpfc_nlp_put(ndlp);
  2036. pmb->context2 = NULL;
  2037. }
  2038. /* Check security permission status on INIT_LINK mailbox command */
  2039. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  2040. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  2041. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2042. "2860 SLI authentication is required "
  2043. "for INIT_LINK but has not done yet\n");
  2044. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  2045. lpfc_sli4_mbox_cmd_free(phba, pmb);
  2046. else
  2047. mempool_free(pmb, phba->mbox_mem_pool);
  2048. }
  2049. /**
  2050. * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
  2051. * @phba: Pointer to HBA context object.
  2052. * @pmb: Pointer to mailbox object.
  2053. *
  2054. * This function is the unreg rpi mailbox completion handler. It
  2055. * frees the memory resources associated with the completed mailbox
  2056. * command. An additional refrenece is put on the ndlp to prevent
  2057. * lpfc_nlp_release from freeing the rpi bit in the bitmask before
  2058. * the unreg mailbox command completes, this routine puts the
  2059. * reference back.
  2060. *
  2061. **/
  2062. void
  2063. lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2064. {
  2065. struct lpfc_vport *vport = pmb->vport;
  2066. struct lpfc_nodelist *ndlp;
  2067. ndlp = pmb->context1;
  2068. if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
  2069. if (phba->sli_rev == LPFC_SLI_REV4 &&
  2070. (bf_get(lpfc_sli_intf_if_type,
  2071. &phba->sli4_hba.sli_intf) ==
  2072. LPFC_SLI_INTF_IF_TYPE_2)) {
  2073. if (ndlp) {
  2074. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  2075. "0010 UNREG_LOGIN vpi:%x "
  2076. "rpi:%x DID:%x map:%x %p\n",
  2077. vport->vpi, ndlp->nlp_rpi,
  2078. ndlp->nlp_DID,
  2079. ndlp->nlp_usg_map, ndlp);
  2080. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2081. lpfc_nlp_put(ndlp);
  2082. }
  2083. }
  2084. }
  2085. mempool_free(pmb, phba->mbox_mem_pool);
  2086. }
  2087. /**
  2088. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2089. * @phba: Pointer to HBA context object.
  2090. *
  2091. * This function is called with no lock held. This function processes all
  2092. * the completed mailbox commands and gives it to upper layers. The interrupt
  2093. * service routine processes mailbox completion interrupt and adds completed
  2094. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2095. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2096. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2097. * function returns the mailbox commands to the upper layer by calling the
  2098. * completion handler function of each mailbox.
  2099. **/
  2100. int
  2101. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2102. {
  2103. MAILBOX_t *pmbox;
  2104. LPFC_MBOXQ_t *pmb;
  2105. int rc;
  2106. LIST_HEAD(cmplq);
  2107. phba->sli.slistat.mbox_event++;
  2108. /* Get all completed mailboxe buffers into the cmplq */
  2109. spin_lock_irq(&phba->hbalock);
  2110. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2111. spin_unlock_irq(&phba->hbalock);
  2112. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2113. do {
  2114. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2115. if (pmb == NULL)
  2116. break;
  2117. pmbox = &pmb->u.mb;
  2118. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2119. if (pmb->vport) {
  2120. lpfc_debugfs_disc_trc(pmb->vport,
  2121. LPFC_DISC_TRC_MBOX_VPORT,
  2122. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2123. (uint32_t)pmbox->mbxCommand,
  2124. pmbox->un.varWords[0],
  2125. pmbox->un.varWords[1]);
  2126. }
  2127. else {
  2128. lpfc_debugfs_disc_trc(phba->pport,
  2129. LPFC_DISC_TRC_MBOX,
  2130. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2131. (uint32_t)pmbox->mbxCommand,
  2132. pmbox->un.varWords[0],
  2133. pmbox->un.varWords[1]);
  2134. }
  2135. }
  2136. /*
  2137. * It is a fatal error if unknown mbox command completion.
  2138. */
  2139. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2140. MBX_SHUTDOWN) {
  2141. /* Unknown mailbox command compl */
  2142. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2143. "(%d):0323 Unknown Mailbox command "
  2144. "x%x (x%x/x%x) Cmpl\n",
  2145. pmb->vport ? pmb->vport->vpi : 0,
  2146. pmbox->mbxCommand,
  2147. lpfc_sli_config_mbox_subsys_get(phba,
  2148. pmb),
  2149. lpfc_sli_config_mbox_opcode_get(phba,
  2150. pmb));
  2151. phba->link_state = LPFC_HBA_ERROR;
  2152. phba->work_hs = HS_FFER3;
  2153. lpfc_handle_eratt(phba);
  2154. continue;
  2155. }
  2156. if (pmbox->mbxStatus) {
  2157. phba->sli.slistat.mbox_stat_err++;
  2158. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2159. /* Mbox cmd cmpl error - RETRYing */
  2160. lpfc_printf_log(phba, KERN_INFO,
  2161. LOG_MBOX | LOG_SLI,
  2162. "(%d):0305 Mbox cmd cmpl "
  2163. "error - RETRYing Data: x%x "
  2164. "(x%x/x%x) x%x x%x x%x\n",
  2165. pmb->vport ? pmb->vport->vpi : 0,
  2166. pmbox->mbxCommand,
  2167. lpfc_sli_config_mbox_subsys_get(phba,
  2168. pmb),
  2169. lpfc_sli_config_mbox_opcode_get(phba,
  2170. pmb),
  2171. pmbox->mbxStatus,
  2172. pmbox->un.varWords[0],
  2173. pmb->vport->port_state);
  2174. pmbox->mbxStatus = 0;
  2175. pmbox->mbxOwner = OWN_HOST;
  2176. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2177. if (rc != MBX_NOT_FINISHED)
  2178. continue;
  2179. }
  2180. }
  2181. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2182. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2183. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2184. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  2185. "x%x x%x x%x\n",
  2186. pmb->vport ? pmb->vport->vpi : 0,
  2187. pmbox->mbxCommand,
  2188. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2189. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2190. pmb->mbox_cmpl,
  2191. *((uint32_t *) pmbox),
  2192. pmbox->un.varWords[0],
  2193. pmbox->un.varWords[1],
  2194. pmbox->un.varWords[2],
  2195. pmbox->un.varWords[3],
  2196. pmbox->un.varWords[4],
  2197. pmbox->un.varWords[5],
  2198. pmbox->un.varWords[6],
  2199. pmbox->un.varWords[7],
  2200. pmbox->un.varWords[8],
  2201. pmbox->un.varWords[9],
  2202. pmbox->un.varWords[10]);
  2203. if (pmb->mbox_cmpl)
  2204. pmb->mbox_cmpl(phba,pmb);
  2205. } while (1);
  2206. return 0;
  2207. }
  2208. /**
  2209. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2210. * @phba: Pointer to HBA context object.
  2211. * @pring: Pointer to driver SLI ring object.
  2212. * @tag: buffer tag.
  2213. *
  2214. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2215. * is set in the tag the buffer is posted for a particular exchange,
  2216. * the function will return the buffer without replacing the buffer.
  2217. * If the buffer is for unsolicited ELS or CT traffic, this function
  2218. * returns the buffer and also posts another buffer to the firmware.
  2219. **/
  2220. static struct lpfc_dmabuf *
  2221. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2222. struct lpfc_sli_ring *pring,
  2223. uint32_t tag)
  2224. {
  2225. struct hbq_dmabuf *hbq_entry;
  2226. if (tag & QUE_BUFTAG_BIT)
  2227. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2228. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2229. if (!hbq_entry)
  2230. return NULL;
  2231. return &hbq_entry->dbuf;
  2232. }
  2233. /**
  2234. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2235. * @phba: Pointer to HBA context object.
  2236. * @pring: Pointer to driver SLI ring object.
  2237. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2238. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2239. * @fch_type: the type for the first frame of the sequence.
  2240. *
  2241. * This function is called with no lock held. This function uses the r_ctl and
  2242. * type of the received sequence to find the correct callback function to call
  2243. * to process the sequence.
  2244. **/
  2245. static int
  2246. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2247. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2248. uint32_t fch_type)
  2249. {
  2250. int i;
  2251. /* unSolicited Responses */
  2252. if (pring->prt[0].profile) {
  2253. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2254. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2255. saveq);
  2256. return 1;
  2257. }
  2258. /* We must search, based on rctl / type
  2259. for the right routine */
  2260. for (i = 0; i < pring->num_mask; i++) {
  2261. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2262. (pring->prt[i].type == fch_type)) {
  2263. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2264. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2265. (phba, pring, saveq);
  2266. return 1;
  2267. }
  2268. }
  2269. return 0;
  2270. }
  2271. /**
  2272. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2273. * @phba: Pointer to HBA context object.
  2274. * @pring: Pointer to driver SLI ring object.
  2275. * @saveq: Pointer to the unsolicited iocb.
  2276. *
  2277. * This function is called with no lock held by the ring event handler
  2278. * when there is an unsolicited iocb posted to the response ring by the
  2279. * firmware. This function gets the buffer associated with the iocbs
  2280. * and calls the event handler for the ring. This function handles both
  2281. * qring buffers and hbq buffers.
  2282. * When the function returns 1 the caller can free the iocb object otherwise
  2283. * upper layer functions will free the iocb objects.
  2284. **/
  2285. static int
  2286. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2287. struct lpfc_iocbq *saveq)
  2288. {
  2289. IOCB_t * irsp;
  2290. WORD5 * w5p;
  2291. uint32_t Rctl, Type;
  2292. struct lpfc_iocbq *iocbq;
  2293. struct lpfc_dmabuf *dmzbuf;
  2294. irsp = &(saveq->iocb);
  2295. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2296. if (pring->lpfc_sli_rcv_async_status)
  2297. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2298. else
  2299. lpfc_printf_log(phba,
  2300. KERN_WARNING,
  2301. LOG_SLI,
  2302. "0316 Ring %d handler: unexpected "
  2303. "ASYNC_STATUS iocb received evt_code "
  2304. "0x%x\n",
  2305. pring->ringno,
  2306. irsp->un.asyncstat.evt_code);
  2307. return 1;
  2308. }
  2309. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2310. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2311. if (irsp->ulpBdeCount > 0) {
  2312. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2313. irsp->un.ulpWord[3]);
  2314. lpfc_in_buf_free(phba, dmzbuf);
  2315. }
  2316. if (irsp->ulpBdeCount > 1) {
  2317. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2318. irsp->unsli3.sli3Words[3]);
  2319. lpfc_in_buf_free(phba, dmzbuf);
  2320. }
  2321. if (irsp->ulpBdeCount > 2) {
  2322. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2323. irsp->unsli3.sli3Words[7]);
  2324. lpfc_in_buf_free(phba, dmzbuf);
  2325. }
  2326. return 1;
  2327. }
  2328. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2329. if (irsp->ulpBdeCount != 0) {
  2330. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2331. irsp->un.ulpWord[3]);
  2332. if (!saveq->context2)
  2333. lpfc_printf_log(phba,
  2334. KERN_ERR,
  2335. LOG_SLI,
  2336. "0341 Ring %d Cannot find buffer for "
  2337. "an unsolicited iocb. tag 0x%x\n",
  2338. pring->ringno,
  2339. irsp->un.ulpWord[3]);
  2340. }
  2341. if (irsp->ulpBdeCount == 2) {
  2342. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2343. irsp->unsli3.sli3Words[7]);
  2344. if (!saveq->context3)
  2345. lpfc_printf_log(phba,
  2346. KERN_ERR,
  2347. LOG_SLI,
  2348. "0342 Ring %d Cannot find buffer for an"
  2349. " unsolicited iocb. tag 0x%x\n",
  2350. pring->ringno,
  2351. irsp->unsli3.sli3Words[7]);
  2352. }
  2353. list_for_each_entry(iocbq, &saveq->list, list) {
  2354. irsp = &(iocbq->iocb);
  2355. if (irsp->ulpBdeCount != 0) {
  2356. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2357. irsp->un.ulpWord[3]);
  2358. if (!iocbq->context2)
  2359. lpfc_printf_log(phba,
  2360. KERN_ERR,
  2361. LOG_SLI,
  2362. "0343 Ring %d Cannot find "
  2363. "buffer for an unsolicited iocb"
  2364. ". tag 0x%x\n", pring->ringno,
  2365. irsp->un.ulpWord[3]);
  2366. }
  2367. if (irsp->ulpBdeCount == 2) {
  2368. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2369. irsp->unsli3.sli3Words[7]);
  2370. if (!iocbq->context3)
  2371. lpfc_printf_log(phba,
  2372. KERN_ERR,
  2373. LOG_SLI,
  2374. "0344 Ring %d Cannot find "
  2375. "buffer for an unsolicited "
  2376. "iocb. tag 0x%x\n",
  2377. pring->ringno,
  2378. irsp->unsli3.sli3Words[7]);
  2379. }
  2380. }
  2381. }
  2382. if (irsp->ulpBdeCount != 0 &&
  2383. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2384. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2385. int found = 0;
  2386. /* search continue save q for same XRI */
  2387. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2388. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2389. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2390. list_add_tail(&saveq->list, &iocbq->list);
  2391. found = 1;
  2392. break;
  2393. }
  2394. }
  2395. if (!found)
  2396. list_add_tail(&saveq->clist,
  2397. &pring->iocb_continue_saveq);
  2398. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2399. list_del_init(&iocbq->clist);
  2400. saveq = iocbq;
  2401. irsp = &(saveq->iocb);
  2402. } else
  2403. return 0;
  2404. }
  2405. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2406. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2407. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2408. Rctl = FC_RCTL_ELS_REQ;
  2409. Type = FC_TYPE_ELS;
  2410. } else {
  2411. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2412. Rctl = w5p->hcsw.Rctl;
  2413. Type = w5p->hcsw.Type;
  2414. /* Firmware Workaround */
  2415. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2416. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2417. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2418. Rctl = FC_RCTL_ELS_REQ;
  2419. Type = FC_TYPE_ELS;
  2420. w5p->hcsw.Rctl = Rctl;
  2421. w5p->hcsw.Type = Type;
  2422. }
  2423. }
  2424. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2425. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2426. "0313 Ring %d handler: unexpected Rctl x%x "
  2427. "Type x%x received\n",
  2428. pring->ringno, Rctl, Type);
  2429. return 1;
  2430. }
  2431. /**
  2432. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2433. * @phba: Pointer to HBA context object.
  2434. * @pring: Pointer to driver SLI ring object.
  2435. * @prspiocb: Pointer to response iocb object.
  2436. *
  2437. * This function looks up the iocb_lookup table to get the command iocb
  2438. * corresponding to the given response iocb using the iotag of the
  2439. * response iocb. This function is called with the hbalock held.
  2440. * This function returns the command iocb object if it finds the command
  2441. * iocb else returns NULL.
  2442. **/
  2443. static struct lpfc_iocbq *
  2444. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2445. struct lpfc_sli_ring *pring,
  2446. struct lpfc_iocbq *prspiocb)
  2447. {
  2448. struct lpfc_iocbq *cmd_iocb = NULL;
  2449. uint16_t iotag;
  2450. lockdep_assert_held(&phba->hbalock);
  2451. iotag = prspiocb->iocb.ulpIoTag;
  2452. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2453. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2454. list_del_init(&cmd_iocb->list);
  2455. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2456. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2457. }
  2458. return cmd_iocb;
  2459. }
  2460. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2461. "0317 iotag x%x is out off "
  2462. "range: max iotag x%x wd0 x%x\n",
  2463. iotag, phba->sli.last_iotag,
  2464. *(((uint32_t *) &prspiocb->iocb) + 7));
  2465. return NULL;
  2466. }
  2467. /**
  2468. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2469. * @phba: Pointer to HBA context object.
  2470. * @pring: Pointer to driver SLI ring object.
  2471. * @iotag: IOCB tag.
  2472. *
  2473. * This function looks up the iocb_lookup table to get the command iocb
  2474. * corresponding to the given iotag. This function is called with the
  2475. * hbalock held.
  2476. * This function returns the command iocb object if it finds the command
  2477. * iocb else returns NULL.
  2478. **/
  2479. static struct lpfc_iocbq *
  2480. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2481. struct lpfc_sli_ring *pring, uint16_t iotag)
  2482. {
  2483. struct lpfc_iocbq *cmd_iocb;
  2484. lockdep_assert_held(&phba->hbalock);
  2485. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2486. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2487. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2488. /* remove from txcmpl queue list */
  2489. list_del_init(&cmd_iocb->list);
  2490. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2491. return cmd_iocb;
  2492. }
  2493. }
  2494. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2495. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2496. iotag, phba->sli.last_iotag);
  2497. return NULL;
  2498. }
  2499. /**
  2500. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2501. * @phba: Pointer to HBA context object.
  2502. * @pring: Pointer to driver SLI ring object.
  2503. * @saveq: Pointer to the response iocb to be processed.
  2504. *
  2505. * This function is called by the ring event handler for non-fcp
  2506. * rings when there is a new response iocb in the response ring.
  2507. * The caller is not required to hold any locks. This function
  2508. * gets the command iocb associated with the response iocb and
  2509. * calls the completion handler for the command iocb. If there
  2510. * is no completion handler, the function will free the resources
  2511. * associated with command iocb. If the response iocb is for
  2512. * an already aborted command iocb, the status of the completion
  2513. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2514. * This function always returns 1.
  2515. **/
  2516. static int
  2517. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2518. struct lpfc_iocbq *saveq)
  2519. {
  2520. struct lpfc_iocbq *cmdiocbp;
  2521. int rc = 1;
  2522. unsigned long iflag;
  2523. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2524. spin_lock_irqsave(&phba->hbalock, iflag);
  2525. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2526. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2527. if (cmdiocbp) {
  2528. if (cmdiocbp->iocb_cmpl) {
  2529. /*
  2530. * If an ELS command failed send an event to mgmt
  2531. * application.
  2532. */
  2533. if (saveq->iocb.ulpStatus &&
  2534. (pring->ringno == LPFC_ELS_RING) &&
  2535. (cmdiocbp->iocb.ulpCommand ==
  2536. CMD_ELS_REQUEST64_CR))
  2537. lpfc_send_els_failure_event(phba,
  2538. cmdiocbp, saveq);
  2539. /*
  2540. * Post all ELS completions to the worker thread.
  2541. * All other are passed to the completion callback.
  2542. */
  2543. if (pring->ringno == LPFC_ELS_RING) {
  2544. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2545. (cmdiocbp->iocb_flag &
  2546. LPFC_DRIVER_ABORTED)) {
  2547. spin_lock_irqsave(&phba->hbalock,
  2548. iflag);
  2549. cmdiocbp->iocb_flag &=
  2550. ~LPFC_DRIVER_ABORTED;
  2551. spin_unlock_irqrestore(&phba->hbalock,
  2552. iflag);
  2553. saveq->iocb.ulpStatus =
  2554. IOSTAT_LOCAL_REJECT;
  2555. saveq->iocb.un.ulpWord[4] =
  2556. IOERR_SLI_ABORTED;
  2557. /* Firmware could still be in progress
  2558. * of DMAing payload, so don't free data
  2559. * buffer till after a hbeat.
  2560. */
  2561. spin_lock_irqsave(&phba->hbalock,
  2562. iflag);
  2563. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2564. spin_unlock_irqrestore(&phba->hbalock,
  2565. iflag);
  2566. }
  2567. if (phba->sli_rev == LPFC_SLI_REV4) {
  2568. if (saveq->iocb_flag &
  2569. LPFC_EXCHANGE_BUSY) {
  2570. /* Set cmdiocb flag for the
  2571. * exchange busy so sgl (xri)
  2572. * will not be released until
  2573. * the abort xri is received
  2574. * from hba.
  2575. */
  2576. spin_lock_irqsave(
  2577. &phba->hbalock, iflag);
  2578. cmdiocbp->iocb_flag |=
  2579. LPFC_EXCHANGE_BUSY;
  2580. spin_unlock_irqrestore(
  2581. &phba->hbalock, iflag);
  2582. }
  2583. if (cmdiocbp->iocb_flag &
  2584. LPFC_DRIVER_ABORTED) {
  2585. /*
  2586. * Clear LPFC_DRIVER_ABORTED
  2587. * bit in case it was driver
  2588. * initiated abort.
  2589. */
  2590. spin_lock_irqsave(
  2591. &phba->hbalock, iflag);
  2592. cmdiocbp->iocb_flag &=
  2593. ~LPFC_DRIVER_ABORTED;
  2594. spin_unlock_irqrestore(
  2595. &phba->hbalock, iflag);
  2596. cmdiocbp->iocb.ulpStatus =
  2597. IOSTAT_LOCAL_REJECT;
  2598. cmdiocbp->iocb.un.ulpWord[4] =
  2599. IOERR_ABORT_REQUESTED;
  2600. /*
  2601. * For SLI4, irsiocb contains
  2602. * NO_XRI in sli_xritag, it
  2603. * shall not affect releasing
  2604. * sgl (xri) process.
  2605. */
  2606. saveq->iocb.ulpStatus =
  2607. IOSTAT_LOCAL_REJECT;
  2608. saveq->iocb.un.ulpWord[4] =
  2609. IOERR_SLI_ABORTED;
  2610. spin_lock_irqsave(
  2611. &phba->hbalock, iflag);
  2612. saveq->iocb_flag |=
  2613. LPFC_DELAY_MEM_FREE;
  2614. spin_unlock_irqrestore(
  2615. &phba->hbalock, iflag);
  2616. }
  2617. }
  2618. }
  2619. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2620. } else
  2621. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2622. } else {
  2623. /*
  2624. * Unknown initiating command based on the response iotag.
  2625. * This could be the case on the ELS ring because of
  2626. * lpfc_els_abort().
  2627. */
  2628. if (pring->ringno != LPFC_ELS_RING) {
  2629. /*
  2630. * Ring <ringno> handler: unexpected completion IoTag
  2631. * <IoTag>
  2632. */
  2633. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2634. "0322 Ring %d handler: "
  2635. "unexpected completion IoTag x%x "
  2636. "Data: x%x x%x x%x x%x\n",
  2637. pring->ringno,
  2638. saveq->iocb.ulpIoTag,
  2639. saveq->iocb.ulpStatus,
  2640. saveq->iocb.un.ulpWord[4],
  2641. saveq->iocb.ulpCommand,
  2642. saveq->iocb.ulpContext);
  2643. }
  2644. }
  2645. return rc;
  2646. }
  2647. /**
  2648. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2649. * @phba: Pointer to HBA context object.
  2650. * @pring: Pointer to driver SLI ring object.
  2651. *
  2652. * This function is called from the iocb ring event handlers when
  2653. * put pointer is ahead of the get pointer for a ring. This function signal
  2654. * an error attention condition to the worker thread and the worker
  2655. * thread will transition the HBA to offline state.
  2656. **/
  2657. static void
  2658. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2659. {
  2660. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2661. /*
  2662. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2663. * rsp ring <portRspMax>
  2664. */
  2665. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2666. "0312 Ring %d handler: portRspPut %d "
  2667. "is bigger than rsp ring %d\n",
  2668. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2669. pring->sli.sli3.numRiocb);
  2670. phba->link_state = LPFC_HBA_ERROR;
  2671. /*
  2672. * All error attention handlers are posted to
  2673. * worker thread
  2674. */
  2675. phba->work_ha |= HA_ERATT;
  2676. phba->work_hs = HS_FFER3;
  2677. lpfc_worker_wake_up(phba);
  2678. return;
  2679. }
  2680. /**
  2681. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2682. * @ptr: Pointer to address of HBA context object.
  2683. *
  2684. * This function is invoked by the Error Attention polling timer when the
  2685. * timer times out. It will check the SLI Error Attention register for
  2686. * possible attention events. If so, it will post an Error Attention event
  2687. * and wake up worker thread to process it. Otherwise, it will set up the
  2688. * Error Attention polling timer for the next poll.
  2689. **/
  2690. void lpfc_poll_eratt(unsigned long ptr)
  2691. {
  2692. struct lpfc_hba *phba;
  2693. uint32_t eratt = 0;
  2694. uint64_t sli_intr, cnt;
  2695. phba = (struct lpfc_hba *)ptr;
  2696. /* Here we will also keep track of interrupts per sec of the hba */
  2697. sli_intr = phba->sli.slistat.sli_intr;
  2698. if (phba->sli.slistat.sli_prev_intr > sli_intr)
  2699. cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
  2700. sli_intr);
  2701. else
  2702. cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
  2703. /* 64-bit integer division not supported on 32-bit x86 - use do_div */
  2704. do_div(cnt, phba->eratt_poll_interval);
  2705. phba->sli.slistat.sli_ips = cnt;
  2706. phba->sli.slistat.sli_prev_intr = sli_intr;
  2707. /* Check chip HA register for error event */
  2708. eratt = lpfc_sli_check_eratt(phba);
  2709. if (eratt)
  2710. /* Tell the worker thread there is work to do */
  2711. lpfc_worker_wake_up(phba);
  2712. else
  2713. /* Restart the timer for next eratt poll */
  2714. mod_timer(&phba->eratt_poll,
  2715. jiffies +
  2716. msecs_to_jiffies(1000 * phba->eratt_poll_interval));
  2717. return;
  2718. }
  2719. /**
  2720. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2721. * @phba: Pointer to HBA context object.
  2722. * @pring: Pointer to driver SLI ring object.
  2723. * @mask: Host attention register mask for this ring.
  2724. *
  2725. * This function is called from the interrupt context when there is a ring
  2726. * event for the fcp ring. The caller does not hold any lock.
  2727. * The function processes each response iocb in the response ring until it
  2728. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2729. * LE bit set. The function will call the completion handler of the command iocb
  2730. * if the response iocb indicates a completion for a command iocb or it is
  2731. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2732. * function if this is an unsolicited iocb.
  2733. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2734. * to check it explicitly.
  2735. */
  2736. int
  2737. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2738. struct lpfc_sli_ring *pring, uint32_t mask)
  2739. {
  2740. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2741. IOCB_t *irsp = NULL;
  2742. IOCB_t *entry = NULL;
  2743. struct lpfc_iocbq *cmdiocbq = NULL;
  2744. struct lpfc_iocbq rspiocbq;
  2745. uint32_t status;
  2746. uint32_t portRspPut, portRspMax;
  2747. int rc = 1;
  2748. lpfc_iocb_type type;
  2749. unsigned long iflag;
  2750. uint32_t rsp_cmpl = 0;
  2751. spin_lock_irqsave(&phba->hbalock, iflag);
  2752. pring->stats.iocb_event++;
  2753. /*
  2754. * The next available response entry should never exceed the maximum
  2755. * entries. If it does, treat it as an adapter hardware error.
  2756. */
  2757. portRspMax = pring->sli.sli3.numRiocb;
  2758. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2759. if (unlikely(portRspPut >= portRspMax)) {
  2760. lpfc_sli_rsp_pointers_error(phba, pring);
  2761. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2762. return 1;
  2763. }
  2764. if (phba->fcp_ring_in_use) {
  2765. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2766. return 1;
  2767. } else
  2768. phba->fcp_ring_in_use = 1;
  2769. rmb();
  2770. while (pring->sli.sli3.rspidx != portRspPut) {
  2771. /*
  2772. * Fetch an entry off the ring and copy it into a local data
  2773. * structure. The copy involves a byte-swap since the
  2774. * network byte order and pci byte orders are different.
  2775. */
  2776. entry = lpfc_resp_iocb(phba, pring);
  2777. phba->last_completion_time = jiffies;
  2778. if (++pring->sli.sli3.rspidx >= portRspMax)
  2779. pring->sli.sli3.rspidx = 0;
  2780. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2781. (uint32_t *) &rspiocbq.iocb,
  2782. phba->iocb_rsp_size);
  2783. INIT_LIST_HEAD(&(rspiocbq.list));
  2784. irsp = &rspiocbq.iocb;
  2785. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2786. pring->stats.iocb_rsp++;
  2787. rsp_cmpl++;
  2788. if (unlikely(irsp->ulpStatus)) {
  2789. /*
  2790. * If resource errors reported from HBA, reduce
  2791. * queuedepths of the SCSI device.
  2792. */
  2793. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2794. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2795. IOERR_NO_RESOURCES)) {
  2796. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2797. phba->lpfc_rampdown_queue_depth(phba);
  2798. spin_lock_irqsave(&phba->hbalock, iflag);
  2799. }
  2800. /* Rsp ring <ringno> error: IOCB */
  2801. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2802. "0336 Rsp Ring %d error: IOCB Data: "
  2803. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2804. pring->ringno,
  2805. irsp->un.ulpWord[0],
  2806. irsp->un.ulpWord[1],
  2807. irsp->un.ulpWord[2],
  2808. irsp->un.ulpWord[3],
  2809. irsp->un.ulpWord[4],
  2810. irsp->un.ulpWord[5],
  2811. *(uint32_t *)&irsp->un1,
  2812. *((uint32_t *)&irsp->un1 + 1));
  2813. }
  2814. switch (type) {
  2815. case LPFC_ABORT_IOCB:
  2816. case LPFC_SOL_IOCB:
  2817. /*
  2818. * Idle exchange closed via ABTS from port. No iocb
  2819. * resources need to be recovered.
  2820. */
  2821. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2822. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2823. "0333 IOCB cmd 0x%x"
  2824. " processed. Skipping"
  2825. " completion\n",
  2826. irsp->ulpCommand);
  2827. break;
  2828. }
  2829. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2830. &rspiocbq);
  2831. if (unlikely(!cmdiocbq))
  2832. break;
  2833. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2834. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2835. if (cmdiocbq->iocb_cmpl) {
  2836. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2837. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2838. &rspiocbq);
  2839. spin_lock_irqsave(&phba->hbalock, iflag);
  2840. }
  2841. break;
  2842. case LPFC_UNSOL_IOCB:
  2843. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2844. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2845. spin_lock_irqsave(&phba->hbalock, iflag);
  2846. break;
  2847. default:
  2848. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2849. char adaptermsg[LPFC_MAX_ADPTMSG];
  2850. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2851. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2852. MAX_MSG_DATA);
  2853. dev_warn(&((phba->pcidev)->dev),
  2854. "lpfc%d: %s\n",
  2855. phba->brd_no, adaptermsg);
  2856. } else {
  2857. /* Unknown IOCB command */
  2858. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2859. "0334 Unknown IOCB command "
  2860. "Data: x%x, x%x x%x x%x x%x\n",
  2861. type, irsp->ulpCommand,
  2862. irsp->ulpStatus,
  2863. irsp->ulpIoTag,
  2864. irsp->ulpContext);
  2865. }
  2866. break;
  2867. }
  2868. /*
  2869. * The response IOCB has been processed. Update the ring
  2870. * pointer in SLIM. If the port response put pointer has not
  2871. * been updated, sync the pgp->rspPutInx and fetch the new port
  2872. * response put pointer.
  2873. */
  2874. writel(pring->sli.sli3.rspidx,
  2875. &phba->host_gp[pring->ringno].rspGetInx);
  2876. if (pring->sli.sli3.rspidx == portRspPut)
  2877. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2878. }
  2879. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2880. pring->stats.iocb_rsp_full++;
  2881. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2882. writel(status, phba->CAregaddr);
  2883. readl(phba->CAregaddr);
  2884. }
  2885. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2886. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2887. pring->stats.iocb_cmd_empty++;
  2888. /* Force update of the local copy of cmdGetInx */
  2889. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2890. lpfc_sli_resume_iocb(phba, pring);
  2891. if ((pring->lpfc_sli_cmd_available))
  2892. (pring->lpfc_sli_cmd_available) (phba, pring);
  2893. }
  2894. phba->fcp_ring_in_use = 0;
  2895. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2896. return rc;
  2897. }
  2898. /**
  2899. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2900. * @phba: Pointer to HBA context object.
  2901. * @pring: Pointer to driver SLI ring object.
  2902. * @rspiocbp: Pointer to driver response IOCB object.
  2903. *
  2904. * This function is called from the worker thread when there is a slow-path
  2905. * response IOCB to process. This function chains all the response iocbs until
  2906. * seeing the iocb with the LE bit set. The function will call
  2907. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2908. * completion of a command iocb. The function will call the
  2909. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2910. * The function frees the resources or calls the completion handler if this
  2911. * iocb is an abort completion. The function returns NULL when the response
  2912. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2913. * this function shall chain the iocb on to the iocb_continueq and return the
  2914. * response iocb passed in.
  2915. **/
  2916. static struct lpfc_iocbq *
  2917. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2918. struct lpfc_iocbq *rspiocbp)
  2919. {
  2920. struct lpfc_iocbq *saveq;
  2921. struct lpfc_iocbq *cmdiocbp;
  2922. struct lpfc_iocbq *next_iocb;
  2923. IOCB_t *irsp = NULL;
  2924. uint32_t free_saveq;
  2925. uint8_t iocb_cmd_type;
  2926. lpfc_iocb_type type;
  2927. unsigned long iflag;
  2928. int rc;
  2929. spin_lock_irqsave(&phba->hbalock, iflag);
  2930. /* First add the response iocb to the countinueq list */
  2931. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2932. pring->iocb_continueq_cnt++;
  2933. /* Now, determine whether the list is completed for processing */
  2934. irsp = &rspiocbp->iocb;
  2935. if (irsp->ulpLe) {
  2936. /*
  2937. * By default, the driver expects to free all resources
  2938. * associated with this iocb completion.
  2939. */
  2940. free_saveq = 1;
  2941. saveq = list_get_first(&pring->iocb_continueq,
  2942. struct lpfc_iocbq, list);
  2943. irsp = &(saveq->iocb);
  2944. list_del_init(&pring->iocb_continueq);
  2945. pring->iocb_continueq_cnt = 0;
  2946. pring->stats.iocb_rsp++;
  2947. /*
  2948. * If resource errors reported from HBA, reduce
  2949. * queuedepths of the SCSI device.
  2950. */
  2951. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2952. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2953. IOERR_NO_RESOURCES)) {
  2954. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2955. phba->lpfc_rampdown_queue_depth(phba);
  2956. spin_lock_irqsave(&phba->hbalock, iflag);
  2957. }
  2958. if (irsp->ulpStatus) {
  2959. /* Rsp ring <ringno> error: IOCB */
  2960. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2961. "0328 Rsp Ring %d error: "
  2962. "IOCB Data: "
  2963. "x%x x%x x%x x%x "
  2964. "x%x x%x x%x x%x "
  2965. "x%x x%x x%x x%x "
  2966. "x%x x%x x%x x%x\n",
  2967. pring->ringno,
  2968. irsp->un.ulpWord[0],
  2969. irsp->un.ulpWord[1],
  2970. irsp->un.ulpWord[2],
  2971. irsp->un.ulpWord[3],
  2972. irsp->un.ulpWord[4],
  2973. irsp->un.ulpWord[5],
  2974. *(((uint32_t *) irsp) + 6),
  2975. *(((uint32_t *) irsp) + 7),
  2976. *(((uint32_t *) irsp) + 8),
  2977. *(((uint32_t *) irsp) + 9),
  2978. *(((uint32_t *) irsp) + 10),
  2979. *(((uint32_t *) irsp) + 11),
  2980. *(((uint32_t *) irsp) + 12),
  2981. *(((uint32_t *) irsp) + 13),
  2982. *(((uint32_t *) irsp) + 14),
  2983. *(((uint32_t *) irsp) + 15));
  2984. }
  2985. /*
  2986. * Fetch the IOCB command type and call the correct completion
  2987. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2988. * get freed back to the lpfc_iocb_list by the discovery
  2989. * kernel thread.
  2990. */
  2991. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2992. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2993. switch (type) {
  2994. case LPFC_SOL_IOCB:
  2995. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2996. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2997. spin_lock_irqsave(&phba->hbalock, iflag);
  2998. break;
  2999. case LPFC_UNSOL_IOCB:
  3000. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3001. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  3002. spin_lock_irqsave(&phba->hbalock, iflag);
  3003. if (!rc)
  3004. free_saveq = 0;
  3005. break;
  3006. case LPFC_ABORT_IOCB:
  3007. cmdiocbp = NULL;
  3008. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  3009. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  3010. saveq);
  3011. if (cmdiocbp) {
  3012. /* Call the specified completion routine */
  3013. if (cmdiocbp->iocb_cmpl) {
  3014. spin_unlock_irqrestore(&phba->hbalock,
  3015. iflag);
  3016. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  3017. saveq);
  3018. spin_lock_irqsave(&phba->hbalock,
  3019. iflag);
  3020. } else
  3021. __lpfc_sli_release_iocbq(phba,
  3022. cmdiocbp);
  3023. }
  3024. break;
  3025. case LPFC_UNKNOWN_IOCB:
  3026. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  3027. char adaptermsg[LPFC_MAX_ADPTMSG];
  3028. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  3029. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  3030. MAX_MSG_DATA);
  3031. dev_warn(&((phba->pcidev)->dev),
  3032. "lpfc%d: %s\n",
  3033. phba->brd_no, adaptermsg);
  3034. } else {
  3035. /* Unknown IOCB command */
  3036. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3037. "0335 Unknown IOCB "
  3038. "command Data: x%x "
  3039. "x%x x%x x%x\n",
  3040. irsp->ulpCommand,
  3041. irsp->ulpStatus,
  3042. irsp->ulpIoTag,
  3043. irsp->ulpContext);
  3044. }
  3045. break;
  3046. }
  3047. if (free_saveq) {
  3048. list_for_each_entry_safe(rspiocbp, next_iocb,
  3049. &saveq->list, list) {
  3050. list_del_init(&rspiocbp->list);
  3051. __lpfc_sli_release_iocbq(phba, rspiocbp);
  3052. }
  3053. __lpfc_sli_release_iocbq(phba, saveq);
  3054. }
  3055. rspiocbp = NULL;
  3056. }
  3057. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3058. return rspiocbp;
  3059. }
  3060. /**
  3061. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  3062. * @phba: Pointer to HBA context object.
  3063. * @pring: Pointer to driver SLI ring object.
  3064. * @mask: Host attention register mask for this ring.
  3065. *
  3066. * This routine wraps the actual slow_ring event process routine from the
  3067. * API jump table function pointer from the lpfc_hba struct.
  3068. **/
  3069. void
  3070. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  3071. struct lpfc_sli_ring *pring, uint32_t mask)
  3072. {
  3073. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  3074. }
  3075. /**
  3076. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  3077. * @phba: Pointer to HBA context object.
  3078. * @pring: Pointer to driver SLI ring object.
  3079. * @mask: Host attention register mask for this ring.
  3080. *
  3081. * This function is called from the worker thread when there is a ring event
  3082. * for non-fcp rings. The caller does not hold any lock. The function will
  3083. * remove each response iocb in the response ring and calls the handle
  3084. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3085. **/
  3086. static void
  3087. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  3088. struct lpfc_sli_ring *pring, uint32_t mask)
  3089. {
  3090. struct lpfc_pgp *pgp;
  3091. IOCB_t *entry;
  3092. IOCB_t *irsp = NULL;
  3093. struct lpfc_iocbq *rspiocbp = NULL;
  3094. uint32_t portRspPut, portRspMax;
  3095. unsigned long iflag;
  3096. uint32_t status;
  3097. pgp = &phba->port_gp[pring->ringno];
  3098. spin_lock_irqsave(&phba->hbalock, iflag);
  3099. pring->stats.iocb_event++;
  3100. /*
  3101. * The next available response entry should never exceed the maximum
  3102. * entries. If it does, treat it as an adapter hardware error.
  3103. */
  3104. portRspMax = pring->sli.sli3.numRiocb;
  3105. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3106. if (portRspPut >= portRspMax) {
  3107. /*
  3108. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3109. * rsp ring <portRspMax>
  3110. */
  3111. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3112. "0303 Ring %d handler: portRspPut %d "
  3113. "is bigger than rsp ring %d\n",
  3114. pring->ringno, portRspPut, portRspMax);
  3115. phba->link_state = LPFC_HBA_ERROR;
  3116. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3117. phba->work_hs = HS_FFER3;
  3118. lpfc_handle_eratt(phba);
  3119. return;
  3120. }
  3121. rmb();
  3122. while (pring->sli.sli3.rspidx != portRspPut) {
  3123. /*
  3124. * Build a completion list and call the appropriate handler.
  3125. * The process is to get the next available response iocb, get
  3126. * a free iocb from the list, copy the response data into the
  3127. * free iocb, insert to the continuation list, and update the
  3128. * next response index to slim. This process makes response
  3129. * iocb's in the ring available to DMA as fast as possible but
  3130. * pays a penalty for a copy operation. Since the iocb is
  3131. * only 32 bytes, this penalty is considered small relative to
  3132. * the PCI reads for register values and a slim write. When
  3133. * the ulpLe field is set, the entire Command has been
  3134. * received.
  3135. */
  3136. entry = lpfc_resp_iocb(phba, pring);
  3137. phba->last_completion_time = jiffies;
  3138. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3139. if (rspiocbp == NULL) {
  3140. printk(KERN_ERR "%s: out of buffers! Failing "
  3141. "completion.\n", __func__);
  3142. break;
  3143. }
  3144. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3145. phba->iocb_rsp_size);
  3146. irsp = &rspiocbp->iocb;
  3147. if (++pring->sli.sli3.rspidx >= portRspMax)
  3148. pring->sli.sli3.rspidx = 0;
  3149. if (pring->ringno == LPFC_ELS_RING) {
  3150. lpfc_debugfs_slow_ring_trc(phba,
  3151. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3152. *(((uint32_t *) irsp) + 4),
  3153. *(((uint32_t *) irsp) + 6),
  3154. *(((uint32_t *) irsp) + 7));
  3155. }
  3156. writel(pring->sli.sli3.rspidx,
  3157. &phba->host_gp[pring->ringno].rspGetInx);
  3158. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3159. /* Handle the response IOCB */
  3160. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3161. spin_lock_irqsave(&phba->hbalock, iflag);
  3162. /*
  3163. * If the port response put pointer has not been updated, sync
  3164. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3165. * response put pointer.
  3166. */
  3167. if (pring->sli.sli3.rspidx == portRspPut) {
  3168. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3169. }
  3170. } /* while (pring->sli.sli3.rspidx != portRspPut) */
  3171. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3172. /* At least one response entry has been freed */
  3173. pring->stats.iocb_rsp_full++;
  3174. /* SET RxRE_RSP in Chip Att register */
  3175. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3176. writel(status, phba->CAregaddr);
  3177. readl(phba->CAregaddr); /* flush */
  3178. }
  3179. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3180. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3181. pring->stats.iocb_cmd_empty++;
  3182. /* Force update of the local copy of cmdGetInx */
  3183. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3184. lpfc_sli_resume_iocb(phba, pring);
  3185. if ((pring->lpfc_sli_cmd_available))
  3186. (pring->lpfc_sli_cmd_available) (phba, pring);
  3187. }
  3188. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3189. return;
  3190. }
  3191. /**
  3192. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3193. * @phba: Pointer to HBA context object.
  3194. * @pring: Pointer to driver SLI ring object.
  3195. * @mask: Host attention register mask for this ring.
  3196. *
  3197. * This function is called from the worker thread when there is a pending
  3198. * ELS response iocb on the driver internal slow-path response iocb worker
  3199. * queue. The caller does not hold any lock. The function will remove each
  3200. * response iocb from the response worker queue and calls the handle
  3201. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3202. **/
  3203. static void
  3204. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3205. struct lpfc_sli_ring *pring, uint32_t mask)
  3206. {
  3207. struct lpfc_iocbq *irspiocbq;
  3208. struct hbq_dmabuf *dmabuf;
  3209. struct lpfc_cq_event *cq_event;
  3210. unsigned long iflag;
  3211. spin_lock_irqsave(&phba->hbalock, iflag);
  3212. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3213. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3214. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3215. /* Get the response iocb from the head of work queue */
  3216. spin_lock_irqsave(&phba->hbalock, iflag);
  3217. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3218. cq_event, struct lpfc_cq_event, list);
  3219. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3220. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3221. case CQE_CODE_COMPL_WQE:
  3222. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3223. cq_event);
  3224. /* Translate ELS WCQE to response IOCBQ */
  3225. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3226. irspiocbq);
  3227. if (irspiocbq)
  3228. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3229. irspiocbq);
  3230. break;
  3231. case CQE_CODE_RECEIVE:
  3232. case CQE_CODE_RECEIVE_V1:
  3233. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3234. cq_event);
  3235. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3236. break;
  3237. default:
  3238. break;
  3239. }
  3240. }
  3241. }
  3242. /**
  3243. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3244. * @phba: Pointer to HBA context object.
  3245. * @pring: Pointer to driver SLI ring object.
  3246. *
  3247. * This function aborts all iocbs in the given ring and frees all the iocb
  3248. * objects in txq. This function issues an abort iocb for all the iocb commands
  3249. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3250. * the return of this function. The caller is not required to hold any locks.
  3251. **/
  3252. void
  3253. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3254. {
  3255. LIST_HEAD(completions);
  3256. struct lpfc_iocbq *iocb, *next_iocb;
  3257. if (pring->ringno == LPFC_ELS_RING) {
  3258. lpfc_fabric_abort_hba(phba);
  3259. }
  3260. /* Error everything on txq and txcmplq
  3261. * First do the txq.
  3262. */
  3263. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3264. spin_lock_irq(&pring->ring_lock);
  3265. list_splice_init(&pring->txq, &completions);
  3266. pring->txq_cnt = 0;
  3267. spin_unlock_irq(&pring->ring_lock);
  3268. spin_lock_irq(&phba->hbalock);
  3269. /* Next issue ABTS for everything on the txcmplq */
  3270. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3271. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3272. spin_unlock_irq(&phba->hbalock);
  3273. } else {
  3274. spin_lock_irq(&phba->hbalock);
  3275. list_splice_init(&pring->txq, &completions);
  3276. pring->txq_cnt = 0;
  3277. /* Next issue ABTS for everything on the txcmplq */
  3278. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3279. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3280. spin_unlock_irq(&phba->hbalock);
  3281. }
  3282. /* Cancel all the IOCBs from the completions list */
  3283. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3284. IOERR_SLI_ABORTED);
  3285. }
  3286. /**
  3287. * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
  3288. * @phba: Pointer to HBA context object.
  3289. * @pring: Pointer to driver SLI ring object.
  3290. *
  3291. * This function aborts all iocbs in FCP rings and frees all the iocb
  3292. * objects in txq. This function issues an abort iocb for all the iocb commands
  3293. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3294. * the return of this function. The caller is not required to hold any locks.
  3295. **/
  3296. void
  3297. lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
  3298. {
  3299. struct lpfc_sli *psli = &phba->sli;
  3300. struct lpfc_sli_ring *pring;
  3301. uint32_t i;
  3302. /* Look on all the FCP Rings for the iotag */
  3303. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3304. for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
  3305. pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS];
  3306. lpfc_sli_abort_iocb_ring(phba, pring);
  3307. }
  3308. } else {
  3309. pring = &psli->ring[psli->fcp_ring];
  3310. lpfc_sli_abort_iocb_ring(phba, pring);
  3311. }
  3312. }
  3313. /**
  3314. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3315. * @phba: Pointer to HBA context object.
  3316. *
  3317. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3318. * objects in txq and txcmplq. This function will not issue abort iocbs
  3319. * for all the iocb commands in txcmplq, they will just be returned with
  3320. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3321. * slot has been permanently disabled.
  3322. **/
  3323. void
  3324. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3325. {
  3326. LIST_HEAD(txq);
  3327. LIST_HEAD(txcmplq);
  3328. struct lpfc_sli *psli = &phba->sli;
  3329. struct lpfc_sli_ring *pring;
  3330. uint32_t i;
  3331. spin_lock_irq(&phba->hbalock);
  3332. /* Indicate the I/O queues are flushed */
  3333. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3334. spin_unlock_irq(&phba->hbalock);
  3335. /* Look on all the FCP Rings for the iotag */
  3336. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3337. for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
  3338. pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS];
  3339. spin_lock_irq(&pring->ring_lock);
  3340. /* Retrieve everything on txq */
  3341. list_splice_init(&pring->txq, &txq);
  3342. /* Retrieve everything on the txcmplq */
  3343. list_splice_init(&pring->txcmplq, &txcmplq);
  3344. pring->txq_cnt = 0;
  3345. pring->txcmplq_cnt = 0;
  3346. spin_unlock_irq(&pring->ring_lock);
  3347. /* Flush the txq */
  3348. lpfc_sli_cancel_iocbs(phba, &txq,
  3349. IOSTAT_LOCAL_REJECT,
  3350. IOERR_SLI_DOWN);
  3351. /* Flush the txcmpq */
  3352. lpfc_sli_cancel_iocbs(phba, &txcmplq,
  3353. IOSTAT_LOCAL_REJECT,
  3354. IOERR_SLI_DOWN);
  3355. }
  3356. } else {
  3357. pring = &psli->ring[psli->fcp_ring];
  3358. spin_lock_irq(&phba->hbalock);
  3359. /* Retrieve everything on txq */
  3360. list_splice_init(&pring->txq, &txq);
  3361. /* Retrieve everything on the txcmplq */
  3362. list_splice_init(&pring->txcmplq, &txcmplq);
  3363. pring->txq_cnt = 0;
  3364. pring->txcmplq_cnt = 0;
  3365. spin_unlock_irq(&phba->hbalock);
  3366. /* Flush the txq */
  3367. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3368. IOERR_SLI_DOWN);
  3369. /* Flush the txcmpq */
  3370. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3371. IOERR_SLI_DOWN);
  3372. }
  3373. }
  3374. /**
  3375. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3376. * @phba: Pointer to HBA context object.
  3377. * @mask: Bit mask to be checked.
  3378. *
  3379. * This function reads the host status register and compares
  3380. * with the provided bit mask to check if HBA completed
  3381. * the restart. This function will wait in a loop for the
  3382. * HBA to complete restart. If the HBA does not restart within
  3383. * 15 iterations, the function will reset the HBA again. The
  3384. * function returns 1 when HBA fail to restart otherwise returns
  3385. * zero.
  3386. **/
  3387. static int
  3388. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3389. {
  3390. uint32_t status;
  3391. int i = 0;
  3392. int retval = 0;
  3393. /* Read the HBA Host Status Register */
  3394. if (lpfc_readl(phba->HSregaddr, &status))
  3395. return 1;
  3396. /*
  3397. * Check status register every 100ms for 5 retries, then every
  3398. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3399. * every 2.5 sec for 4.
  3400. * Break our of the loop if errors occurred during init.
  3401. */
  3402. while (((status & mask) != mask) &&
  3403. !(status & HS_FFERM) &&
  3404. i++ < 20) {
  3405. if (i <= 5)
  3406. msleep(10);
  3407. else if (i <= 10)
  3408. msleep(500);
  3409. else
  3410. msleep(2500);
  3411. if (i == 15) {
  3412. /* Do post */
  3413. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3414. lpfc_sli_brdrestart(phba);
  3415. }
  3416. /* Read the HBA Host Status Register */
  3417. if (lpfc_readl(phba->HSregaddr, &status)) {
  3418. retval = 1;
  3419. break;
  3420. }
  3421. }
  3422. /* Check to see if any errors occurred during init */
  3423. if ((status & HS_FFERM) || (i >= 20)) {
  3424. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3425. "2751 Adapter failed to restart, "
  3426. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3427. status,
  3428. readl(phba->MBslimaddr + 0xa8),
  3429. readl(phba->MBslimaddr + 0xac));
  3430. phba->link_state = LPFC_HBA_ERROR;
  3431. retval = 1;
  3432. }
  3433. return retval;
  3434. }
  3435. /**
  3436. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3437. * @phba: Pointer to HBA context object.
  3438. * @mask: Bit mask to be checked.
  3439. *
  3440. * This function checks the host status register to check if HBA is
  3441. * ready. This function will wait in a loop for the HBA to be ready
  3442. * If the HBA is not ready , the function will will reset the HBA PCI
  3443. * function again. The function returns 1 when HBA fail to be ready
  3444. * otherwise returns zero.
  3445. **/
  3446. static int
  3447. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3448. {
  3449. uint32_t status;
  3450. int retval = 0;
  3451. /* Read the HBA Host Status Register */
  3452. status = lpfc_sli4_post_status_check(phba);
  3453. if (status) {
  3454. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3455. lpfc_sli_brdrestart(phba);
  3456. status = lpfc_sli4_post_status_check(phba);
  3457. }
  3458. /* Check to see if any errors occurred during init */
  3459. if (status) {
  3460. phba->link_state = LPFC_HBA_ERROR;
  3461. retval = 1;
  3462. } else
  3463. phba->sli4_hba.intr_enable = 0;
  3464. return retval;
  3465. }
  3466. /**
  3467. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3468. * @phba: Pointer to HBA context object.
  3469. * @mask: Bit mask to be checked.
  3470. *
  3471. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3472. * from the API jump table function pointer from the lpfc_hba struct.
  3473. **/
  3474. int
  3475. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3476. {
  3477. return phba->lpfc_sli_brdready(phba, mask);
  3478. }
  3479. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3480. /**
  3481. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3482. * @phba: Pointer to HBA context object.
  3483. *
  3484. * This function is called before resetting an HBA. This function is called
  3485. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3486. **/
  3487. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3488. {
  3489. uint32_t __iomem *resp_buf;
  3490. uint32_t __iomem *mbox_buf;
  3491. volatile uint32_t mbox;
  3492. uint32_t hc_copy, ha_copy, resp_data;
  3493. int i;
  3494. uint8_t hdrtype;
  3495. lockdep_assert_held(&phba->hbalock);
  3496. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3497. if (hdrtype != 0x80 ||
  3498. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3499. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3500. return;
  3501. /*
  3502. * Tell the other part of the chip to suspend temporarily all
  3503. * its DMA activity.
  3504. */
  3505. resp_buf = phba->MBslimaddr;
  3506. /* Disable the error attention */
  3507. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3508. return;
  3509. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3510. readl(phba->HCregaddr); /* flush */
  3511. phba->link_flag |= LS_IGNORE_ERATT;
  3512. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3513. return;
  3514. if (ha_copy & HA_ERATT) {
  3515. /* Clear Chip error bit */
  3516. writel(HA_ERATT, phba->HAregaddr);
  3517. phba->pport->stopped = 1;
  3518. }
  3519. mbox = 0;
  3520. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3521. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3522. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3523. mbox_buf = phba->MBslimaddr;
  3524. writel(mbox, mbox_buf);
  3525. for (i = 0; i < 50; i++) {
  3526. if (lpfc_readl((resp_buf + 1), &resp_data))
  3527. return;
  3528. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3529. mdelay(1);
  3530. else
  3531. break;
  3532. }
  3533. resp_data = 0;
  3534. if (lpfc_readl((resp_buf + 1), &resp_data))
  3535. return;
  3536. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3537. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3538. phba->pport->stopped)
  3539. goto restore_hc;
  3540. else
  3541. goto clear_errat;
  3542. }
  3543. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3544. resp_data = 0;
  3545. for (i = 0; i < 500; i++) {
  3546. if (lpfc_readl(resp_buf, &resp_data))
  3547. return;
  3548. if (resp_data != mbox)
  3549. mdelay(1);
  3550. else
  3551. break;
  3552. }
  3553. clear_errat:
  3554. while (++i < 500) {
  3555. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3556. return;
  3557. if (!(ha_copy & HA_ERATT))
  3558. mdelay(1);
  3559. else
  3560. break;
  3561. }
  3562. if (readl(phba->HAregaddr) & HA_ERATT) {
  3563. writel(HA_ERATT, phba->HAregaddr);
  3564. phba->pport->stopped = 1;
  3565. }
  3566. restore_hc:
  3567. phba->link_flag &= ~LS_IGNORE_ERATT;
  3568. writel(hc_copy, phba->HCregaddr);
  3569. readl(phba->HCregaddr); /* flush */
  3570. }
  3571. /**
  3572. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3573. * @phba: Pointer to HBA context object.
  3574. *
  3575. * This function issues a kill_board mailbox command and waits for
  3576. * the error attention interrupt. This function is called for stopping
  3577. * the firmware processing. The caller is not required to hold any
  3578. * locks. This function calls lpfc_hba_down_post function to free
  3579. * any pending commands after the kill. The function will return 1 when it
  3580. * fails to kill the board else will return 0.
  3581. **/
  3582. int
  3583. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3584. {
  3585. struct lpfc_sli *psli;
  3586. LPFC_MBOXQ_t *pmb;
  3587. uint32_t status;
  3588. uint32_t ha_copy;
  3589. int retval;
  3590. int i = 0;
  3591. psli = &phba->sli;
  3592. /* Kill HBA */
  3593. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3594. "0329 Kill HBA Data: x%x x%x\n",
  3595. phba->pport->port_state, psli->sli_flag);
  3596. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3597. if (!pmb)
  3598. return 1;
  3599. /* Disable the error attention */
  3600. spin_lock_irq(&phba->hbalock);
  3601. if (lpfc_readl(phba->HCregaddr, &status)) {
  3602. spin_unlock_irq(&phba->hbalock);
  3603. mempool_free(pmb, phba->mbox_mem_pool);
  3604. return 1;
  3605. }
  3606. status &= ~HC_ERINT_ENA;
  3607. writel(status, phba->HCregaddr);
  3608. readl(phba->HCregaddr); /* flush */
  3609. phba->link_flag |= LS_IGNORE_ERATT;
  3610. spin_unlock_irq(&phba->hbalock);
  3611. lpfc_kill_board(phba, pmb);
  3612. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3613. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3614. if (retval != MBX_SUCCESS) {
  3615. if (retval != MBX_BUSY)
  3616. mempool_free(pmb, phba->mbox_mem_pool);
  3617. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3618. "2752 KILL_BOARD command failed retval %d\n",
  3619. retval);
  3620. spin_lock_irq(&phba->hbalock);
  3621. phba->link_flag &= ~LS_IGNORE_ERATT;
  3622. spin_unlock_irq(&phba->hbalock);
  3623. return 1;
  3624. }
  3625. spin_lock_irq(&phba->hbalock);
  3626. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3627. spin_unlock_irq(&phba->hbalock);
  3628. mempool_free(pmb, phba->mbox_mem_pool);
  3629. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3630. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3631. * 3 seconds we still set HBA_ERROR state because the status of the
  3632. * board is now undefined.
  3633. */
  3634. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3635. return 1;
  3636. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3637. mdelay(100);
  3638. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3639. return 1;
  3640. }
  3641. del_timer_sync(&psli->mbox_tmo);
  3642. if (ha_copy & HA_ERATT) {
  3643. writel(HA_ERATT, phba->HAregaddr);
  3644. phba->pport->stopped = 1;
  3645. }
  3646. spin_lock_irq(&phba->hbalock);
  3647. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3648. psli->mbox_active = NULL;
  3649. phba->link_flag &= ~LS_IGNORE_ERATT;
  3650. spin_unlock_irq(&phba->hbalock);
  3651. lpfc_hba_down_post(phba);
  3652. phba->link_state = LPFC_HBA_ERROR;
  3653. return ha_copy & HA_ERATT ? 0 : 1;
  3654. }
  3655. /**
  3656. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3657. * @phba: Pointer to HBA context object.
  3658. *
  3659. * This function resets the HBA by writing HC_INITFF to the control
  3660. * register. After the HBA resets, this function resets all the iocb ring
  3661. * indices. This function disables PCI layer parity checking during
  3662. * the reset.
  3663. * This function returns 0 always.
  3664. * The caller is not required to hold any locks.
  3665. **/
  3666. int
  3667. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3668. {
  3669. struct lpfc_sli *psli;
  3670. struct lpfc_sli_ring *pring;
  3671. uint16_t cfg_value;
  3672. int i;
  3673. psli = &phba->sli;
  3674. /* Reset HBA */
  3675. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3676. "0325 Reset HBA Data: x%x x%x\n",
  3677. phba->pport->port_state, psli->sli_flag);
  3678. /* perform board reset */
  3679. phba->fc_eventTag = 0;
  3680. phba->link_events = 0;
  3681. phba->pport->fc_myDID = 0;
  3682. phba->pport->fc_prevDID = 0;
  3683. /* Turn off parity checking and serr during the physical reset */
  3684. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3685. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3686. (cfg_value &
  3687. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3688. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3689. /* Now toggle INITFF bit in the Host Control Register */
  3690. writel(HC_INITFF, phba->HCregaddr);
  3691. mdelay(1);
  3692. readl(phba->HCregaddr); /* flush */
  3693. writel(0, phba->HCregaddr);
  3694. readl(phba->HCregaddr); /* flush */
  3695. /* Restore PCI cmd register */
  3696. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3697. /* Initialize relevant SLI info */
  3698. for (i = 0; i < psli->num_rings; i++) {
  3699. pring = &psli->ring[i];
  3700. pring->flag = 0;
  3701. pring->sli.sli3.rspidx = 0;
  3702. pring->sli.sli3.next_cmdidx = 0;
  3703. pring->sli.sli3.local_getidx = 0;
  3704. pring->sli.sli3.cmdidx = 0;
  3705. pring->missbufcnt = 0;
  3706. }
  3707. phba->link_state = LPFC_WARM_START;
  3708. return 0;
  3709. }
  3710. /**
  3711. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3712. * @phba: Pointer to HBA context object.
  3713. *
  3714. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3715. * checking during resets the device. The caller is not required to hold
  3716. * any locks.
  3717. *
  3718. * This function returns 0 always.
  3719. **/
  3720. int
  3721. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3722. {
  3723. struct lpfc_sli *psli = &phba->sli;
  3724. uint16_t cfg_value;
  3725. int rc = 0;
  3726. /* Reset HBA */
  3727. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3728. "0295 Reset HBA Data: x%x x%x x%x\n",
  3729. phba->pport->port_state, psli->sli_flag,
  3730. phba->hba_flag);
  3731. /* perform board reset */
  3732. phba->fc_eventTag = 0;
  3733. phba->link_events = 0;
  3734. phba->pport->fc_myDID = 0;
  3735. phba->pport->fc_prevDID = 0;
  3736. spin_lock_irq(&phba->hbalock);
  3737. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3738. phba->fcf.fcf_flag = 0;
  3739. spin_unlock_irq(&phba->hbalock);
  3740. /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
  3741. if (phba->hba_flag & HBA_FW_DUMP_OP) {
  3742. phba->hba_flag &= ~HBA_FW_DUMP_OP;
  3743. return rc;
  3744. }
  3745. /* Now physically reset the device */
  3746. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3747. "0389 Performing PCI function reset!\n");
  3748. /* Turn off parity checking and serr during the physical reset */
  3749. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3750. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3751. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3752. /* Perform FCoE PCI function reset before freeing queue memory */
  3753. rc = lpfc_pci_function_reset(phba);
  3754. lpfc_sli4_queue_destroy(phba);
  3755. /* Restore PCI cmd register */
  3756. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3757. return rc;
  3758. }
  3759. /**
  3760. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3761. * @phba: Pointer to HBA context object.
  3762. *
  3763. * This function is called in the SLI initialization code path to
  3764. * restart the HBA. The caller is not required to hold any lock.
  3765. * This function writes MBX_RESTART mailbox command to the SLIM and
  3766. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3767. * function to free any pending commands. The function enables
  3768. * POST only during the first initialization. The function returns zero.
  3769. * The function does not guarantee completion of MBX_RESTART mailbox
  3770. * command before the return of this function.
  3771. **/
  3772. static int
  3773. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3774. {
  3775. MAILBOX_t *mb;
  3776. struct lpfc_sli *psli;
  3777. volatile uint32_t word0;
  3778. void __iomem *to_slim;
  3779. uint32_t hba_aer_enabled;
  3780. spin_lock_irq(&phba->hbalock);
  3781. /* Take PCIe device Advanced Error Reporting (AER) state */
  3782. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3783. psli = &phba->sli;
  3784. /* Restart HBA */
  3785. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3786. "0337 Restart HBA Data: x%x x%x\n",
  3787. phba->pport->port_state, psli->sli_flag);
  3788. word0 = 0;
  3789. mb = (MAILBOX_t *) &word0;
  3790. mb->mbxCommand = MBX_RESTART;
  3791. mb->mbxHc = 1;
  3792. lpfc_reset_barrier(phba);
  3793. to_slim = phba->MBslimaddr;
  3794. writel(*(uint32_t *) mb, to_slim);
  3795. readl(to_slim); /* flush */
  3796. /* Only skip post after fc_ffinit is completed */
  3797. if (phba->pport->port_state)
  3798. word0 = 1; /* This is really setting up word1 */
  3799. else
  3800. word0 = 0; /* This is really setting up word1 */
  3801. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3802. writel(*(uint32_t *) mb, to_slim);
  3803. readl(to_slim); /* flush */
  3804. lpfc_sli_brdreset(phba);
  3805. phba->pport->stopped = 0;
  3806. phba->link_state = LPFC_INIT_START;
  3807. phba->hba_flag = 0;
  3808. spin_unlock_irq(&phba->hbalock);
  3809. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3810. psli->stats_start = get_seconds();
  3811. /* Give the INITFF and Post time to settle. */
  3812. mdelay(100);
  3813. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3814. if (hba_aer_enabled)
  3815. pci_disable_pcie_error_reporting(phba->pcidev);
  3816. lpfc_hba_down_post(phba);
  3817. return 0;
  3818. }
  3819. /**
  3820. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3821. * @phba: Pointer to HBA context object.
  3822. *
  3823. * This function is called in the SLI initialization code path to restart
  3824. * a SLI4 HBA. The caller is not required to hold any lock.
  3825. * At the end of the function, it calls lpfc_hba_down_post function to
  3826. * free any pending commands.
  3827. **/
  3828. static int
  3829. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3830. {
  3831. struct lpfc_sli *psli = &phba->sli;
  3832. uint32_t hba_aer_enabled;
  3833. int rc;
  3834. /* Restart HBA */
  3835. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3836. "0296 Restart HBA Data: x%x x%x\n",
  3837. phba->pport->port_state, psli->sli_flag);
  3838. /* Take PCIe device Advanced Error Reporting (AER) state */
  3839. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3840. rc = lpfc_sli4_brdreset(phba);
  3841. spin_lock_irq(&phba->hbalock);
  3842. phba->pport->stopped = 0;
  3843. phba->link_state = LPFC_INIT_START;
  3844. phba->hba_flag = 0;
  3845. spin_unlock_irq(&phba->hbalock);
  3846. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3847. psli->stats_start = get_seconds();
  3848. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3849. if (hba_aer_enabled)
  3850. pci_disable_pcie_error_reporting(phba->pcidev);
  3851. lpfc_hba_down_post(phba);
  3852. return rc;
  3853. }
  3854. /**
  3855. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3856. * @phba: Pointer to HBA context object.
  3857. *
  3858. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3859. * API jump table function pointer from the lpfc_hba struct.
  3860. **/
  3861. int
  3862. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3863. {
  3864. return phba->lpfc_sli_brdrestart(phba);
  3865. }
  3866. /**
  3867. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3868. * @phba: Pointer to HBA context object.
  3869. *
  3870. * This function is called after a HBA restart to wait for successful
  3871. * restart of the HBA. Successful restart of the HBA is indicated by
  3872. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3873. * iteration, the function will restart the HBA again. The function returns
  3874. * zero if HBA successfully restarted else returns negative error code.
  3875. **/
  3876. static int
  3877. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3878. {
  3879. uint32_t status, i = 0;
  3880. /* Read the HBA Host Status Register */
  3881. if (lpfc_readl(phba->HSregaddr, &status))
  3882. return -EIO;
  3883. /* Check status register to see what current state is */
  3884. i = 0;
  3885. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3886. /* Check every 10ms for 10 retries, then every 100ms for 90
  3887. * retries, then every 1 sec for 50 retires for a total of
  3888. * ~60 seconds before reset the board again and check every
  3889. * 1 sec for 50 retries. The up to 60 seconds before the
  3890. * board ready is required by the Falcon FIPS zeroization
  3891. * complete, and any reset the board in between shall cause
  3892. * restart of zeroization, further delay the board ready.
  3893. */
  3894. if (i++ >= 200) {
  3895. /* Adapter failed to init, timeout, status reg
  3896. <status> */
  3897. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3898. "0436 Adapter failed to init, "
  3899. "timeout, status reg x%x, "
  3900. "FW Data: A8 x%x AC x%x\n", status,
  3901. readl(phba->MBslimaddr + 0xa8),
  3902. readl(phba->MBslimaddr + 0xac));
  3903. phba->link_state = LPFC_HBA_ERROR;
  3904. return -ETIMEDOUT;
  3905. }
  3906. /* Check to see if any errors occurred during init */
  3907. if (status & HS_FFERM) {
  3908. /* ERROR: During chipset initialization */
  3909. /* Adapter failed to init, chipset, status reg
  3910. <status> */
  3911. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3912. "0437 Adapter failed to init, "
  3913. "chipset, status reg x%x, "
  3914. "FW Data: A8 x%x AC x%x\n", status,
  3915. readl(phba->MBslimaddr + 0xa8),
  3916. readl(phba->MBslimaddr + 0xac));
  3917. phba->link_state = LPFC_HBA_ERROR;
  3918. return -EIO;
  3919. }
  3920. if (i <= 10)
  3921. msleep(10);
  3922. else if (i <= 100)
  3923. msleep(100);
  3924. else
  3925. msleep(1000);
  3926. if (i == 150) {
  3927. /* Do post */
  3928. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3929. lpfc_sli_brdrestart(phba);
  3930. }
  3931. /* Read the HBA Host Status Register */
  3932. if (lpfc_readl(phba->HSregaddr, &status))
  3933. return -EIO;
  3934. }
  3935. /* Check to see if any errors occurred during init */
  3936. if (status & HS_FFERM) {
  3937. /* ERROR: During chipset initialization */
  3938. /* Adapter failed to init, chipset, status reg <status> */
  3939. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3940. "0438 Adapter failed to init, chipset, "
  3941. "status reg x%x, "
  3942. "FW Data: A8 x%x AC x%x\n", status,
  3943. readl(phba->MBslimaddr + 0xa8),
  3944. readl(phba->MBslimaddr + 0xac));
  3945. phba->link_state = LPFC_HBA_ERROR;
  3946. return -EIO;
  3947. }
  3948. /* Clear all interrupt enable conditions */
  3949. writel(0, phba->HCregaddr);
  3950. readl(phba->HCregaddr); /* flush */
  3951. /* setup host attn register */
  3952. writel(0xffffffff, phba->HAregaddr);
  3953. readl(phba->HAregaddr); /* flush */
  3954. return 0;
  3955. }
  3956. /**
  3957. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3958. *
  3959. * This function calculates and returns the number of HBQs required to be
  3960. * configured.
  3961. **/
  3962. int
  3963. lpfc_sli_hbq_count(void)
  3964. {
  3965. return ARRAY_SIZE(lpfc_hbq_defs);
  3966. }
  3967. /**
  3968. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3969. *
  3970. * This function adds the number of hbq entries in every HBQ to get
  3971. * the total number of hbq entries required for the HBA and returns
  3972. * the total count.
  3973. **/
  3974. static int
  3975. lpfc_sli_hbq_entry_count(void)
  3976. {
  3977. int hbq_count = lpfc_sli_hbq_count();
  3978. int count = 0;
  3979. int i;
  3980. for (i = 0; i < hbq_count; ++i)
  3981. count += lpfc_hbq_defs[i]->entry_count;
  3982. return count;
  3983. }
  3984. /**
  3985. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3986. *
  3987. * This function calculates amount of memory required for all hbq entries
  3988. * to be configured and returns the total memory required.
  3989. **/
  3990. int
  3991. lpfc_sli_hbq_size(void)
  3992. {
  3993. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3994. }
  3995. /**
  3996. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3997. * @phba: Pointer to HBA context object.
  3998. *
  3999. * This function is called during the SLI initialization to configure
  4000. * all the HBQs and post buffers to the HBQ. The caller is not
  4001. * required to hold any locks. This function will return zero if successful
  4002. * else it will return negative error code.
  4003. **/
  4004. static int
  4005. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  4006. {
  4007. int hbq_count = lpfc_sli_hbq_count();
  4008. LPFC_MBOXQ_t *pmb;
  4009. MAILBOX_t *pmbox;
  4010. uint32_t hbqno;
  4011. uint32_t hbq_entry_index;
  4012. /* Get a Mailbox buffer to setup mailbox
  4013. * commands for HBA initialization
  4014. */
  4015. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4016. if (!pmb)
  4017. return -ENOMEM;
  4018. pmbox = &pmb->u.mb;
  4019. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  4020. phba->link_state = LPFC_INIT_MBX_CMDS;
  4021. phba->hbq_in_use = 1;
  4022. hbq_entry_index = 0;
  4023. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  4024. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  4025. phba->hbqs[hbqno].hbqPutIdx = 0;
  4026. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  4027. phba->hbqs[hbqno].entry_count =
  4028. lpfc_hbq_defs[hbqno]->entry_count;
  4029. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  4030. hbq_entry_index, pmb);
  4031. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  4032. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  4033. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  4034. mbxStatus <status>, ring <num> */
  4035. lpfc_printf_log(phba, KERN_ERR,
  4036. LOG_SLI | LOG_VPORT,
  4037. "1805 Adapter failed to init. "
  4038. "Data: x%x x%x x%x\n",
  4039. pmbox->mbxCommand,
  4040. pmbox->mbxStatus, hbqno);
  4041. phba->link_state = LPFC_HBA_ERROR;
  4042. mempool_free(pmb, phba->mbox_mem_pool);
  4043. return -ENXIO;
  4044. }
  4045. }
  4046. phba->hbq_count = hbq_count;
  4047. mempool_free(pmb, phba->mbox_mem_pool);
  4048. /* Initially populate or replenish the HBQs */
  4049. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  4050. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  4051. return 0;
  4052. }
  4053. /**
  4054. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  4055. * @phba: Pointer to HBA context object.
  4056. *
  4057. * This function is called during the SLI initialization to configure
  4058. * all the HBQs and post buffers to the HBQ. The caller is not
  4059. * required to hold any locks. This function will return zero if successful
  4060. * else it will return negative error code.
  4061. **/
  4062. static int
  4063. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  4064. {
  4065. phba->hbq_in_use = 1;
  4066. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  4067. phba->hbq_count = 1;
  4068. /* Initially populate or replenish the HBQs */
  4069. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  4070. return 0;
  4071. }
  4072. /**
  4073. * lpfc_sli_config_port - Issue config port mailbox command
  4074. * @phba: Pointer to HBA context object.
  4075. * @sli_mode: sli mode - 2/3
  4076. *
  4077. * This function is called by the sli intialization code path
  4078. * to issue config_port mailbox command. This function restarts the
  4079. * HBA firmware and issues a config_port mailbox command to configure
  4080. * the SLI interface in the sli mode specified by sli_mode
  4081. * variable. The caller is not required to hold any locks.
  4082. * The function returns 0 if successful, else returns negative error
  4083. * code.
  4084. **/
  4085. int
  4086. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  4087. {
  4088. LPFC_MBOXQ_t *pmb;
  4089. uint32_t resetcount = 0, rc = 0, done = 0;
  4090. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4091. if (!pmb) {
  4092. phba->link_state = LPFC_HBA_ERROR;
  4093. return -ENOMEM;
  4094. }
  4095. phba->sli_rev = sli_mode;
  4096. while (resetcount < 2 && !done) {
  4097. spin_lock_irq(&phba->hbalock);
  4098. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4099. spin_unlock_irq(&phba->hbalock);
  4100. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  4101. lpfc_sli_brdrestart(phba);
  4102. rc = lpfc_sli_chipset_init(phba);
  4103. if (rc)
  4104. break;
  4105. spin_lock_irq(&phba->hbalock);
  4106. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4107. spin_unlock_irq(&phba->hbalock);
  4108. resetcount++;
  4109. /* Call pre CONFIG_PORT mailbox command initialization. A
  4110. * value of 0 means the call was successful. Any other
  4111. * nonzero value is a failure, but if ERESTART is returned,
  4112. * the driver may reset the HBA and try again.
  4113. */
  4114. rc = lpfc_config_port_prep(phba);
  4115. if (rc == -ERESTART) {
  4116. phba->link_state = LPFC_LINK_UNKNOWN;
  4117. continue;
  4118. } else if (rc)
  4119. break;
  4120. phba->link_state = LPFC_INIT_MBX_CMDS;
  4121. lpfc_config_port(phba, pmb);
  4122. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4123. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  4124. LPFC_SLI3_HBQ_ENABLED |
  4125. LPFC_SLI3_CRP_ENABLED |
  4126. LPFC_SLI3_BG_ENABLED |
  4127. LPFC_SLI3_DSS_ENABLED);
  4128. if (rc != MBX_SUCCESS) {
  4129. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4130. "0442 Adapter failed to init, mbxCmd x%x "
  4131. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  4132. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  4133. spin_lock_irq(&phba->hbalock);
  4134. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  4135. spin_unlock_irq(&phba->hbalock);
  4136. rc = -ENXIO;
  4137. } else {
  4138. /* Allow asynchronous mailbox command to go through */
  4139. spin_lock_irq(&phba->hbalock);
  4140. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4141. spin_unlock_irq(&phba->hbalock);
  4142. done = 1;
  4143. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  4144. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  4145. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4146. "3110 Port did not grant ASABT\n");
  4147. }
  4148. }
  4149. if (!done) {
  4150. rc = -EINVAL;
  4151. goto do_prep_failed;
  4152. }
  4153. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  4154. if (!pmb->u.mb.un.varCfgPort.cMA) {
  4155. rc = -ENXIO;
  4156. goto do_prep_failed;
  4157. }
  4158. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  4159. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  4160. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  4161. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  4162. phba->max_vpi : phba->max_vports;
  4163. } else
  4164. phba->max_vpi = 0;
  4165. phba->fips_level = 0;
  4166. phba->fips_spec_rev = 0;
  4167. if (pmb->u.mb.un.varCfgPort.gdss) {
  4168. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  4169. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  4170. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  4171. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4172. "2850 Security Crypto Active. FIPS x%d "
  4173. "(Spec Rev: x%d)",
  4174. phba->fips_level, phba->fips_spec_rev);
  4175. }
  4176. if (pmb->u.mb.un.varCfgPort.sec_err) {
  4177. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4178. "2856 Config Port Security Crypto "
  4179. "Error: x%x ",
  4180. pmb->u.mb.un.varCfgPort.sec_err);
  4181. }
  4182. if (pmb->u.mb.un.varCfgPort.gerbm)
  4183. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  4184. if (pmb->u.mb.un.varCfgPort.gcrp)
  4185. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  4186. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  4187. phba->port_gp = phba->mbox->us.s3_pgp.port;
  4188. if (phba->cfg_enable_bg) {
  4189. if (pmb->u.mb.un.varCfgPort.gbg)
  4190. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  4191. else
  4192. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4193. "0443 Adapter did not grant "
  4194. "BlockGuard\n");
  4195. }
  4196. } else {
  4197. phba->hbq_get = NULL;
  4198. phba->port_gp = phba->mbox->us.s2.port;
  4199. phba->max_vpi = 0;
  4200. }
  4201. do_prep_failed:
  4202. mempool_free(pmb, phba->mbox_mem_pool);
  4203. return rc;
  4204. }
  4205. /**
  4206. * lpfc_sli_hba_setup - SLI intialization function
  4207. * @phba: Pointer to HBA context object.
  4208. *
  4209. * This function is the main SLI intialization function. This function
  4210. * is called by the HBA intialization code, HBA reset code and HBA
  4211. * error attention handler code. Caller is not required to hold any
  4212. * locks. This function issues config_port mailbox command to configure
  4213. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4214. * calls the config_port_post function to issue init_link mailbox
  4215. * command and to start the discovery. The function will return zero
  4216. * if successful, else it will return negative error code.
  4217. **/
  4218. int
  4219. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4220. {
  4221. uint32_t rc;
  4222. int mode = 3, i;
  4223. int longs;
  4224. switch (phba->cfg_sli_mode) {
  4225. case 2:
  4226. if (phba->cfg_enable_npiv) {
  4227. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4228. "1824 NPIV enabled: Override sli_mode "
  4229. "parameter (%d) to auto (0).\n",
  4230. phba->cfg_sli_mode);
  4231. break;
  4232. }
  4233. mode = 2;
  4234. break;
  4235. case 0:
  4236. case 3:
  4237. break;
  4238. default:
  4239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4240. "1819 Unrecognized sli_mode parameter: %d.\n",
  4241. phba->cfg_sli_mode);
  4242. break;
  4243. }
  4244. phba->fcp_embed_io = 0; /* SLI4 FC support only */
  4245. rc = lpfc_sli_config_port(phba, mode);
  4246. if (rc && phba->cfg_sli_mode == 3)
  4247. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4248. "1820 Unable to select SLI-3. "
  4249. "Not supported by adapter.\n");
  4250. if (rc && mode != 2)
  4251. rc = lpfc_sli_config_port(phba, 2);
  4252. else if (rc && mode == 2)
  4253. rc = lpfc_sli_config_port(phba, 3);
  4254. if (rc)
  4255. goto lpfc_sli_hba_setup_error;
  4256. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4257. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4258. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4259. if (!rc) {
  4260. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4261. "2709 This device supports "
  4262. "Advanced Error Reporting (AER)\n");
  4263. spin_lock_irq(&phba->hbalock);
  4264. phba->hba_flag |= HBA_AER_ENABLED;
  4265. spin_unlock_irq(&phba->hbalock);
  4266. } else {
  4267. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4268. "2708 This device does not support "
  4269. "Advanced Error Reporting (AER): %d\n",
  4270. rc);
  4271. phba->cfg_aer_support = 0;
  4272. }
  4273. }
  4274. if (phba->sli_rev == 3) {
  4275. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4276. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4277. } else {
  4278. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4279. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4280. phba->sli3_options = 0;
  4281. }
  4282. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4283. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4284. phba->sli_rev, phba->max_vpi);
  4285. rc = lpfc_sli_ring_map(phba);
  4286. if (rc)
  4287. goto lpfc_sli_hba_setup_error;
  4288. /* Initialize VPIs. */
  4289. if (phba->sli_rev == LPFC_SLI_REV3) {
  4290. /*
  4291. * The VPI bitmask and physical ID array are allocated
  4292. * and initialized once only - at driver load. A port
  4293. * reset doesn't need to reinitialize this memory.
  4294. */
  4295. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4296. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4297. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4298. GFP_KERNEL);
  4299. if (!phba->vpi_bmask) {
  4300. rc = -ENOMEM;
  4301. goto lpfc_sli_hba_setup_error;
  4302. }
  4303. phba->vpi_ids = kzalloc(
  4304. (phba->max_vpi+1) * sizeof(uint16_t),
  4305. GFP_KERNEL);
  4306. if (!phba->vpi_ids) {
  4307. kfree(phba->vpi_bmask);
  4308. rc = -ENOMEM;
  4309. goto lpfc_sli_hba_setup_error;
  4310. }
  4311. for (i = 0; i < phba->max_vpi; i++)
  4312. phba->vpi_ids[i] = i;
  4313. }
  4314. }
  4315. /* Init HBQs */
  4316. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4317. rc = lpfc_sli_hbq_setup(phba);
  4318. if (rc)
  4319. goto lpfc_sli_hba_setup_error;
  4320. }
  4321. spin_lock_irq(&phba->hbalock);
  4322. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4323. spin_unlock_irq(&phba->hbalock);
  4324. rc = lpfc_config_port_post(phba);
  4325. if (rc)
  4326. goto lpfc_sli_hba_setup_error;
  4327. return rc;
  4328. lpfc_sli_hba_setup_error:
  4329. phba->link_state = LPFC_HBA_ERROR;
  4330. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4331. "0445 Firmware initialization failed\n");
  4332. return rc;
  4333. }
  4334. /**
  4335. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4336. * @phba: Pointer to HBA context object.
  4337. * @mboxq: mailbox pointer.
  4338. * This function issue a dump mailbox command to read config region
  4339. * 23 and parse the records in the region and populate driver
  4340. * data structure.
  4341. **/
  4342. static int
  4343. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4344. {
  4345. LPFC_MBOXQ_t *mboxq;
  4346. struct lpfc_dmabuf *mp;
  4347. struct lpfc_mqe *mqe;
  4348. uint32_t data_length;
  4349. int rc;
  4350. /* Program the default value of vlan_id and fc_map */
  4351. phba->valid_vlan = 0;
  4352. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4353. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4354. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4355. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4356. if (!mboxq)
  4357. return -ENOMEM;
  4358. mqe = &mboxq->u.mqe;
  4359. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4360. rc = -ENOMEM;
  4361. goto out_free_mboxq;
  4362. }
  4363. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4364. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4365. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4366. "(%d):2571 Mailbox cmd x%x Status x%x "
  4367. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4368. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4369. "CQ: x%x x%x x%x x%x\n",
  4370. mboxq->vport ? mboxq->vport->vpi : 0,
  4371. bf_get(lpfc_mqe_command, mqe),
  4372. bf_get(lpfc_mqe_status, mqe),
  4373. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4374. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4375. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4376. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4377. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4378. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4379. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4380. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4381. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4382. mboxq->mcqe.word0,
  4383. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4384. mboxq->mcqe.trailer);
  4385. if (rc) {
  4386. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4387. kfree(mp);
  4388. rc = -EIO;
  4389. goto out_free_mboxq;
  4390. }
  4391. data_length = mqe->un.mb_words[5];
  4392. if (data_length > DMP_RGN23_SIZE) {
  4393. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4394. kfree(mp);
  4395. rc = -EIO;
  4396. goto out_free_mboxq;
  4397. }
  4398. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4399. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4400. kfree(mp);
  4401. rc = 0;
  4402. out_free_mboxq:
  4403. mempool_free(mboxq, phba->mbox_mem_pool);
  4404. return rc;
  4405. }
  4406. /**
  4407. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4408. * @phba: pointer to lpfc hba data structure.
  4409. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4410. * @vpd: pointer to the memory to hold resulting port vpd data.
  4411. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4412. * On output, the number of data bytes in @vpd.
  4413. *
  4414. * This routine executes a READ_REV SLI4 mailbox command. In
  4415. * addition, this routine gets the port vpd data.
  4416. *
  4417. * Return codes
  4418. * 0 - successful
  4419. * -ENOMEM - could not allocated memory.
  4420. **/
  4421. static int
  4422. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4423. uint8_t *vpd, uint32_t *vpd_size)
  4424. {
  4425. int rc = 0;
  4426. uint32_t dma_size;
  4427. struct lpfc_dmabuf *dmabuf;
  4428. struct lpfc_mqe *mqe;
  4429. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4430. if (!dmabuf)
  4431. return -ENOMEM;
  4432. /*
  4433. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4434. * mailbox command.
  4435. */
  4436. dma_size = *vpd_size;
  4437. dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size,
  4438. &dmabuf->phys, GFP_KERNEL);
  4439. if (!dmabuf->virt) {
  4440. kfree(dmabuf);
  4441. return -ENOMEM;
  4442. }
  4443. /*
  4444. * The SLI4 implementation of READ_REV conflicts at word1,
  4445. * bits 31:16 and SLI4 adds vpd functionality not present
  4446. * in SLI3. This code corrects the conflicts.
  4447. */
  4448. lpfc_read_rev(phba, mboxq);
  4449. mqe = &mboxq->u.mqe;
  4450. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4451. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4452. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4453. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4454. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4455. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4456. if (rc) {
  4457. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4458. dmabuf->virt, dmabuf->phys);
  4459. kfree(dmabuf);
  4460. return -EIO;
  4461. }
  4462. /*
  4463. * The available vpd length cannot be bigger than the
  4464. * DMA buffer passed to the port. Catch the less than
  4465. * case and update the caller's size.
  4466. */
  4467. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4468. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4469. memcpy(vpd, dmabuf->virt, *vpd_size);
  4470. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4471. dmabuf->virt, dmabuf->phys);
  4472. kfree(dmabuf);
  4473. return 0;
  4474. }
  4475. /**
  4476. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4477. * @phba: pointer to lpfc hba data structure.
  4478. *
  4479. * This routine retrieves SLI4 device physical port name this PCI function
  4480. * is attached to.
  4481. *
  4482. * Return codes
  4483. * 0 - successful
  4484. * otherwise - failed to retrieve physical port name
  4485. **/
  4486. static int
  4487. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4488. {
  4489. LPFC_MBOXQ_t *mboxq;
  4490. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4491. struct lpfc_controller_attribute *cntl_attr;
  4492. struct lpfc_mbx_get_port_name *get_port_name;
  4493. void *virtaddr = NULL;
  4494. uint32_t alloclen, reqlen;
  4495. uint32_t shdr_status, shdr_add_status;
  4496. union lpfc_sli4_cfg_shdr *shdr;
  4497. char cport_name = 0;
  4498. int rc;
  4499. /* We assume nothing at this point */
  4500. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4501. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4502. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4503. if (!mboxq)
  4504. return -ENOMEM;
  4505. /* obtain link type and link number via READ_CONFIG */
  4506. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4507. lpfc_sli4_read_config(phba);
  4508. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4509. goto retrieve_ppname;
  4510. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4511. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4512. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4513. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4514. LPFC_SLI4_MBX_NEMBED);
  4515. if (alloclen < reqlen) {
  4516. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4517. "3084 Allocated DMA memory size (%d) is "
  4518. "less than the requested DMA memory size "
  4519. "(%d)\n", alloclen, reqlen);
  4520. rc = -ENOMEM;
  4521. goto out_free_mboxq;
  4522. }
  4523. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4524. virtaddr = mboxq->sge_array->addr[0];
  4525. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4526. shdr = &mbx_cntl_attr->cfg_shdr;
  4527. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4528. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4529. if (shdr_status || shdr_add_status || rc) {
  4530. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4531. "3085 Mailbox x%x (x%x/x%x) failed, "
  4532. "rc:x%x, status:x%x, add_status:x%x\n",
  4533. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4534. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4535. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4536. rc, shdr_status, shdr_add_status);
  4537. rc = -ENXIO;
  4538. goto out_free_mboxq;
  4539. }
  4540. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4541. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4542. phba->sli4_hba.lnk_info.lnk_tp =
  4543. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4544. phba->sli4_hba.lnk_info.lnk_no =
  4545. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4546. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4547. "3086 lnk_type:%d, lnk_numb:%d\n",
  4548. phba->sli4_hba.lnk_info.lnk_tp,
  4549. phba->sli4_hba.lnk_info.lnk_no);
  4550. retrieve_ppname:
  4551. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4552. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4553. sizeof(struct lpfc_mbx_get_port_name) -
  4554. sizeof(struct lpfc_sli4_cfg_mhdr),
  4555. LPFC_SLI4_MBX_EMBED);
  4556. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4557. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4558. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4559. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4560. phba->sli4_hba.lnk_info.lnk_tp);
  4561. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4562. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4563. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4564. if (shdr_status || shdr_add_status || rc) {
  4565. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4566. "3087 Mailbox x%x (x%x/x%x) failed: "
  4567. "rc:x%x, status:x%x, add_status:x%x\n",
  4568. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4569. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4570. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4571. rc, shdr_status, shdr_add_status);
  4572. rc = -ENXIO;
  4573. goto out_free_mboxq;
  4574. }
  4575. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4576. case LPFC_LINK_NUMBER_0:
  4577. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4578. &get_port_name->u.response);
  4579. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4580. break;
  4581. case LPFC_LINK_NUMBER_1:
  4582. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4583. &get_port_name->u.response);
  4584. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4585. break;
  4586. case LPFC_LINK_NUMBER_2:
  4587. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4588. &get_port_name->u.response);
  4589. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4590. break;
  4591. case LPFC_LINK_NUMBER_3:
  4592. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4593. &get_port_name->u.response);
  4594. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4595. break;
  4596. default:
  4597. break;
  4598. }
  4599. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4600. phba->Port[0] = cport_name;
  4601. phba->Port[1] = '\0';
  4602. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4603. "3091 SLI get port name: %s\n", phba->Port);
  4604. }
  4605. out_free_mboxq:
  4606. if (rc != MBX_TIMEOUT) {
  4607. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4608. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4609. else
  4610. mempool_free(mboxq, phba->mbox_mem_pool);
  4611. }
  4612. return rc;
  4613. }
  4614. /**
  4615. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4616. * @phba: pointer to lpfc hba data structure.
  4617. *
  4618. * This routine is called to explicitly arm the SLI4 device's completion and
  4619. * event queues
  4620. **/
  4621. static void
  4622. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4623. {
  4624. int fcp_eqidx;
  4625. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4626. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4627. fcp_eqidx = 0;
  4628. if (phba->sli4_hba.fcp_cq) {
  4629. do {
  4630. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4631. LPFC_QUEUE_REARM);
  4632. } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
  4633. }
  4634. if (phba->cfg_fof)
  4635. lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM);
  4636. if (phba->sli4_hba.hba_eq) {
  4637. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
  4638. fcp_eqidx++)
  4639. lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
  4640. LPFC_QUEUE_REARM);
  4641. }
  4642. if (phba->cfg_fof)
  4643. lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM);
  4644. }
  4645. /**
  4646. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4647. * @phba: Pointer to HBA context object.
  4648. * @type: The resource extent type.
  4649. * @extnt_count: buffer to hold port available extent count.
  4650. * @extnt_size: buffer to hold element count per extent.
  4651. *
  4652. * This function calls the port and retrievs the number of available
  4653. * extents and their size for a particular extent type.
  4654. *
  4655. * Returns: 0 if successful. Nonzero otherwise.
  4656. **/
  4657. int
  4658. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4659. uint16_t *extnt_count, uint16_t *extnt_size)
  4660. {
  4661. int rc = 0;
  4662. uint32_t length;
  4663. uint32_t mbox_tmo;
  4664. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4665. LPFC_MBOXQ_t *mbox;
  4666. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4667. if (!mbox)
  4668. return -ENOMEM;
  4669. /* Find out how many extents are available for this resource type */
  4670. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4671. sizeof(struct lpfc_sli4_cfg_mhdr));
  4672. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4673. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4674. length, LPFC_SLI4_MBX_EMBED);
  4675. /* Send an extents count of 0 - the GET doesn't use it. */
  4676. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4677. LPFC_SLI4_MBX_EMBED);
  4678. if (unlikely(rc)) {
  4679. rc = -EIO;
  4680. goto err_exit;
  4681. }
  4682. if (!phba->sli4_hba.intr_enable)
  4683. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4684. else {
  4685. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4686. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4687. }
  4688. if (unlikely(rc)) {
  4689. rc = -EIO;
  4690. goto err_exit;
  4691. }
  4692. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4693. if (bf_get(lpfc_mbox_hdr_status,
  4694. &rsrc_info->header.cfg_shdr.response)) {
  4695. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4696. "2930 Failed to get resource extents "
  4697. "Status 0x%x Add'l Status 0x%x\n",
  4698. bf_get(lpfc_mbox_hdr_status,
  4699. &rsrc_info->header.cfg_shdr.response),
  4700. bf_get(lpfc_mbox_hdr_add_status,
  4701. &rsrc_info->header.cfg_shdr.response));
  4702. rc = -EIO;
  4703. goto err_exit;
  4704. }
  4705. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4706. &rsrc_info->u.rsp);
  4707. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4708. &rsrc_info->u.rsp);
  4709. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4710. "3162 Retrieved extents type-%d from port: count:%d, "
  4711. "size:%d\n", type, *extnt_count, *extnt_size);
  4712. err_exit:
  4713. mempool_free(mbox, phba->mbox_mem_pool);
  4714. return rc;
  4715. }
  4716. /**
  4717. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4718. * @phba: Pointer to HBA context object.
  4719. * @type: The extent type to check.
  4720. *
  4721. * This function reads the current available extents from the port and checks
  4722. * if the extent count or extent size has changed since the last access.
  4723. * Callers use this routine post port reset to understand if there is a
  4724. * extent reprovisioning requirement.
  4725. *
  4726. * Returns:
  4727. * -Error: error indicates problem.
  4728. * 1: Extent count or size has changed.
  4729. * 0: No changes.
  4730. **/
  4731. static int
  4732. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4733. {
  4734. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4735. uint16_t size_diff, rsrc_ext_size;
  4736. int rc = 0;
  4737. struct lpfc_rsrc_blks *rsrc_entry;
  4738. struct list_head *rsrc_blk_list = NULL;
  4739. size_diff = 0;
  4740. curr_ext_cnt = 0;
  4741. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4742. &rsrc_ext_cnt,
  4743. &rsrc_ext_size);
  4744. if (unlikely(rc))
  4745. return -EIO;
  4746. switch (type) {
  4747. case LPFC_RSC_TYPE_FCOE_RPI:
  4748. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4749. break;
  4750. case LPFC_RSC_TYPE_FCOE_VPI:
  4751. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4752. break;
  4753. case LPFC_RSC_TYPE_FCOE_XRI:
  4754. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4755. break;
  4756. case LPFC_RSC_TYPE_FCOE_VFI:
  4757. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4758. break;
  4759. default:
  4760. break;
  4761. }
  4762. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4763. curr_ext_cnt++;
  4764. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4765. size_diff++;
  4766. }
  4767. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4768. rc = 1;
  4769. return rc;
  4770. }
  4771. /**
  4772. * lpfc_sli4_cfg_post_extnts -
  4773. * @phba: Pointer to HBA context object.
  4774. * @extnt_cnt - number of available extents.
  4775. * @type - the extent type (rpi, xri, vfi, vpi).
  4776. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4777. * @mbox - pointer to the caller's allocated mailbox structure.
  4778. *
  4779. * This function executes the extents allocation request. It also
  4780. * takes care of the amount of memory needed to allocate or get the
  4781. * allocated extents. It is the caller's responsibility to evaluate
  4782. * the response.
  4783. *
  4784. * Returns:
  4785. * -Error: Error value describes the condition found.
  4786. * 0: if successful
  4787. **/
  4788. static int
  4789. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4790. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4791. {
  4792. int rc = 0;
  4793. uint32_t req_len;
  4794. uint32_t emb_len;
  4795. uint32_t alloc_len, mbox_tmo;
  4796. /* Calculate the total requested length of the dma memory */
  4797. req_len = extnt_cnt * sizeof(uint16_t);
  4798. /*
  4799. * Calculate the size of an embedded mailbox. The uint32_t
  4800. * accounts for extents-specific word.
  4801. */
  4802. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4803. sizeof(uint32_t);
  4804. /*
  4805. * Presume the allocation and response will fit into an embedded
  4806. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4807. */
  4808. *emb = LPFC_SLI4_MBX_EMBED;
  4809. if (req_len > emb_len) {
  4810. req_len = extnt_cnt * sizeof(uint16_t) +
  4811. sizeof(union lpfc_sli4_cfg_shdr) +
  4812. sizeof(uint32_t);
  4813. *emb = LPFC_SLI4_MBX_NEMBED;
  4814. }
  4815. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4816. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4817. req_len, *emb);
  4818. if (alloc_len < req_len) {
  4819. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4820. "2982 Allocated DMA memory size (x%x) is "
  4821. "less than the requested DMA memory "
  4822. "size (x%x)\n", alloc_len, req_len);
  4823. return -ENOMEM;
  4824. }
  4825. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4826. if (unlikely(rc))
  4827. return -EIO;
  4828. if (!phba->sli4_hba.intr_enable)
  4829. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4830. else {
  4831. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4832. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4833. }
  4834. if (unlikely(rc))
  4835. rc = -EIO;
  4836. return rc;
  4837. }
  4838. /**
  4839. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4840. * @phba: Pointer to HBA context object.
  4841. * @type: The resource extent type to allocate.
  4842. *
  4843. * This function allocates the number of elements for the specified
  4844. * resource type.
  4845. **/
  4846. static int
  4847. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4848. {
  4849. bool emb = false;
  4850. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4851. uint16_t rsrc_id, rsrc_start, j, k;
  4852. uint16_t *ids;
  4853. int i, rc;
  4854. unsigned long longs;
  4855. unsigned long *bmask;
  4856. struct lpfc_rsrc_blks *rsrc_blks;
  4857. LPFC_MBOXQ_t *mbox;
  4858. uint32_t length;
  4859. struct lpfc_id_range *id_array = NULL;
  4860. void *virtaddr = NULL;
  4861. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4862. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4863. struct list_head *ext_blk_list;
  4864. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4865. &rsrc_cnt,
  4866. &rsrc_size);
  4867. if (unlikely(rc))
  4868. return -EIO;
  4869. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4870. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4871. "3009 No available Resource Extents "
  4872. "for resource type 0x%x: Count: 0x%x, "
  4873. "Size 0x%x\n", type, rsrc_cnt,
  4874. rsrc_size);
  4875. return -ENOMEM;
  4876. }
  4877. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4878. "2903 Post resource extents type-0x%x: "
  4879. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4880. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4881. if (!mbox)
  4882. return -ENOMEM;
  4883. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4884. if (unlikely(rc)) {
  4885. rc = -EIO;
  4886. goto err_exit;
  4887. }
  4888. /*
  4889. * Figure out where the response is located. Then get local pointers
  4890. * to the response data. The port does not guarantee to respond to
  4891. * all extents counts request so update the local variable with the
  4892. * allocated count from the port.
  4893. */
  4894. if (emb == LPFC_SLI4_MBX_EMBED) {
  4895. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4896. id_array = &rsrc_ext->u.rsp.id[0];
  4897. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4898. } else {
  4899. virtaddr = mbox->sge_array->addr[0];
  4900. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4901. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4902. id_array = &n_rsrc->id;
  4903. }
  4904. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4905. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4906. /*
  4907. * Based on the resource size and count, correct the base and max
  4908. * resource values.
  4909. */
  4910. length = sizeof(struct lpfc_rsrc_blks);
  4911. switch (type) {
  4912. case LPFC_RSC_TYPE_FCOE_RPI:
  4913. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4914. sizeof(unsigned long),
  4915. GFP_KERNEL);
  4916. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4917. rc = -ENOMEM;
  4918. goto err_exit;
  4919. }
  4920. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4921. sizeof(uint16_t),
  4922. GFP_KERNEL);
  4923. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4924. kfree(phba->sli4_hba.rpi_bmask);
  4925. rc = -ENOMEM;
  4926. goto err_exit;
  4927. }
  4928. /*
  4929. * The next_rpi was initialized with the maximum available
  4930. * count but the port may allocate a smaller number. Catch
  4931. * that case and update the next_rpi.
  4932. */
  4933. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4934. /* Initialize local ptrs for common extent processing later. */
  4935. bmask = phba->sli4_hba.rpi_bmask;
  4936. ids = phba->sli4_hba.rpi_ids;
  4937. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4938. break;
  4939. case LPFC_RSC_TYPE_FCOE_VPI:
  4940. phba->vpi_bmask = kzalloc(longs *
  4941. sizeof(unsigned long),
  4942. GFP_KERNEL);
  4943. if (unlikely(!phba->vpi_bmask)) {
  4944. rc = -ENOMEM;
  4945. goto err_exit;
  4946. }
  4947. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4948. sizeof(uint16_t),
  4949. GFP_KERNEL);
  4950. if (unlikely(!phba->vpi_ids)) {
  4951. kfree(phba->vpi_bmask);
  4952. rc = -ENOMEM;
  4953. goto err_exit;
  4954. }
  4955. /* Initialize local ptrs for common extent processing later. */
  4956. bmask = phba->vpi_bmask;
  4957. ids = phba->vpi_ids;
  4958. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4959. break;
  4960. case LPFC_RSC_TYPE_FCOE_XRI:
  4961. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4962. sizeof(unsigned long),
  4963. GFP_KERNEL);
  4964. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4965. rc = -ENOMEM;
  4966. goto err_exit;
  4967. }
  4968. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4969. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4970. sizeof(uint16_t),
  4971. GFP_KERNEL);
  4972. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4973. kfree(phba->sli4_hba.xri_bmask);
  4974. rc = -ENOMEM;
  4975. goto err_exit;
  4976. }
  4977. /* Initialize local ptrs for common extent processing later. */
  4978. bmask = phba->sli4_hba.xri_bmask;
  4979. ids = phba->sli4_hba.xri_ids;
  4980. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4981. break;
  4982. case LPFC_RSC_TYPE_FCOE_VFI:
  4983. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4984. sizeof(unsigned long),
  4985. GFP_KERNEL);
  4986. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4987. rc = -ENOMEM;
  4988. goto err_exit;
  4989. }
  4990. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4991. sizeof(uint16_t),
  4992. GFP_KERNEL);
  4993. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4994. kfree(phba->sli4_hba.vfi_bmask);
  4995. rc = -ENOMEM;
  4996. goto err_exit;
  4997. }
  4998. /* Initialize local ptrs for common extent processing later. */
  4999. bmask = phba->sli4_hba.vfi_bmask;
  5000. ids = phba->sli4_hba.vfi_ids;
  5001. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  5002. break;
  5003. default:
  5004. /* Unsupported Opcode. Fail call. */
  5005. id_array = NULL;
  5006. bmask = NULL;
  5007. ids = NULL;
  5008. ext_blk_list = NULL;
  5009. goto err_exit;
  5010. }
  5011. /*
  5012. * Complete initializing the extent configuration with the
  5013. * allocated ids assigned to this function. The bitmask serves
  5014. * as an index into the array and manages the available ids. The
  5015. * array just stores the ids communicated to the port via the wqes.
  5016. */
  5017. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  5018. if ((i % 2) == 0)
  5019. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  5020. &id_array[k]);
  5021. else
  5022. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  5023. &id_array[k]);
  5024. rsrc_blks = kzalloc(length, GFP_KERNEL);
  5025. if (unlikely(!rsrc_blks)) {
  5026. rc = -ENOMEM;
  5027. kfree(bmask);
  5028. kfree(ids);
  5029. goto err_exit;
  5030. }
  5031. rsrc_blks->rsrc_start = rsrc_id;
  5032. rsrc_blks->rsrc_size = rsrc_size;
  5033. list_add_tail(&rsrc_blks->list, ext_blk_list);
  5034. rsrc_start = rsrc_id;
  5035. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  5036. phba->sli4_hba.scsi_xri_start = rsrc_start +
  5037. lpfc_sli4_get_els_iocb_cnt(phba);
  5038. while (rsrc_id < (rsrc_start + rsrc_size)) {
  5039. ids[j] = rsrc_id;
  5040. rsrc_id++;
  5041. j++;
  5042. }
  5043. /* Entire word processed. Get next word.*/
  5044. if ((i % 2) == 1)
  5045. k++;
  5046. }
  5047. err_exit:
  5048. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5049. return rc;
  5050. }
  5051. /**
  5052. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  5053. * @phba: Pointer to HBA context object.
  5054. * @type: the extent's type.
  5055. *
  5056. * This function deallocates all extents of a particular resource type.
  5057. * SLI4 does not allow for deallocating a particular extent range. It
  5058. * is the caller's responsibility to release all kernel memory resources.
  5059. **/
  5060. static int
  5061. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  5062. {
  5063. int rc;
  5064. uint32_t length, mbox_tmo = 0;
  5065. LPFC_MBOXQ_t *mbox;
  5066. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  5067. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  5068. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5069. if (!mbox)
  5070. return -ENOMEM;
  5071. /*
  5072. * This function sends an embedded mailbox because it only sends the
  5073. * the resource type. All extents of this type are released by the
  5074. * port.
  5075. */
  5076. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  5077. sizeof(struct lpfc_sli4_cfg_mhdr));
  5078. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5079. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  5080. length, LPFC_SLI4_MBX_EMBED);
  5081. /* Send an extents count of 0 - the dealloc doesn't use it. */
  5082. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  5083. LPFC_SLI4_MBX_EMBED);
  5084. if (unlikely(rc)) {
  5085. rc = -EIO;
  5086. goto out_free_mbox;
  5087. }
  5088. if (!phba->sli4_hba.intr_enable)
  5089. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5090. else {
  5091. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5092. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5093. }
  5094. if (unlikely(rc)) {
  5095. rc = -EIO;
  5096. goto out_free_mbox;
  5097. }
  5098. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  5099. if (bf_get(lpfc_mbox_hdr_status,
  5100. &dealloc_rsrc->header.cfg_shdr.response)) {
  5101. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5102. "2919 Failed to release resource extents "
  5103. "for type %d - Status 0x%x Add'l Status 0x%x. "
  5104. "Resource memory not released.\n",
  5105. type,
  5106. bf_get(lpfc_mbox_hdr_status,
  5107. &dealloc_rsrc->header.cfg_shdr.response),
  5108. bf_get(lpfc_mbox_hdr_add_status,
  5109. &dealloc_rsrc->header.cfg_shdr.response));
  5110. rc = -EIO;
  5111. goto out_free_mbox;
  5112. }
  5113. /* Release kernel memory resources for the specific type. */
  5114. switch (type) {
  5115. case LPFC_RSC_TYPE_FCOE_VPI:
  5116. kfree(phba->vpi_bmask);
  5117. kfree(phba->vpi_ids);
  5118. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5119. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5120. &phba->lpfc_vpi_blk_list, list) {
  5121. list_del_init(&rsrc_blk->list);
  5122. kfree(rsrc_blk);
  5123. }
  5124. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5125. break;
  5126. case LPFC_RSC_TYPE_FCOE_XRI:
  5127. kfree(phba->sli4_hba.xri_bmask);
  5128. kfree(phba->sli4_hba.xri_ids);
  5129. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5130. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  5131. list_del_init(&rsrc_blk->list);
  5132. kfree(rsrc_blk);
  5133. }
  5134. break;
  5135. case LPFC_RSC_TYPE_FCOE_VFI:
  5136. kfree(phba->sli4_hba.vfi_bmask);
  5137. kfree(phba->sli4_hba.vfi_ids);
  5138. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5139. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5140. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  5141. list_del_init(&rsrc_blk->list);
  5142. kfree(rsrc_blk);
  5143. }
  5144. break;
  5145. case LPFC_RSC_TYPE_FCOE_RPI:
  5146. /* RPI bitmask and physical id array are cleaned up earlier. */
  5147. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5148. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  5149. list_del_init(&rsrc_blk->list);
  5150. kfree(rsrc_blk);
  5151. }
  5152. break;
  5153. default:
  5154. break;
  5155. }
  5156. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5157. out_free_mbox:
  5158. mempool_free(mbox, phba->mbox_mem_pool);
  5159. return rc;
  5160. }
  5161. static void
  5162. lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
  5163. uint32_t feature)
  5164. {
  5165. uint32_t len;
  5166. len = sizeof(struct lpfc_mbx_set_feature) -
  5167. sizeof(struct lpfc_sli4_cfg_mhdr);
  5168. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5169. LPFC_MBOX_OPCODE_SET_FEATURES, len,
  5170. LPFC_SLI4_MBX_EMBED);
  5171. switch (feature) {
  5172. case LPFC_SET_UE_RECOVERY:
  5173. bf_set(lpfc_mbx_set_feature_UER,
  5174. &mbox->u.mqe.un.set_feature, 1);
  5175. mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
  5176. mbox->u.mqe.un.set_feature.param_len = 8;
  5177. break;
  5178. case LPFC_SET_MDS_DIAGS:
  5179. bf_set(lpfc_mbx_set_feature_mds,
  5180. &mbox->u.mqe.un.set_feature, 1);
  5181. bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
  5182. &mbox->u.mqe.un.set_feature, 0);
  5183. mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
  5184. mbox->u.mqe.un.set_feature.param_len = 8;
  5185. break;
  5186. }
  5187. return;
  5188. }
  5189. /**
  5190. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  5191. * @phba: Pointer to HBA context object.
  5192. *
  5193. * This function allocates all SLI4 resource identifiers.
  5194. **/
  5195. int
  5196. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  5197. {
  5198. int i, rc, error = 0;
  5199. uint16_t count, base;
  5200. unsigned long longs;
  5201. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5202. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  5203. if (phba->sli4_hba.extents_in_use) {
  5204. /*
  5205. * The port supports resource extents. The XRI, VPI, VFI, RPI
  5206. * resource extent count must be read and allocated before
  5207. * provisioning the resource id arrays.
  5208. */
  5209. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5210. LPFC_IDX_RSRC_RDY) {
  5211. /*
  5212. * Extent-based resources are set - the driver could
  5213. * be in a port reset. Figure out if any corrective
  5214. * actions need to be taken.
  5215. */
  5216. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5217. LPFC_RSC_TYPE_FCOE_VFI);
  5218. if (rc != 0)
  5219. error++;
  5220. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5221. LPFC_RSC_TYPE_FCOE_VPI);
  5222. if (rc != 0)
  5223. error++;
  5224. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5225. LPFC_RSC_TYPE_FCOE_XRI);
  5226. if (rc != 0)
  5227. error++;
  5228. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5229. LPFC_RSC_TYPE_FCOE_RPI);
  5230. if (rc != 0)
  5231. error++;
  5232. /*
  5233. * It's possible that the number of resources
  5234. * provided to this port instance changed between
  5235. * resets. Detect this condition and reallocate
  5236. * resources. Otherwise, there is no action.
  5237. */
  5238. if (error) {
  5239. lpfc_printf_log(phba, KERN_INFO,
  5240. LOG_MBOX | LOG_INIT,
  5241. "2931 Detected extent resource "
  5242. "change. Reallocating all "
  5243. "extents.\n");
  5244. rc = lpfc_sli4_dealloc_extent(phba,
  5245. LPFC_RSC_TYPE_FCOE_VFI);
  5246. rc = lpfc_sli4_dealloc_extent(phba,
  5247. LPFC_RSC_TYPE_FCOE_VPI);
  5248. rc = lpfc_sli4_dealloc_extent(phba,
  5249. LPFC_RSC_TYPE_FCOE_XRI);
  5250. rc = lpfc_sli4_dealloc_extent(phba,
  5251. LPFC_RSC_TYPE_FCOE_RPI);
  5252. } else
  5253. return 0;
  5254. }
  5255. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5256. if (unlikely(rc))
  5257. goto err_exit;
  5258. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5259. if (unlikely(rc))
  5260. goto err_exit;
  5261. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5262. if (unlikely(rc))
  5263. goto err_exit;
  5264. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5265. if (unlikely(rc))
  5266. goto err_exit;
  5267. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5268. LPFC_IDX_RSRC_RDY);
  5269. return rc;
  5270. } else {
  5271. /*
  5272. * The port does not support resource extents. The XRI, VPI,
  5273. * VFI, RPI resource ids were determined from READ_CONFIG.
  5274. * Just allocate the bitmasks and provision the resource id
  5275. * arrays. If a port reset is active, the resources don't
  5276. * need any action - just exit.
  5277. */
  5278. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5279. LPFC_IDX_RSRC_RDY) {
  5280. lpfc_sli4_dealloc_resource_identifiers(phba);
  5281. lpfc_sli4_remove_rpis(phba);
  5282. }
  5283. /* RPIs. */
  5284. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5285. if (count <= 0) {
  5286. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5287. "3279 Invalid provisioning of "
  5288. "rpi:%d\n", count);
  5289. rc = -EINVAL;
  5290. goto err_exit;
  5291. }
  5292. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5293. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5294. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5295. sizeof(unsigned long),
  5296. GFP_KERNEL);
  5297. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5298. rc = -ENOMEM;
  5299. goto err_exit;
  5300. }
  5301. phba->sli4_hba.rpi_ids = kzalloc(count *
  5302. sizeof(uint16_t),
  5303. GFP_KERNEL);
  5304. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5305. rc = -ENOMEM;
  5306. goto free_rpi_bmask;
  5307. }
  5308. for (i = 0; i < count; i++)
  5309. phba->sli4_hba.rpi_ids[i] = base + i;
  5310. /* VPIs. */
  5311. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5312. if (count <= 0) {
  5313. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5314. "3280 Invalid provisioning of "
  5315. "vpi:%d\n", count);
  5316. rc = -EINVAL;
  5317. goto free_rpi_ids;
  5318. }
  5319. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5320. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5321. phba->vpi_bmask = kzalloc(longs *
  5322. sizeof(unsigned long),
  5323. GFP_KERNEL);
  5324. if (unlikely(!phba->vpi_bmask)) {
  5325. rc = -ENOMEM;
  5326. goto free_rpi_ids;
  5327. }
  5328. phba->vpi_ids = kzalloc(count *
  5329. sizeof(uint16_t),
  5330. GFP_KERNEL);
  5331. if (unlikely(!phba->vpi_ids)) {
  5332. rc = -ENOMEM;
  5333. goto free_vpi_bmask;
  5334. }
  5335. for (i = 0; i < count; i++)
  5336. phba->vpi_ids[i] = base + i;
  5337. /* XRIs. */
  5338. count = phba->sli4_hba.max_cfg_param.max_xri;
  5339. if (count <= 0) {
  5340. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5341. "3281 Invalid provisioning of "
  5342. "xri:%d\n", count);
  5343. rc = -EINVAL;
  5344. goto free_vpi_ids;
  5345. }
  5346. base = phba->sli4_hba.max_cfg_param.xri_base;
  5347. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5348. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5349. sizeof(unsigned long),
  5350. GFP_KERNEL);
  5351. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5352. rc = -ENOMEM;
  5353. goto free_vpi_ids;
  5354. }
  5355. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5356. phba->sli4_hba.xri_ids = kzalloc(count *
  5357. sizeof(uint16_t),
  5358. GFP_KERNEL);
  5359. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5360. rc = -ENOMEM;
  5361. goto free_xri_bmask;
  5362. }
  5363. for (i = 0; i < count; i++)
  5364. phba->sli4_hba.xri_ids[i] = base + i;
  5365. /* VFIs. */
  5366. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5367. if (count <= 0) {
  5368. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5369. "3282 Invalid provisioning of "
  5370. "vfi:%d\n", count);
  5371. rc = -EINVAL;
  5372. goto free_xri_ids;
  5373. }
  5374. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5375. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5376. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5377. sizeof(unsigned long),
  5378. GFP_KERNEL);
  5379. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5380. rc = -ENOMEM;
  5381. goto free_xri_ids;
  5382. }
  5383. phba->sli4_hba.vfi_ids = kzalloc(count *
  5384. sizeof(uint16_t),
  5385. GFP_KERNEL);
  5386. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5387. rc = -ENOMEM;
  5388. goto free_vfi_bmask;
  5389. }
  5390. for (i = 0; i < count; i++)
  5391. phba->sli4_hba.vfi_ids[i] = base + i;
  5392. /*
  5393. * Mark all resources ready. An HBA reset doesn't need
  5394. * to reset the initialization.
  5395. */
  5396. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5397. LPFC_IDX_RSRC_RDY);
  5398. return 0;
  5399. }
  5400. free_vfi_bmask:
  5401. kfree(phba->sli4_hba.vfi_bmask);
  5402. phba->sli4_hba.vfi_bmask = NULL;
  5403. free_xri_ids:
  5404. kfree(phba->sli4_hba.xri_ids);
  5405. phba->sli4_hba.xri_ids = NULL;
  5406. free_xri_bmask:
  5407. kfree(phba->sli4_hba.xri_bmask);
  5408. phba->sli4_hba.xri_bmask = NULL;
  5409. free_vpi_ids:
  5410. kfree(phba->vpi_ids);
  5411. phba->vpi_ids = NULL;
  5412. free_vpi_bmask:
  5413. kfree(phba->vpi_bmask);
  5414. phba->vpi_bmask = NULL;
  5415. free_rpi_ids:
  5416. kfree(phba->sli4_hba.rpi_ids);
  5417. phba->sli4_hba.rpi_ids = NULL;
  5418. free_rpi_bmask:
  5419. kfree(phba->sli4_hba.rpi_bmask);
  5420. phba->sli4_hba.rpi_bmask = NULL;
  5421. err_exit:
  5422. return rc;
  5423. }
  5424. /**
  5425. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5426. * @phba: Pointer to HBA context object.
  5427. *
  5428. * This function allocates the number of elements for the specified
  5429. * resource type.
  5430. **/
  5431. int
  5432. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5433. {
  5434. if (phba->sli4_hba.extents_in_use) {
  5435. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5436. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5437. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5438. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5439. } else {
  5440. kfree(phba->vpi_bmask);
  5441. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5442. kfree(phba->vpi_ids);
  5443. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5444. kfree(phba->sli4_hba.xri_bmask);
  5445. kfree(phba->sli4_hba.xri_ids);
  5446. kfree(phba->sli4_hba.vfi_bmask);
  5447. kfree(phba->sli4_hba.vfi_ids);
  5448. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5449. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5450. }
  5451. return 0;
  5452. }
  5453. /**
  5454. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5455. * @phba: Pointer to HBA context object.
  5456. * @type: The resource extent type.
  5457. * @extnt_count: buffer to hold port extent count response
  5458. * @extnt_size: buffer to hold port extent size response.
  5459. *
  5460. * This function calls the port to read the host allocated extents
  5461. * for a particular type.
  5462. **/
  5463. int
  5464. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5465. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5466. {
  5467. bool emb;
  5468. int rc = 0;
  5469. uint16_t curr_blks = 0;
  5470. uint32_t req_len, emb_len;
  5471. uint32_t alloc_len, mbox_tmo;
  5472. struct list_head *blk_list_head;
  5473. struct lpfc_rsrc_blks *rsrc_blk;
  5474. LPFC_MBOXQ_t *mbox;
  5475. void *virtaddr = NULL;
  5476. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5477. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5478. union lpfc_sli4_cfg_shdr *shdr;
  5479. switch (type) {
  5480. case LPFC_RSC_TYPE_FCOE_VPI:
  5481. blk_list_head = &phba->lpfc_vpi_blk_list;
  5482. break;
  5483. case LPFC_RSC_TYPE_FCOE_XRI:
  5484. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5485. break;
  5486. case LPFC_RSC_TYPE_FCOE_VFI:
  5487. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5488. break;
  5489. case LPFC_RSC_TYPE_FCOE_RPI:
  5490. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5491. break;
  5492. default:
  5493. return -EIO;
  5494. }
  5495. /* Count the number of extents currently allocatd for this type. */
  5496. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5497. if (curr_blks == 0) {
  5498. /*
  5499. * The GET_ALLOCATED mailbox does not return the size,
  5500. * just the count. The size should be just the size
  5501. * stored in the current allocated block and all sizes
  5502. * for an extent type are the same so set the return
  5503. * value now.
  5504. */
  5505. *extnt_size = rsrc_blk->rsrc_size;
  5506. }
  5507. curr_blks++;
  5508. }
  5509. /*
  5510. * Calculate the size of an embedded mailbox. The uint32_t
  5511. * accounts for extents-specific word.
  5512. */
  5513. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5514. sizeof(uint32_t);
  5515. /*
  5516. * Presume the allocation and response will fit into an embedded
  5517. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5518. */
  5519. emb = LPFC_SLI4_MBX_EMBED;
  5520. req_len = emb_len;
  5521. if (req_len > emb_len) {
  5522. req_len = curr_blks * sizeof(uint16_t) +
  5523. sizeof(union lpfc_sli4_cfg_shdr) +
  5524. sizeof(uint32_t);
  5525. emb = LPFC_SLI4_MBX_NEMBED;
  5526. }
  5527. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5528. if (!mbox)
  5529. return -ENOMEM;
  5530. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5531. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5532. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5533. req_len, emb);
  5534. if (alloc_len < req_len) {
  5535. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5536. "2983 Allocated DMA memory size (x%x) is "
  5537. "less than the requested DMA memory "
  5538. "size (x%x)\n", alloc_len, req_len);
  5539. rc = -ENOMEM;
  5540. goto err_exit;
  5541. }
  5542. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5543. if (unlikely(rc)) {
  5544. rc = -EIO;
  5545. goto err_exit;
  5546. }
  5547. if (!phba->sli4_hba.intr_enable)
  5548. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5549. else {
  5550. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5551. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5552. }
  5553. if (unlikely(rc)) {
  5554. rc = -EIO;
  5555. goto err_exit;
  5556. }
  5557. /*
  5558. * Figure out where the response is located. Then get local pointers
  5559. * to the response data. The port does not guarantee to respond to
  5560. * all extents counts request so update the local variable with the
  5561. * allocated count from the port.
  5562. */
  5563. if (emb == LPFC_SLI4_MBX_EMBED) {
  5564. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5565. shdr = &rsrc_ext->header.cfg_shdr;
  5566. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5567. } else {
  5568. virtaddr = mbox->sge_array->addr[0];
  5569. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5570. shdr = &n_rsrc->cfg_shdr;
  5571. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5572. }
  5573. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5574. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5575. "2984 Failed to read allocated resources "
  5576. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5577. type,
  5578. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5579. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5580. rc = -EIO;
  5581. goto err_exit;
  5582. }
  5583. err_exit:
  5584. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5585. return rc;
  5586. }
  5587. /**
  5588. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5589. * @phba: pointer to lpfc hba data structure.
  5590. *
  5591. * This routine walks the list of els buffers that have been allocated and
  5592. * repost them to the port by using SGL block post. This is needed after a
  5593. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5594. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5595. * SGL block post mailbox commands to post them to the port. For single els
  5596. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5597. * mailbox command for posting.
  5598. *
  5599. * Returns: 0 = success, non-zero failure.
  5600. **/
  5601. static int
  5602. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5603. {
  5604. struct lpfc_sglq *sglq_entry = NULL;
  5605. struct lpfc_sglq *sglq_entry_next = NULL;
  5606. struct lpfc_sglq *sglq_entry_first = NULL;
  5607. int status, total_cnt, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5608. int last_xritag = NO_XRI;
  5609. struct lpfc_sli_ring *pring;
  5610. LIST_HEAD(prep_sgl_list);
  5611. LIST_HEAD(blck_sgl_list);
  5612. LIST_HEAD(allc_sgl_list);
  5613. LIST_HEAD(post_sgl_list);
  5614. LIST_HEAD(free_sgl_list);
  5615. pring = &phba->sli.ring[LPFC_ELS_RING];
  5616. spin_lock_irq(&phba->hbalock);
  5617. spin_lock(&pring->ring_lock);
  5618. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5619. spin_unlock(&pring->ring_lock);
  5620. spin_unlock_irq(&phba->hbalock);
  5621. total_cnt = phba->sli4_hba.els_xri_cnt;
  5622. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5623. &allc_sgl_list, list) {
  5624. list_del_init(&sglq_entry->list);
  5625. block_cnt++;
  5626. if ((last_xritag != NO_XRI) &&
  5627. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5628. /* a hole in xri block, form a sgl posting block */
  5629. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5630. post_cnt = block_cnt - 1;
  5631. /* prepare list for next posting block */
  5632. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5633. block_cnt = 1;
  5634. } else {
  5635. /* prepare list for next posting block */
  5636. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5637. /* enough sgls for non-embed sgl mbox command */
  5638. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5639. list_splice_init(&prep_sgl_list,
  5640. &blck_sgl_list);
  5641. post_cnt = block_cnt;
  5642. block_cnt = 0;
  5643. }
  5644. }
  5645. num_posted++;
  5646. /* keep track of last sgl's xritag */
  5647. last_xritag = sglq_entry->sli4_xritag;
  5648. /* end of repost sgl list condition for els buffers */
  5649. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5650. if (post_cnt == 0) {
  5651. list_splice_init(&prep_sgl_list,
  5652. &blck_sgl_list);
  5653. post_cnt = block_cnt;
  5654. } else if (block_cnt == 1) {
  5655. status = lpfc_sli4_post_sgl(phba,
  5656. sglq_entry->phys, 0,
  5657. sglq_entry->sli4_xritag);
  5658. if (!status) {
  5659. /* successful, put sgl to posted list */
  5660. list_add_tail(&sglq_entry->list,
  5661. &post_sgl_list);
  5662. } else {
  5663. /* Failure, put sgl to free list */
  5664. lpfc_printf_log(phba, KERN_WARNING,
  5665. LOG_SLI,
  5666. "3159 Failed to post els "
  5667. "sgl, xritag:x%x\n",
  5668. sglq_entry->sli4_xritag);
  5669. list_add_tail(&sglq_entry->list,
  5670. &free_sgl_list);
  5671. total_cnt--;
  5672. }
  5673. }
  5674. }
  5675. /* continue until a nembed page worth of sgls */
  5676. if (post_cnt == 0)
  5677. continue;
  5678. /* post the els buffer list sgls as a block */
  5679. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5680. post_cnt);
  5681. if (!status) {
  5682. /* success, put sgl list to posted sgl list */
  5683. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5684. } else {
  5685. /* Failure, put sgl list to free sgl list */
  5686. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5687. struct lpfc_sglq,
  5688. list);
  5689. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5690. "3160 Failed to post els sgl-list, "
  5691. "xritag:x%x-x%x\n",
  5692. sglq_entry_first->sli4_xritag,
  5693. (sglq_entry_first->sli4_xritag +
  5694. post_cnt - 1));
  5695. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5696. total_cnt -= post_cnt;
  5697. }
  5698. /* don't reset xirtag due to hole in xri block */
  5699. if (block_cnt == 0)
  5700. last_xritag = NO_XRI;
  5701. /* reset els sgl post count for next round of posting */
  5702. post_cnt = 0;
  5703. }
  5704. /* update the number of XRIs posted for ELS */
  5705. phba->sli4_hba.els_xri_cnt = total_cnt;
  5706. /* free the els sgls failed to post */
  5707. lpfc_free_sgl_list(phba, &free_sgl_list);
  5708. /* push els sgls posted to the availble list */
  5709. if (!list_empty(&post_sgl_list)) {
  5710. spin_lock_irq(&phba->hbalock);
  5711. spin_lock(&pring->ring_lock);
  5712. list_splice_init(&post_sgl_list,
  5713. &phba->sli4_hba.lpfc_sgl_list);
  5714. spin_unlock(&pring->ring_lock);
  5715. spin_unlock_irq(&phba->hbalock);
  5716. } else {
  5717. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5718. "3161 Failure to post els sgl to port.\n");
  5719. return -EIO;
  5720. }
  5721. return 0;
  5722. }
  5723. /**
  5724. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5725. * @phba: Pointer to HBA context object.
  5726. *
  5727. * This function is the main SLI4 device intialization PCI function. This
  5728. * function is called by the HBA intialization code, HBA reset code and
  5729. * HBA error attention handler code. Caller is not required to hold any
  5730. * locks.
  5731. **/
  5732. int
  5733. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5734. {
  5735. int rc;
  5736. LPFC_MBOXQ_t *mboxq;
  5737. struct lpfc_mqe *mqe;
  5738. uint8_t *vpd;
  5739. uint32_t vpd_size;
  5740. uint32_t ftr_rsp = 0;
  5741. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5742. struct lpfc_vport *vport = phba->pport;
  5743. struct lpfc_dmabuf *mp;
  5744. /* Perform a PCI function reset to start from clean */
  5745. rc = lpfc_pci_function_reset(phba);
  5746. if (unlikely(rc))
  5747. return -ENODEV;
  5748. /* Check the HBA Host Status Register for readyness */
  5749. rc = lpfc_sli4_post_status_check(phba);
  5750. if (unlikely(rc))
  5751. return -ENODEV;
  5752. else {
  5753. spin_lock_irq(&phba->hbalock);
  5754. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5755. spin_unlock_irq(&phba->hbalock);
  5756. }
  5757. /*
  5758. * Allocate a single mailbox container for initializing the
  5759. * port.
  5760. */
  5761. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5762. if (!mboxq)
  5763. return -ENOMEM;
  5764. /* Issue READ_REV to collect vpd and FW information. */
  5765. vpd_size = SLI4_PAGE_SIZE;
  5766. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5767. if (!vpd) {
  5768. rc = -ENOMEM;
  5769. goto out_free_mbox;
  5770. }
  5771. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5772. if (unlikely(rc)) {
  5773. kfree(vpd);
  5774. goto out_free_mbox;
  5775. }
  5776. mqe = &mboxq->u.mqe;
  5777. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5778. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
  5779. phba->hba_flag |= HBA_FCOE_MODE;
  5780. phba->fcp_embed_io = 0; /* SLI4 FC support only */
  5781. } else {
  5782. phba->hba_flag &= ~HBA_FCOE_MODE;
  5783. }
  5784. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5785. LPFC_DCBX_CEE_MODE)
  5786. phba->hba_flag |= HBA_FIP_SUPPORT;
  5787. else
  5788. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5789. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5790. if (phba->sli_rev != LPFC_SLI_REV4) {
  5791. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5792. "0376 READ_REV Error. SLI Level %d "
  5793. "FCoE enabled %d\n",
  5794. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5795. rc = -EIO;
  5796. kfree(vpd);
  5797. goto out_free_mbox;
  5798. }
  5799. /*
  5800. * Continue initialization with default values even if driver failed
  5801. * to read FCoE param config regions, only read parameters if the
  5802. * board is FCoE
  5803. */
  5804. if (phba->hba_flag & HBA_FCOE_MODE &&
  5805. lpfc_sli4_read_fcoe_params(phba))
  5806. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5807. "2570 Failed to read FCoE parameters\n");
  5808. /*
  5809. * Retrieve sli4 device physical port name, failure of doing it
  5810. * is considered as non-fatal.
  5811. */
  5812. rc = lpfc_sli4_retrieve_pport_name(phba);
  5813. if (!rc)
  5814. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5815. "3080 Successful retrieving SLI4 device "
  5816. "physical port name: %s.\n", phba->Port);
  5817. /*
  5818. * Evaluate the read rev and vpd data. Populate the driver
  5819. * state with the results. If this routine fails, the failure
  5820. * is not fatal as the driver will use generic values.
  5821. */
  5822. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5823. if (unlikely(!rc)) {
  5824. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5825. "0377 Error %d parsing vpd. "
  5826. "Using defaults.\n", rc);
  5827. rc = 0;
  5828. }
  5829. kfree(vpd);
  5830. /* Save information as VPD data */
  5831. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5832. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5833. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5834. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5835. &mqe->un.read_rev);
  5836. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5837. &mqe->un.read_rev);
  5838. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5839. &mqe->un.read_rev);
  5840. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5841. &mqe->un.read_rev);
  5842. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5843. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5844. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5845. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5846. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5847. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5848. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5849. "(%d):0380 READ_REV Status x%x "
  5850. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5851. mboxq->vport ? mboxq->vport->vpi : 0,
  5852. bf_get(lpfc_mqe_status, mqe),
  5853. phba->vpd.rev.opFwName,
  5854. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5855. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5856. /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
  5857. rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3);
  5858. if (phba->pport->cfg_lun_queue_depth > rc) {
  5859. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5860. "3362 LUN queue depth changed from %d to %d\n",
  5861. phba->pport->cfg_lun_queue_depth, rc);
  5862. phba->pport->cfg_lun_queue_depth = rc;
  5863. }
  5864. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  5865. LPFC_SLI_INTF_IF_TYPE_0) {
  5866. lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
  5867. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5868. if (rc == MBX_SUCCESS) {
  5869. phba->hba_flag |= HBA_RECOVERABLE_UE;
  5870. /* Set 1Sec interval to detect UE */
  5871. phba->eratt_poll_interval = 1;
  5872. phba->sli4_hba.ue_to_sr = bf_get(
  5873. lpfc_mbx_set_feature_UESR,
  5874. &mboxq->u.mqe.un.set_feature);
  5875. phba->sli4_hba.ue_to_rp = bf_get(
  5876. lpfc_mbx_set_feature_UERP,
  5877. &mboxq->u.mqe.un.set_feature);
  5878. }
  5879. }
  5880. if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
  5881. /* Enable MDS Diagnostics only if the SLI Port supports it */
  5882. lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
  5883. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5884. if (rc != MBX_SUCCESS)
  5885. phba->mds_diags_support = 0;
  5886. }
  5887. /*
  5888. * Discover the port's supported feature set and match it against the
  5889. * hosts requests.
  5890. */
  5891. lpfc_request_features(phba, mboxq);
  5892. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5893. if (unlikely(rc)) {
  5894. rc = -EIO;
  5895. goto out_free_mbox;
  5896. }
  5897. /*
  5898. * The port must support FCP initiator mode as this is the
  5899. * only mode running in the host.
  5900. */
  5901. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5902. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5903. "0378 No support for fcpi mode.\n");
  5904. ftr_rsp++;
  5905. }
  5906. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5907. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5908. else
  5909. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5910. /*
  5911. * If the port cannot support the host's requested features
  5912. * then turn off the global config parameters to disable the
  5913. * feature in the driver. This is not a fatal error.
  5914. */
  5915. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5916. if (phba->cfg_enable_bg) {
  5917. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5918. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5919. else
  5920. ftr_rsp++;
  5921. }
  5922. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5923. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5924. ftr_rsp++;
  5925. if (ftr_rsp) {
  5926. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5927. "0379 Feature Mismatch Data: x%08x %08x "
  5928. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5929. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5930. phba->cfg_enable_npiv, phba->max_vpi);
  5931. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5932. phba->cfg_enable_bg = 0;
  5933. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5934. phba->cfg_enable_npiv = 0;
  5935. }
  5936. /* These SLI3 features are assumed in SLI4 */
  5937. spin_lock_irq(&phba->hbalock);
  5938. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5939. spin_unlock_irq(&phba->hbalock);
  5940. /*
  5941. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5942. * calls depends on these resources to complete port setup.
  5943. */
  5944. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5945. if (rc) {
  5946. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5947. "2920 Failed to alloc Resource IDs "
  5948. "rc = x%x\n", rc);
  5949. goto out_free_mbox;
  5950. }
  5951. /* Read the port's service parameters. */
  5952. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5953. if (rc) {
  5954. phba->link_state = LPFC_HBA_ERROR;
  5955. rc = -ENOMEM;
  5956. goto out_free_mbox;
  5957. }
  5958. mboxq->vport = vport;
  5959. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5960. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5961. if (rc == MBX_SUCCESS) {
  5962. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5963. rc = 0;
  5964. }
  5965. /*
  5966. * This memory was allocated by the lpfc_read_sparam routine. Release
  5967. * it to the mbuf pool.
  5968. */
  5969. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5970. kfree(mp);
  5971. mboxq->context1 = NULL;
  5972. if (unlikely(rc)) {
  5973. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5974. "0382 READ_SPARAM command failed "
  5975. "status %d, mbxStatus x%x\n",
  5976. rc, bf_get(lpfc_mqe_status, mqe));
  5977. phba->link_state = LPFC_HBA_ERROR;
  5978. rc = -EIO;
  5979. goto out_free_mbox;
  5980. }
  5981. lpfc_update_vport_wwn(vport);
  5982. /* Update the fc_host data structures with new wwn. */
  5983. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5984. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5985. /* update host els and scsi xri-sgl sizes and mappings */
  5986. rc = lpfc_sli4_xri_sgl_update(phba);
  5987. if (unlikely(rc)) {
  5988. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5989. "1400 Failed to update xri-sgl size and "
  5990. "mapping: %d\n", rc);
  5991. goto out_free_mbox;
  5992. }
  5993. /* register the els sgl pool to the port */
  5994. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5995. if (unlikely(rc)) {
  5996. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5997. "0582 Error %d during els sgl post "
  5998. "operation\n", rc);
  5999. rc = -ENODEV;
  6000. goto out_free_mbox;
  6001. }
  6002. /* register the allocated scsi sgl pool to the port */
  6003. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  6004. if (unlikely(rc)) {
  6005. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6006. "0383 Error %d during scsi sgl post "
  6007. "operation\n", rc);
  6008. /* Some Scsi buffers were moved to the abort scsi list */
  6009. /* A pci function reset will repost them */
  6010. rc = -ENODEV;
  6011. goto out_free_mbox;
  6012. }
  6013. /* Post the rpi header region to the device. */
  6014. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  6015. if (unlikely(rc)) {
  6016. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6017. "0393 Error %d during rpi post operation\n",
  6018. rc);
  6019. rc = -ENODEV;
  6020. goto out_free_mbox;
  6021. }
  6022. lpfc_sli4_node_prep(phba);
  6023. /* Create all the SLI4 queues */
  6024. rc = lpfc_sli4_queue_create(phba);
  6025. if (rc) {
  6026. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6027. "3089 Failed to allocate queues\n");
  6028. rc = -ENODEV;
  6029. goto out_stop_timers;
  6030. }
  6031. /* Set up all the queues to the device */
  6032. rc = lpfc_sli4_queue_setup(phba);
  6033. if (unlikely(rc)) {
  6034. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6035. "0381 Error %d during queue setup.\n ", rc);
  6036. goto out_destroy_queue;
  6037. }
  6038. /* Arm the CQs and then EQs on device */
  6039. lpfc_sli4_arm_cqeq_intr(phba);
  6040. /* Indicate device interrupt mode */
  6041. phba->sli4_hba.intr_enable = 1;
  6042. /* Allow asynchronous mailbox command to go through */
  6043. spin_lock_irq(&phba->hbalock);
  6044. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6045. spin_unlock_irq(&phba->hbalock);
  6046. /* Post receive buffers to the device */
  6047. lpfc_sli4_rb_setup(phba);
  6048. /* Reset HBA FCF states after HBA reset */
  6049. phba->fcf.fcf_flag = 0;
  6050. phba->fcf.current_rec.flag = 0;
  6051. /* Start the ELS watchdog timer */
  6052. mod_timer(&vport->els_tmofunc,
  6053. jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
  6054. /* Start heart beat timer */
  6055. mod_timer(&phba->hb_tmofunc,
  6056. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  6057. phba->hb_outstanding = 0;
  6058. phba->last_completion_time = jiffies;
  6059. /* Start error attention (ERATT) polling timer */
  6060. mod_timer(&phba->eratt_poll,
  6061. jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
  6062. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  6063. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  6064. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  6065. if (!rc) {
  6066. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6067. "2829 This device supports "
  6068. "Advanced Error Reporting (AER)\n");
  6069. spin_lock_irq(&phba->hbalock);
  6070. phba->hba_flag |= HBA_AER_ENABLED;
  6071. spin_unlock_irq(&phba->hbalock);
  6072. } else {
  6073. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6074. "2830 This device does not support "
  6075. "Advanced Error Reporting (AER)\n");
  6076. phba->cfg_aer_support = 0;
  6077. }
  6078. rc = 0;
  6079. }
  6080. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  6081. /*
  6082. * The FC Port needs to register FCFI (index 0)
  6083. */
  6084. lpfc_reg_fcfi(phba, mboxq);
  6085. mboxq->vport = phba->pport;
  6086. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6087. if (rc != MBX_SUCCESS)
  6088. goto out_unset_queue;
  6089. rc = 0;
  6090. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  6091. &mboxq->u.mqe.un.reg_fcfi);
  6092. /* Check if the port is configured to be disabled */
  6093. lpfc_sli_read_link_ste(phba);
  6094. }
  6095. /*
  6096. * The port is ready, set the host's link state to LINK_DOWN
  6097. * in preparation for link interrupts.
  6098. */
  6099. spin_lock_irq(&phba->hbalock);
  6100. phba->link_state = LPFC_LINK_DOWN;
  6101. spin_unlock_irq(&phba->hbalock);
  6102. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  6103. (phba->hba_flag & LINK_DISABLED)) {
  6104. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  6105. "3103 Adapter Link is disabled.\n");
  6106. lpfc_down_link(phba, mboxq);
  6107. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6108. if (rc != MBX_SUCCESS) {
  6109. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  6110. "3104 Adapter failed to issue "
  6111. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  6112. goto out_unset_queue;
  6113. }
  6114. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  6115. /* don't perform init_link on SLI4 FC port loopback test */
  6116. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  6117. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  6118. if (rc)
  6119. goto out_unset_queue;
  6120. }
  6121. }
  6122. mempool_free(mboxq, phba->mbox_mem_pool);
  6123. return rc;
  6124. out_unset_queue:
  6125. /* Unset all the queues set up in this routine when error out */
  6126. lpfc_sli4_queue_unset(phba);
  6127. out_destroy_queue:
  6128. lpfc_sli4_queue_destroy(phba);
  6129. out_stop_timers:
  6130. lpfc_stop_hba_timers(phba);
  6131. out_free_mbox:
  6132. mempool_free(mboxq, phba->mbox_mem_pool);
  6133. return rc;
  6134. }
  6135. /**
  6136. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  6137. * @ptr: context object - pointer to hba structure.
  6138. *
  6139. * This is the callback function for mailbox timer. The mailbox
  6140. * timer is armed when a new mailbox command is issued and the timer
  6141. * is deleted when the mailbox complete. The function is called by
  6142. * the kernel timer code when a mailbox does not complete within
  6143. * expected time. This function wakes up the worker thread to
  6144. * process the mailbox timeout and returns. All the processing is
  6145. * done by the worker thread function lpfc_mbox_timeout_handler.
  6146. **/
  6147. void
  6148. lpfc_mbox_timeout(unsigned long ptr)
  6149. {
  6150. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  6151. unsigned long iflag;
  6152. uint32_t tmo_posted;
  6153. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  6154. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  6155. if (!tmo_posted)
  6156. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  6157. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  6158. if (!tmo_posted)
  6159. lpfc_worker_wake_up(phba);
  6160. return;
  6161. }
  6162. /**
  6163. * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
  6164. * are pending
  6165. * @phba: Pointer to HBA context object.
  6166. *
  6167. * This function checks if any mailbox completions are present on the mailbox
  6168. * completion queue.
  6169. **/
  6170. static bool
  6171. lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
  6172. {
  6173. uint32_t idx;
  6174. struct lpfc_queue *mcq;
  6175. struct lpfc_mcqe *mcqe;
  6176. bool pending_completions = false;
  6177. if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
  6178. return false;
  6179. /* Check for completions on mailbox completion queue */
  6180. mcq = phba->sli4_hba.mbx_cq;
  6181. idx = mcq->hba_index;
  6182. while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) {
  6183. mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe;
  6184. if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
  6185. (!bf_get_le32(lpfc_trailer_async, mcqe))) {
  6186. pending_completions = true;
  6187. break;
  6188. }
  6189. idx = (idx + 1) % mcq->entry_count;
  6190. if (mcq->hba_index == idx)
  6191. break;
  6192. }
  6193. return pending_completions;
  6194. }
  6195. /**
  6196. * lpfc_sli4_process_missed_mbox_completions - process mbox completions
  6197. * that were missed.
  6198. * @phba: Pointer to HBA context object.
  6199. *
  6200. * For sli4, it is possible to miss an interrupt. As such mbox completions
  6201. * maybe missed causing erroneous mailbox timeouts to occur. This function
  6202. * checks to see if mbox completions are on the mailbox completion queue
  6203. * and will process all the completions associated with the eq for the
  6204. * mailbox completion queue.
  6205. **/
  6206. bool
  6207. lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
  6208. {
  6209. uint32_t eqidx;
  6210. struct lpfc_queue *fpeq = NULL;
  6211. struct lpfc_eqe *eqe;
  6212. bool mbox_pending;
  6213. if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
  6214. return false;
  6215. /* Find the eq associated with the mcq */
  6216. if (phba->sli4_hba.hba_eq)
  6217. for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++)
  6218. if (phba->sli4_hba.hba_eq[eqidx]->queue_id ==
  6219. phba->sli4_hba.mbx_cq->assoc_qid) {
  6220. fpeq = phba->sli4_hba.hba_eq[eqidx];
  6221. break;
  6222. }
  6223. if (!fpeq)
  6224. return false;
  6225. /* Turn off interrupts from this EQ */
  6226. lpfc_sli4_eq_clr_intr(fpeq);
  6227. /* Check to see if a mbox completion is pending */
  6228. mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
  6229. /*
  6230. * If a mbox completion is pending, process all the events on EQ
  6231. * associated with the mbox completion queue (this could include
  6232. * mailbox commands, async events, els commands, receive queue data
  6233. * and fcp commands)
  6234. */
  6235. if (mbox_pending)
  6236. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  6237. lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx);
  6238. fpeq->EQ_processed++;
  6239. }
  6240. /* Always clear and re-arm the EQ */
  6241. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  6242. return mbox_pending;
  6243. }
  6244. /**
  6245. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  6246. * @phba: Pointer to HBA context object.
  6247. *
  6248. * This function is called from worker thread when a mailbox command times out.
  6249. * The caller is not required to hold any locks. This function will reset the
  6250. * HBA and recover all the pending commands.
  6251. **/
  6252. void
  6253. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  6254. {
  6255. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  6256. MAILBOX_t *mb = NULL;
  6257. struct lpfc_sli *psli = &phba->sli;
  6258. /* If the mailbox completed, process the completion and return */
  6259. if (lpfc_sli4_process_missed_mbox_completions(phba))
  6260. return;
  6261. if (pmbox != NULL)
  6262. mb = &pmbox->u.mb;
  6263. /* Check the pmbox pointer first. There is a race condition
  6264. * between the mbox timeout handler getting executed in the
  6265. * worklist and the mailbox actually completing. When this
  6266. * race condition occurs, the mbox_active will be NULL.
  6267. */
  6268. spin_lock_irq(&phba->hbalock);
  6269. if (pmbox == NULL) {
  6270. lpfc_printf_log(phba, KERN_WARNING,
  6271. LOG_MBOX | LOG_SLI,
  6272. "0353 Active Mailbox cleared - mailbox timeout "
  6273. "exiting\n");
  6274. spin_unlock_irq(&phba->hbalock);
  6275. return;
  6276. }
  6277. /* Mbox cmd <mbxCommand> timeout */
  6278. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6279. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  6280. mb->mbxCommand,
  6281. phba->pport->port_state,
  6282. phba->sli.sli_flag,
  6283. phba->sli.mbox_active);
  6284. spin_unlock_irq(&phba->hbalock);
  6285. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  6286. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  6287. * it to fail all outstanding SCSI IO.
  6288. */
  6289. spin_lock_irq(&phba->pport->work_port_lock);
  6290. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6291. spin_unlock_irq(&phba->pport->work_port_lock);
  6292. spin_lock_irq(&phba->hbalock);
  6293. phba->link_state = LPFC_LINK_UNKNOWN;
  6294. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6295. spin_unlock_irq(&phba->hbalock);
  6296. lpfc_sli_abort_fcp_rings(phba);
  6297. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6298. "0345 Resetting board due to mailbox timeout\n");
  6299. /* Reset the HBA device */
  6300. lpfc_reset_hba(phba);
  6301. }
  6302. /**
  6303. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  6304. * @phba: Pointer to HBA context object.
  6305. * @pmbox: Pointer to mailbox object.
  6306. * @flag: Flag indicating how the mailbox need to be processed.
  6307. *
  6308. * This function is called by discovery code and HBA management code
  6309. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  6310. * function gets the hbalock to protect the data structures.
  6311. * The mailbox command can be submitted in polling mode, in which case
  6312. * this function will wait in a polling loop for the completion of the
  6313. * mailbox.
  6314. * If the mailbox is submitted in no_wait mode (not polling) the
  6315. * function will submit the command and returns immediately without waiting
  6316. * for the mailbox completion. The no_wait is supported only when HBA
  6317. * is in SLI2/SLI3 mode - interrupts are enabled.
  6318. * The SLI interface allows only one mailbox pending at a time. If the
  6319. * mailbox is issued in polling mode and there is already a mailbox
  6320. * pending, then the function will return an error. If the mailbox is issued
  6321. * in NO_WAIT mode and there is a mailbox pending already, the function
  6322. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  6323. * The sli layer owns the mailbox object until the completion of mailbox
  6324. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  6325. * return codes the caller owns the mailbox command after the return of
  6326. * the function.
  6327. **/
  6328. static int
  6329. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  6330. uint32_t flag)
  6331. {
  6332. MAILBOX_t *mbx;
  6333. struct lpfc_sli *psli = &phba->sli;
  6334. uint32_t status, evtctr;
  6335. uint32_t ha_copy, hc_copy;
  6336. int i;
  6337. unsigned long timeout;
  6338. unsigned long drvr_flag = 0;
  6339. uint32_t word0, ldata;
  6340. void __iomem *to_slim;
  6341. int processing_queue = 0;
  6342. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6343. if (!pmbox) {
  6344. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6345. /* processing mbox queue from intr_handler */
  6346. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6347. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6348. return MBX_SUCCESS;
  6349. }
  6350. processing_queue = 1;
  6351. pmbox = lpfc_mbox_get(phba);
  6352. if (!pmbox) {
  6353. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6354. return MBX_SUCCESS;
  6355. }
  6356. }
  6357. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  6358. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  6359. if(!pmbox->vport) {
  6360. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6361. lpfc_printf_log(phba, KERN_ERR,
  6362. LOG_MBOX | LOG_VPORT,
  6363. "1806 Mbox x%x failed. No vport\n",
  6364. pmbox->u.mb.mbxCommand);
  6365. dump_stack();
  6366. goto out_not_finished;
  6367. }
  6368. }
  6369. /* If the PCI channel is in offline state, do not post mbox. */
  6370. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6371. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6372. goto out_not_finished;
  6373. }
  6374. /* If HBA has a deferred error attention, fail the iocb. */
  6375. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6376. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6377. goto out_not_finished;
  6378. }
  6379. psli = &phba->sli;
  6380. mbx = &pmbox->u.mb;
  6381. status = MBX_SUCCESS;
  6382. if (phba->link_state == LPFC_HBA_ERROR) {
  6383. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6384. /* Mbox command <mbxCommand> cannot issue */
  6385. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6386. "(%d):0311 Mailbox command x%x cannot "
  6387. "issue Data: x%x x%x\n",
  6388. pmbox->vport ? pmbox->vport->vpi : 0,
  6389. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6390. goto out_not_finished;
  6391. }
  6392. if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6393. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6394. !(hc_copy & HC_MBINT_ENA)) {
  6395. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6396. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6397. "(%d):2528 Mailbox command x%x cannot "
  6398. "issue Data: x%x x%x\n",
  6399. pmbox->vport ? pmbox->vport->vpi : 0,
  6400. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6401. goto out_not_finished;
  6402. }
  6403. }
  6404. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6405. /* Polling for a mbox command when another one is already active
  6406. * is not allowed in SLI. Also, the driver must have established
  6407. * SLI2 mode to queue and process multiple mbox commands.
  6408. */
  6409. if (flag & MBX_POLL) {
  6410. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6411. /* Mbox command <mbxCommand> cannot issue */
  6412. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6413. "(%d):2529 Mailbox command x%x "
  6414. "cannot issue Data: x%x x%x\n",
  6415. pmbox->vport ? pmbox->vport->vpi : 0,
  6416. pmbox->u.mb.mbxCommand,
  6417. psli->sli_flag, flag);
  6418. goto out_not_finished;
  6419. }
  6420. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6421. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6422. /* Mbox command <mbxCommand> cannot issue */
  6423. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6424. "(%d):2530 Mailbox command x%x "
  6425. "cannot issue Data: x%x x%x\n",
  6426. pmbox->vport ? pmbox->vport->vpi : 0,
  6427. pmbox->u.mb.mbxCommand,
  6428. psli->sli_flag, flag);
  6429. goto out_not_finished;
  6430. }
  6431. /* Another mailbox command is still being processed, queue this
  6432. * command to be processed later.
  6433. */
  6434. lpfc_mbox_put(phba, pmbox);
  6435. /* Mbox cmd issue - BUSY */
  6436. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6437. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6438. "x%x x%x x%x x%x\n",
  6439. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6440. mbx->mbxCommand, phba->pport->port_state,
  6441. psli->sli_flag, flag);
  6442. psli->slistat.mbox_busy++;
  6443. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6444. if (pmbox->vport) {
  6445. lpfc_debugfs_disc_trc(pmbox->vport,
  6446. LPFC_DISC_TRC_MBOX_VPORT,
  6447. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6448. (uint32_t)mbx->mbxCommand,
  6449. mbx->un.varWords[0], mbx->un.varWords[1]);
  6450. }
  6451. else {
  6452. lpfc_debugfs_disc_trc(phba->pport,
  6453. LPFC_DISC_TRC_MBOX,
  6454. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6455. (uint32_t)mbx->mbxCommand,
  6456. mbx->un.varWords[0], mbx->un.varWords[1]);
  6457. }
  6458. return MBX_BUSY;
  6459. }
  6460. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6461. /* If we are not polling, we MUST be in SLI2 mode */
  6462. if (flag != MBX_POLL) {
  6463. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6464. (mbx->mbxCommand != MBX_KILL_BOARD)) {
  6465. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6466. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6467. /* Mbox command <mbxCommand> cannot issue */
  6468. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6469. "(%d):2531 Mailbox command x%x "
  6470. "cannot issue Data: x%x x%x\n",
  6471. pmbox->vport ? pmbox->vport->vpi : 0,
  6472. pmbox->u.mb.mbxCommand,
  6473. psli->sli_flag, flag);
  6474. goto out_not_finished;
  6475. }
  6476. /* timeout active mbox command */
  6477. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6478. 1000);
  6479. mod_timer(&psli->mbox_tmo, jiffies + timeout);
  6480. }
  6481. /* Mailbox cmd <cmd> issue */
  6482. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6483. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6484. "x%x\n",
  6485. pmbox->vport ? pmbox->vport->vpi : 0,
  6486. mbx->mbxCommand, phba->pport->port_state,
  6487. psli->sli_flag, flag);
  6488. if (mbx->mbxCommand != MBX_HEARTBEAT) {
  6489. if (pmbox->vport) {
  6490. lpfc_debugfs_disc_trc(pmbox->vport,
  6491. LPFC_DISC_TRC_MBOX_VPORT,
  6492. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6493. (uint32_t)mbx->mbxCommand,
  6494. mbx->un.varWords[0], mbx->un.varWords[1]);
  6495. }
  6496. else {
  6497. lpfc_debugfs_disc_trc(phba->pport,
  6498. LPFC_DISC_TRC_MBOX,
  6499. "MBOX Send: cmd:x%x mb:x%x x%x",
  6500. (uint32_t)mbx->mbxCommand,
  6501. mbx->un.varWords[0], mbx->un.varWords[1]);
  6502. }
  6503. }
  6504. psli->slistat.mbox_cmd++;
  6505. evtctr = psli->slistat.mbox_event;
  6506. /* next set own bit for the adapter and copy over command word */
  6507. mbx->mbxOwner = OWN_CHIP;
  6508. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6509. /* Populate mbox extension offset word. */
  6510. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6511. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6512. = (uint8_t *)phba->mbox_ext
  6513. - (uint8_t *)phba->mbox;
  6514. }
  6515. /* Copy the mailbox extension data */
  6516. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6517. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6518. (uint8_t *)phba->mbox_ext,
  6519. pmbox->in_ext_byte_len);
  6520. }
  6521. /* Copy command data to host SLIM area */
  6522. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6523. } else {
  6524. /* Populate mbox extension offset word. */
  6525. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6526. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6527. = MAILBOX_HBA_EXT_OFFSET;
  6528. /* Copy the mailbox extension data */
  6529. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6530. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6531. MAILBOX_HBA_EXT_OFFSET,
  6532. pmbox->context2, pmbox->in_ext_byte_len);
  6533. }
  6534. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6535. /* copy command data into host mbox for cmpl */
  6536. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6537. }
  6538. /* First copy mbox command data to HBA SLIM, skip past first
  6539. word */
  6540. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6541. lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
  6542. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6543. /* Next copy over first word, with mbxOwner set */
  6544. ldata = *((uint32_t *)mbx);
  6545. to_slim = phba->MBslimaddr;
  6546. writel(ldata, to_slim);
  6547. readl(to_slim); /* flush */
  6548. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6549. /* switch over to host mailbox */
  6550. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6551. }
  6552. }
  6553. wmb();
  6554. switch (flag) {
  6555. case MBX_NOWAIT:
  6556. /* Set up reference to mailbox command */
  6557. psli->mbox_active = pmbox;
  6558. /* Interrupt board to do it */
  6559. writel(CA_MBATT, phba->CAregaddr);
  6560. readl(phba->CAregaddr); /* flush */
  6561. /* Don't wait for it to finish, just return */
  6562. break;
  6563. case MBX_POLL:
  6564. /* Set up null reference to mailbox command */
  6565. psli->mbox_active = NULL;
  6566. /* Interrupt board to do it */
  6567. writel(CA_MBATT, phba->CAregaddr);
  6568. readl(phba->CAregaddr); /* flush */
  6569. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6570. /* First read mbox status word */
  6571. word0 = *((uint32_t *)phba->mbox);
  6572. word0 = le32_to_cpu(word0);
  6573. } else {
  6574. /* First read mbox status word */
  6575. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6576. spin_unlock_irqrestore(&phba->hbalock,
  6577. drvr_flag);
  6578. goto out_not_finished;
  6579. }
  6580. }
  6581. /* Read the HBA Host Attention Register */
  6582. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6583. spin_unlock_irqrestore(&phba->hbalock,
  6584. drvr_flag);
  6585. goto out_not_finished;
  6586. }
  6587. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6588. 1000) + jiffies;
  6589. i = 0;
  6590. /* Wait for command to complete */
  6591. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6592. (!(ha_copy & HA_MBATT) &&
  6593. (phba->link_state > LPFC_WARM_START))) {
  6594. if (time_after(jiffies, timeout)) {
  6595. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6596. spin_unlock_irqrestore(&phba->hbalock,
  6597. drvr_flag);
  6598. goto out_not_finished;
  6599. }
  6600. /* Check if we took a mbox interrupt while we were
  6601. polling */
  6602. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6603. && (evtctr != psli->slistat.mbox_event))
  6604. break;
  6605. if (i++ > 10) {
  6606. spin_unlock_irqrestore(&phba->hbalock,
  6607. drvr_flag);
  6608. msleep(1);
  6609. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6610. }
  6611. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6612. /* First copy command data */
  6613. word0 = *((uint32_t *)phba->mbox);
  6614. word0 = le32_to_cpu(word0);
  6615. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6616. MAILBOX_t *slimmb;
  6617. uint32_t slimword0;
  6618. /* Check real SLIM for any errors */
  6619. slimword0 = readl(phba->MBslimaddr);
  6620. slimmb = (MAILBOX_t *) & slimword0;
  6621. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6622. && slimmb->mbxStatus) {
  6623. psli->sli_flag &=
  6624. ~LPFC_SLI_ACTIVE;
  6625. word0 = slimword0;
  6626. }
  6627. }
  6628. } else {
  6629. /* First copy command data */
  6630. word0 = readl(phba->MBslimaddr);
  6631. }
  6632. /* Read the HBA Host Attention Register */
  6633. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6634. spin_unlock_irqrestore(&phba->hbalock,
  6635. drvr_flag);
  6636. goto out_not_finished;
  6637. }
  6638. }
  6639. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6640. /* copy results back to user */
  6641. lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE);
  6642. /* Copy the mailbox extension data */
  6643. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6644. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6645. pmbox->context2,
  6646. pmbox->out_ext_byte_len);
  6647. }
  6648. } else {
  6649. /* First copy command data */
  6650. lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
  6651. MAILBOX_CMD_SIZE);
  6652. /* Copy the mailbox extension data */
  6653. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6654. lpfc_memcpy_from_slim(pmbox->context2,
  6655. phba->MBslimaddr +
  6656. MAILBOX_HBA_EXT_OFFSET,
  6657. pmbox->out_ext_byte_len);
  6658. }
  6659. }
  6660. writel(HA_MBATT, phba->HAregaddr);
  6661. readl(phba->HAregaddr); /* flush */
  6662. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6663. status = mbx->mbxStatus;
  6664. }
  6665. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6666. return status;
  6667. out_not_finished:
  6668. if (processing_queue) {
  6669. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6670. lpfc_mbox_cmpl_put(phba, pmbox);
  6671. }
  6672. return MBX_NOT_FINISHED;
  6673. }
  6674. /**
  6675. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6676. * @phba: Pointer to HBA context object.
  6677. *
  6678. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6679. * the driver internal pending mailbox queue. It will then try to wait out the
  6680. * possible outstanding mailbox command before return.
  6681. *
  6682. * Returns:
  6683. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6684. * the outstanding mailbox command timed out.
  6685. **/
  6686. static int
  6687. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6688. {
  6689. struct lpfc_sli *psli = &phba->sli;
  6690. int rc = 0;
  6691. unsigned long timeout = 0;
  6692. /* Mark the asynchronous mailbox command posting as blocked */
  6693. spin_lock_irq(&phba->hbalock);
  6694. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6695. /* Determine how long we might wait for the active mailbox
  6696. * command to be gracefully completed by firmware.
  6697. */
  6698. if (phba->sli.mbox_active)
  6699. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6700. phba->sli.mbox_active) *
  6701. 1000) + jiffies;
  6702. spin_unlock_irq(&phba->hbalock);
  6703. /* Make sure the mailbox is really active */
  6704. if (timeout)
  6705. lpfc_sli4_process_missed_mbox_completions(phba);
  6706. /* Wait for the outstnading mailbox command to complete */
  6707. while (phba->sli.mbox_active) {
  6708. /* Check active mailbox complete status every 2ms */
  6709. msleep(2);
  6710. if (time_after(jiffies, timeout)) {
  6711. /* Timeout, marked the outstanding cmd not complete */
  6712. rc = 1;
  6713. break;
  6714. }
  6715. }
  6716. /* Can not cleanly block async mailbox command, fails it */
  6717. if (rc) {
  6718. spin_lock_irq(&phba->hbalock);
  6719. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6720. spin_unlock_irq(&phba->hbalock);
  6721. }
  6722. return rc;
  6723. }
  6724. /**
  6725. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6726. * @phba: Pointer to HBA context object.
  6727. *
  6728. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6729. * commands from the driver internal pending mailbox queue. It makes sure
  6730. * that there is no outstanding mailbox command before resuming posting
  6731. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6732. * mailbox command, it will try to wait it out before resuming asynchronous
  6733. * mailbox command posting.
  6734. **/
  6735. static void
  6736. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6737. {
  6738. struct lpfc_sli *psli = &phba->sli;
  6739. spin_lock_irq(&phba->hbalock);
  6740. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6741. /* Asynchronous mailbox posting is not blocked, do nothing */
  6742. spin_unlock_irq(&phba->hbalock);
  6743. return;
  6744. }
  6745. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6746. * successful or timeout, after timing-out the outstanding mailbox
  6747. * command shall always be removed, so just unblock posting async
  6748. * mailbox command and resume
  6749. */
  6750. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6751. spin_unlock_irq(&phba->hbalock);
  6752. /* wake up worker thread to post asynchronlous mailbox command */
  6753. lpfc_worker_wake_up(phba);
  6754. }
  6755. /**
  6756. * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
  6757. * @phba: Pointer to HBA context object.
  6758. * @mboxq: Pointer to mailbox object.
  6759. *
  6760. * The function waits for the bootstrap mailbox register ready bit from
  6761. * port for twice the regular mailbox command timeout value.
  6762. *
  6763. * 0 - no timeout on waiting for bootstrap mailbox register ready.
  6764. * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
  6765. **/
  6766. static int
  6767. lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6768. {
  6769. uint32_t db_ready;
  6770. unsigned long timeout;
  6771. struct lpfc_register bmbx_reg;
  6772. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6773. * 1000) + jiffies;
  6774. do {
  6775. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6776. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6777. if (!db_ready)
  6778. msleep(2);
  6779. if (time_after(jiffies, timeout))
  6780. return MBXERR_ERROR;
  6781. } while (!db_ready);
  6782. return 0;
  6783. }
  6784. /**
  6785. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6786. * @phba: Pointer to HBA context object.
  6787. * @mboxq: Pointer to mailbox object.
  6788. *
  6789. * The function posts a mailbox to the port. The mailbox is expected
  6790. * to be comletely filled in and ready for the port to operate on it.
  6791. * This routine executes a synchronous completion operation on the
  6792. * mailbox by polling for its completion.
  6793. *
  6794. * The caller must not be holding any locks when calling this routine.
  6795. *
  6796. * Returns:
  6797. * MBX_SUCCESS - mailbox posted successfully
  6798. * Any of the MBX error values.
  6799. **/
  6800. static int
  6801. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6802. {
  6803. int rc = MBX_SUCCESS;
  6804. unsigned long iflag;
  6805. uint32_t mcqe_status;
  6806. uint32_t mbx_cmnd;
  6807. struct lpfc_sli *psli = &phba->sli;
  6808. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6809. struct lpfc_bmbx_create *mbox_rgn;
  6810. struct dma_address *dma_address;
  6811. /*
  6812. * Only one mailbox can be active to the bootstrap mailbox region
  6813. * at a time and there is no queueing provided.
  6814. */
  6815. spin_lock_irqsave(&phba->hbalock, iflag);
  6816. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6817. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6818. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6819. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6820. "cannot issue Data: x%x x%x\n",
  6821. mboxq->vport ? mboxq->vport->vpi : 0,
  6822. mboxq->u.mb.mbxCommand,
  6823. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6824. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6825. psli->sli_flag, MBX_POLL);
  6826. return MBXERR_ERROR;
  6827. }
  6828. /* The server grabs the token and owns it until release */
  6829. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6830. phba->sli.mbox_active = mboxq;
  6831. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6832. /* wait for bootstrap mbox register for readyness */
  6833. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6834. if (rc)
  6835. goto exit;
  6836. /*
  6837. * Initialize the bootstrap memory region to avoid stale data areas
  6838. * in the mailbox post. Then copy the caller's mailbox contents to
  6839. * the bmbx mailbox region.
  6840. */
  6841. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6842. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6843. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6844. sizeof(struct lpfc_mqe));
  6845. /* Post the high mailbox dma address to the port and wait for ready. */
  6846. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6847. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6848. /* wait for bootstrap mbox register for hi-address write done */
  6849. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6850. if (rc)
  6851. goto exit;
  6852. /* Post the low mailbox dma address to the port. */
  6853. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6854. /* wait for bootstrap mbox register for low address write done */
  6855. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6856. if (rc)
  6857. goto exit;
  6858. /*
  6859. * Read the CQ to ensure the mailbox has completed.
  6860. * If so, update the mailbox status so that the upper layers
  6861. * can complete the request normally.
  6862. */
  6863. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6864. sizeof(struct lpfc_mqe));
  6865. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6866. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6867. sizeof(struct lpfc_mcqe));
  6868. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6869. /*
  6870. * When the CQE status indicates a failure and the mailbox status
  6871. * indicates success then copy the CQE status into the mailbox status
  6872. * (and prefix it with x4000).
  6873. */
  6874. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6875. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6876. bf_set(lpfc_mqe_status, mb,
  6877. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6878. rc = MBXERR_ERROR;
  6879. } else
  6880. lpfc_sli4_swap_str(phba, mboxq);
  6881. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6882. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6883. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6884. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6885. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6886. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6887. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6888. bf_get(lpfc_mqe_status, mb),
  6889. mb->un.mb_words[0], mb->un.mb_words[1],
  6890. mb->un.mb_words[2], mb->un.mb_words[3],
  6891. mb->un.mb_words[4], mb->un.mb_words[5],
  6892. mb->un.mb_words[6], mb->un.mb_words[7],
  6893. mb->un.mb_words[8], mb->un.mb_words[9],
  6894. mb->un.mb_words[10], mb->un.mb_words[11],
  6895. mb->un.mb_words[12], mboxq->mcqe.word0,
  6896. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6897. mboxq->mcqe.trailer);
  6898. exit:
  6899. /* We are holding the token, no needed for lock when release */
  6900. spin_lock_irqsave(&phba->hbalock, iflag);
  6901. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6902. phba->sli.mbox_active = NULL;
  6903. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6904. return rc;
  6905. }
  6906. /**
  6907. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6908. * @phba: Pointer to HBA context object.
  6909. * @pmbox: Pointer to mailbox object.
  6910. * @flag: Flag indicating how the mailbox need to be processed.
  6911. *
  6912. * This function is called by discovery code and HBA management code to submit
  6913. * a mailbox command to firmware with SLI-4 interface spec.
  6914. *
  6915. * Return codes the caller owns the mailbox command after the return of the
  6916. * function.
  6917. **/
  6918. static int
  6919. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6920. uint32_t flag)
  6921. {
  6922. struct lpfc_sli *psli = &phba->sli;
  6923. unsigned long iflags;
  6924. int rc;
  6925. /* dump from issue mailbox command if setup */
  6926. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6927. rc = lpfc_mbox_dev_check(phba);
  6928. if (unlikely(rc)) {
  6929. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6930. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6931. "cannot issue Data: x%x x%x\n",
  6932. mboxq->vport ? mboxq->vport->vpi : 0,
  6933. mboxq->u.mb.mbxCommand,
  6934. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6935. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6936. psli->sli_flag, flag);
  6937. goto out_not_finished;
  6938. }
  6939. /* Detect polling mode and jump to a handler */
  6940. if (!phba->sli4_hba.intr_enable) {
  6941. if (flag == MBX_POLL)
  6942. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6943. else
  6944. rc = -EIO;
  6945. if (rc != MBX_SUCCESS)
  6946. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6947. "(%d):2541 Mailbox command x%x "
  6948. "(x%x/x%x) failure: "
  6949. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6950. "Data: x%x x%x\n,",
  6951. mboxq->vport ? mboxq->vport->vpi : 0,
  6952. mboxq->u.mb.mbxCommand,
  6953. lpfc_sli_config_mbox_subsys_get(phba,
  6954. mboxq),
  6955. lpfc_sli_config_mbox_opcode_get(phba,
  6956. mboxq),
  6957. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6958. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6959. bf_get(lpfc_mcqe_ext_status,
  6960. &mboxq->mcqe),
  6961. psli->sli_flag, flag);
  6962. return rc;
  6963. } else if (flag == MBX_POLL) {
  6964. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6965. "(%d):2542 Try to issue mailbox command "
  6966. "x%x (x%x/x%x) synchronously ahead of async"
  6967. "mailbox command queue: x%x x%x\n",
  6968. mboxq->vport ? mboxq->vport->vpi : 0,
  6969. mboxq->u.mb.mbxCommand,
  6970. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6971. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6972. psli->sli_flag, flag);
  6973. /* Try to block the asynchronous mailbox posting */
  6974. rc = lpfc_sli4_async_mbox_block(phba);
  6975. if (!rc) {
  6976. /* Successfully blocked, now issue sync mbox cmd */
  6977. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6978. if (rc != MBX_SUCCESS)
  6979. lpfc_printf_log(phba, KERN_WARNING,
  6980. LOG_MBOX | LOG_SLI,
  6981. "(%d):2597 Sync Mailbox command "
  6982. "x%x (x%x/x%x) failure: "
  6983. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6984. "Data: x%x x%x\n,",
  6985. mboxq->vport ? mboxq->vport->vpi : 0,
  6986. mboxq->u.mb.mbxCommand,
  6987. lpfc_sli_config_mbox_subsys_get(phba,
  6988. mboxq),
  6989. lpfc_sli_config_mbox_opcode_get(phba,
  6990. mboxq),
  6991. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6992. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6993. bf_get(lpfc_mcqe_ext_status,
  6994. &mboxq->mcqe),
  6995. psli->sli_flag, flag);
  6996. /* Unblock the async mailbox posting afterward */
  6997. lpfc_sli4_async_mbox_unblock(phba);
  6998. }
  6999. return rc;
  7000. }
  7001. /* Now, interrupt mode asynchrous mailbox command */
  7002. rc = lpfc_mbox_cmd_check(phba, mboxq);
  7003. if (rc) {
  7004. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  7005. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  7006. "cannot issue Data: x%x x%x\n",
  7007. mboxq->vport ? mboxq->vport->vpi : 0,
  7008. mboxq->u.mb.mbxCommand,
  7009. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7010. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7011. psli->sli_flag, flag);
  7012. goto out_not_finished;
  7013. }
  7014. /* Put the mailbox command to the driver internal FIFO */
  7015. psli->slistat.mbox_busy++;
  7016. spin_lock_irqsave(&phba->hbalock, iflags);
  7017. lpfc_mbox_put(phba, mboxq);
  7018. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7019. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  7020. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  7021. "x%x (x%x/x%x) x%x x%x x%x\n",
  7022. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  7023. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  7024. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7025. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7026. phba->pport->port_state,
  7027. psli->sli_flag, MBX_NOWAIT);
  7028. /* Wake up worker thread to transport mailbox command from head */
  7029. lpfc_worker_wake_up(phba);
  7030. return MBX_BUSY;
  7031. out_not_finished:
  7032. return MBX_NOT_FINISHED;
  7033. }
  7034. /**
  7035. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  7036. * @phba: Pointer to HBA context object.
  7037. *
  7038. * This function is called by worker thread to send a mailbox command to
  7039. * SLI4 HBA firmware.
  7040. *
  7041. **/
  7042. int
  7043. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  7044. {
  7045. struct lpfc_sli *psli = &phba->sli;
  7046. LPFC_MBOXQ_t *mboxq;
  7047. int rc = MBX_SUCCESS;
  7048. unsigned long iflags;
  7049. struct lpfc_mqe *mqe;
  7050. uint32_t mbx_cmnd;
  7051. /* Check interrupt mode before post async mailbox command */
  7052. if (unlikely(!phba->sli4_hba.intr_enable))
  7053. return MBX_NOT_FINISHED;
  7054. /* Check for mailbox command service token */
  7055. spin_lock_irqsave(&phba->hbalock, iflags);
  7056. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  7057. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7058. return MBX_NOT_FINISHED;
  7059. }
  7060. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  7061. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7062. return MBX_NOT_FINISHED;
  7063. }
  7064. if (unlikely(phba->sli.mbox_active)) {
  7065. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7066. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  7067. "0384 There is pending active mailbox cmd\n");
  7068. return MBX_NOT_FINISHED;
  7069. }
  7070. /* Take the mailbox command service token */
  7071. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  7072. /* Get the next mailbox command from head of queue */
  7073. mboxq = lpfc_mbox_get(phba);
  7074. /* If no more mailbox command waiting for post, we're done */
  7075. if (!mboxq) {
  7076. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7077. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7078. return MBX_SUCCESS;
  7079. }
  7080. phba->sli.mbox_active = mboxq;
  7081. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7082. /* Check device readiness for posting mailbox command */
  7083. rc = lpfc_mbox_dev_check(phba);
  7084. if (unlikely(rc))
  7085. /* Driver clean routine will clean up pending mailbox */
  7086. goto out_not_finished;
  7087. /* Prepare the mbox command to be posted */
  7088. mqe = &mboxq->u.mqe;
  7089. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  7090. /* Start timer for the mbox_tmo and log some mailbox post messages */
  7091. mod_timer(&psli->mbox_tmo, (jiffies +
  7092. msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
  7093. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  7094. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  7095. "x%x x%x\n",
  7096. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  7097. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7098. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7099. phba->pport->port_state, psli->sli_flag);
  7100. if (mbx_cmnd != MBX_HEARTBEAT) {
  7101. if (mboxq->vport) {
  7102. lpfc_debugfs_disc_trc(mboxq->vport,
  7103. LPFC_DISC_TRC_MBOX_VPORT,
  7104. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  7105. mbx_cmnd, mqe->un.mb_words[0],
  7106. mqe->un.mb_words[1]);
  7107. } else {
  7108. lpfc_debugfs_disc_trc(phba->pport,
  7109. LPFC_DISC_TRC_MBOX,
  7110. "MBOX Send: cmd:x%x mb:x%x x%x",
  7111. mbx_cmnd, mqe->un.mb_words[0],
  7112. mqe->un.mb_words[1]);
  7113. }
  7114. }
  7115. psli->slistat.mbox_cmd++;
  7116. /* Post the mailbox command to the port */
  7117. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  7118. if (rc != MBX_SUCCESS) {
  7119. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  7120. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  7121. "cannot issue Data: x%x x%x\n",
  7122. mboxq->vport ? mboxq->vport->vpi : 0,
  7123. mboxq->u.mb.mbxCommand,
  7124. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7125. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7126. psli->sli_flag, MBX_NOWAIT);
  7127. goto out_not_finished;
  7128. }
  7129. return rc;
  7130. out_not_finished:
  7131. spin_lock_irqsave(&phba->hbalock, iflags);
  7132. if (phba->sli.mbox_active) {
  7133. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  7134. __lpfc_mbox_cmpl_put(phba, mboxq);
  7135. /* Release the token */
  7136. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7137. phba->sli.mbox_active = NULL;
  7138. }
  7139. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7140. return MBX_NOT_FINISHED;
  7141. }
  7142. /**
  7143. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  7144. * @phba: Pointer to HBA context object.
  7145. * @pmbox: Pointer to mailbox object.
  7146. * @flag: Flag indicating how the mailbox need to be processed.
  7147. *
  7148. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  7149. * the API jump table function pointer from the lpfc_hba struct.
  7150. *
  7151. * Return codes the caller owns the mailbox command after the return of the
  7152. * function.
  7153. **/
  7154. int
  7155. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  7156. {
  7157. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  7158. }
  7159. /**
  7160. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  7161. * @phba: The hba struct for which this call is being executed.
  7162. * @dev_grp: The HBA PCI-Device group number.
  7163. *
  7164. * This routine sets up the mbox interface API function jump table in @phba
  7165. * struct.
  7166. * Returns: 0 - success, -ENODEV - failure.
  7167. **/
  7168. int
  7169. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7170. {
  7171. switch (dev_grp) {
  7172. case LPFC_PCI_DEV_LP:
  7173. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  7174. phba->lpfc_sli_handle_slow_ring_event =
  7175. lpfc_sli_handle_slow_ring_event_s3;
  7176. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  7177. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  7178. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  7179. break;
  7180. case LPFC_PCI_DEV_OC:
  7181. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  7182. phba->lpfc_sli_handle_slow_ring_event =
  7183. lpfc_sli_handle_slow_ring_event_s4;
  7184. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  7185. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  7186. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  7187. break;
  7188. default:
  7189. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7190. "1420 Invalid HBA PCI-device group: 0x%x\n",
  7191. dev_grp);
  7192. return -ENODEV;
  7193. break;
  7194. }
  7195. return 0;
  7196. }
  7197. /**
  7198. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  7199. * @phba: Pointer to HBA context object.
  7200. * @pring: Pointer to driver SLI ring object.
  7201. * @piocb: Pointer to address of newly added command iocb.
  7202. *
  7203. * This function is called with hbalock held to add a command
  7204. * iocb to the txq when SLI layer cannot submit the command iocb
  7205. * to the ring.
  7206. **/
  7207. void
  7208. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7209. struct lpfc_iocbq *piocb)
  7210. {
  7211. lockdep_assert_held(&phba->hbalock);
  7212. /* Insert the caller's iocb in the txq tail for later processing. */
  7213. list_add_tail(&piocb->list, &pring->txq);
  7214. }
  7215. /**
  7216. * lpfc_sli_next_iocb - Get the next iocb in the txq
  7217. * @phba: Pointer to HBA context object.
  7218. * @pring: Pointer to driver SLI ring object.
  7219. * @piocb: Pointer to address of newly added command iocb.
  7220. *
  7221. * This function is called with hbalock held before a new
  7222. * iocb is submitted to the firmware. This function checks
  7223. * txq to flush the iocbs in txq to Firmware before
  7224. * submitting new iocbs to the Firmware.
  7225. * If there are iocbs in the txq which need to be submitted
  7226. * to firmware, lpfc_sli_next_iocb returns the first element
  7227. * of the txq after dequeuing it from txq.
  7228. * If there is no iocb in the txq then the function will return
  7229. * *piocb and *piocb is set to NULL. Caller needs to check
  7230. * *piocb to find if there are more commands in the txq.
  7231. **/
  7232. static struct lpfc_iocbq *
  7233. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7234. struct lpfc_iocbq **piocb)
  7235. {
  7236. struct lpfc_iocbq * nextiocb;
  7237. lockdep_assert_held(&phba->hbalock);
  7238. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  7239. if (!nextiocb) {
  7240. nextiocb = *piocb;
  7241. *piocb = NULL;
  7242. }
  7243. return nextiocb;
  7244. }
  7245. /**
  7246. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  7247. * @phba: Pointer to HBA context object.
  7248. * @ring_number: SLI ring number to issue iocb on.
  7249. * @piocb: Pointer to command iocb.
  7250. * @flag: Flag indicating if this command can be put into txq.
  7251. *
  7252. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  7253. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  7254. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  7255. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  7256. * this function allows only iocbs for posting buffers. This function finds
  7257. * next available slot in the command ring and posts the command to the
  7258. * available slot and writes the port attention register to request HBA start
  7259. * processing new iocb. If there is no slot available in the ring and
  7260. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  7261. * the function returns IOCB_BUSY.
  7262. *
  7263. * This function is called with hbalock held. The function will return success
  7264. * after it successfully submit the iocb to firmware or after adding to the
  7265. * txq.
  7266. **/
  7267. static int
  7268. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  7269. struct lpfc_iocbq *piocb, uint32_t flag)
  7270. {
  7271. struct lpfc_iocbq *nextiocb;
  7272. IOCB_t *iocb;
  7273. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7274. lockdep_assert_held(&phba->hbalock);
  7275. if (piocb->iocb_cmpl && (!piocb->vport) &&
  7276. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  7277. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  7278. lpfc_printf_log(phba, KERN_ERR,
  7279. LOG_SLI | LOG_VPORT,
  7280. "1807 IOCB x%x failed. No vport\n",
  7281. piocb->iocb.ulpCommand);
  7282. dump_stack();
  7283. return IOCB_ERROR;
  7284. }
  7285. /* If the PCI channel is in offline state, do not post iocbs. */
  7286. if (unlikely(pci_channel_offline(phba->pcidev)))
  7287. return IOCB_ERROR;
  7288. /* If HBA has a deferred error attention, fail the iocb. */
  7289. if (unlikely(phba->hba_flag & DEFER_ERATT))
  7290. return IOCB_ERROR;
  7291. /*
  7292. * We should never get an IOCB if we are in a < LINK_DOWN state
  7293. */
  7294. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7295. return IOCB_ERROR;
  7296. /*
  7297. * Check to see if we are blocking IOCB processing because of a
  7298. * outstanding event.
  7299. */
  7300. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  7301. goto iocb_busy;
  7302. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  7303. /*
  7304. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  7305. * can be issued if the link is not up.
  7306. */
  7307. switch (piocb->iocb.ulpCommand) {
  7308. case CMD_GEN_REQUEST64_CR:
  7309. case CMD_GEN_REQUEST64_CX:
  7310. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  7311. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  7312. FC_RCTL_DD_UNSOL_CMD) ||
  7313. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  7314. MENLO_TRANSPORT_TYPE))
  7315. goto iocb_busy;
  7316. break;
  7317. case CMD_QUE_RING_BUF_CN:
  7318. case CMD_QUE_RING_BUF64_CN:
  7319. /*
  7320. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  7321. * completion, iocb_cmpl MUST be 0.
  7322. */
  7323. if (piocb->iocb_cmpl)
  7324. piocb->iocb_cmpl = NULL;
  7325. /*FALLTHROUGH*/
  7326. case CMD_CREATE_XRI_CR:
  7327. case CMD_CLOSE_XRI_CN:
  7328. case CMD_CLOSE_XRI_CX:
  7329. break;
  7330. default:
  7331. goto iocb_busy;
  7332. }
  7333. /*
  7334. * For FCP commands, we must be in a state where we can process link
  7335. * attention events.
  7336. */
  7337. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  7338. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  7339. goto iocb_busy;
  7340. }
  7341. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  7342. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  7343. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  7344. if (iocb)
  7345. lpfc_sli_update_ring(phba, pring);
  7346. else
  7347. lpfc_sli_update_full_ring(phba, pring);
  7348. if (!piocb)
  7349. return IOCB_SUCCESS;
  7350. goto out_busy;
  7351. iocb_busy:
  7352. pring->stats.iocb_cmd_delay++;
  7353. out_busy:
  7354. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7355. __lpfc_sli_ringtx_put(phba, pring, piocb);
  7356. return IOCB_SUCCESS;
  7357. }
  7358. return IOCB_BUSY;
  7359. }
  7360. /**
  7361. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  7362. * @phba: Pointer to HBA context object.
  7363. * @piocb: Pointer to command iocb.
  7364. * @sglq: Pointer to the scatter gather queue object.
  7365. *
  7366. * This routine converts the bpl or bde that is in the IOCB
  7367. * to a sgl list for the sli4 hardware. The physical address
  7368. * of the bpl/bde is converted back to a virtual address.
  7369. * If the IOCB contains a BPL then the list of BDE's is
  7370. * converted to sli4_sge's. If the IOCB contains a single
  7371. * BDE then it is converted to a single sli_sge.
  7372. * The IOCB is still in cpu endianess so the contents of
  7373. * the bpl can be used without byte swapping.
  7374. *
  7375. * Returns valid XRI = Success, NO_XRI = Failure.
  7376. **/
  7377. static uint16_t
  7378. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  7379. struct lpfc_sglq *sglq)
  7380. {
  7381. uint16_t xritag = NO_XRI;
  7382. struct ulp_bde64 *bpl = NULL;
  7383. struct ulp_bde64 bde;
  7384. struct sli4_sge *sgl = NULL;
  7385. struct lpfc_dmabuf *dmabuf;
  7386. IOCB_t *icmd;
  7387. int numBdes = 0;
  7388. int i = 0;
  7389. uint32_t offset = 0; /* accumulated offset in the sg request list */
  7390. int inbound = 0; /* number of sg reply entries inbound from firmware */
  7391. if (!piocbq || !sglq)
  7392. return xritag;
  7393. sgl = (struct sli4_sge *)sglq->sgl;
  7394. icmd = &piocbq->iocb;
  7395. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  7396. return sglq->sli4_xritag;
  7397. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7398. numBdes = icmd->un.genreq64.bdl.bdeSize /
  7399. sizeof(struct ulp_bde64);
  7400. /* The addrHigh and addrLow fields within the IOCB
  7401. * have not been byteswapped yet so there is no
  7402. * need to swap them back.
  7403. */
  7404. if (piocbq->context3)
  7405. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7406. else
  7407. return xritag;
  7408. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7409. if (!bpl)
  7410. return xritag;
  7411. for (i = 0; i < numBdes; i++) {
  7412. /* Should already be byte swapped. */
  7413. sgl->addr_hi = bpl->addrHigh;
  7414. sgl->addr_lo = bpl->addrLow;
  7415. sgl->word2 = le32_to_cpu(sgl->word2);
  7416. if ((i+1) == numBdes)
  7417. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7418. else
  7419. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7420. /* swap the size field back to the cpu so we
  7421. * can assign it to the sgl.
  7422. */
  7423. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7424. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7425. /* The offsets in the sgl need to be accumulated
  7426. * separately for the request and reply lists.
  7427. * The request is always first, the reply follows.
  7428. */
  7429. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7430. /* add up the reply sg entries */
  7431. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7432. inbound++;
  7433. /* first inbound? reset the offset */
  7434. if (inbound == 1)
  7435. offset = 0;
  7436. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7437. bf_set(lpfc_sli4_sge_type, sgl,
  7438. LPFC_SGE_TYPE_DATA);
  7439. offset += bde.tus.f.bdeSize;
  7440. }
  7441. sgl->word2 = cpu_to_le32(sgl->word2);
  7442. bpl++;
  7443. sgl++;
  7444. }
  7445. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7446. /* The addrHigh and addrLow fields of the BDE have not
  7447. * been byteswapped yet so they need to be swapped
  7448. * before putting them in the sgl.
  7449. */
  7450. sgl->addr_hi =
  7451. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7452. sgl->addr_lo =
  7453. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7454. sgl->word2 = le32_to_cpu(sgl->word2);
  7455. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7456. sgl->word2 = cpu_to_le32(sgl->word2);
  7457. sgl->sge_len =
  7458. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7459. }
  7460. return sglq->sli4_xritag;
  7461. }
  7462. /**
  7463. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7464. * @phba: Pointer to HBA context object.
  7465. * @piocb: Pointer to command iocb.
  7466. * @wqe: Pointer to the work queue entry.
  7467. *
  7468. * This routine converts the iocb command to its Work Queue Entry
  7469. * equivalent. The wqe pointer should not have any fields set when
  7470. * this routine is called because it will memcpy over them.
  7471. * This routine does not set the CQ_ID or the WQEC bits in the
  7472. * wqe.
  7473. *
  7474. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7475. **/
  7476. static int
  7477. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7478. union lpfc_wqe *wqe)
  7479. {
  7480. uint32_t xmit_len = 0, total_len = 0;
  7481. uint8_t ct = 0;
  7482. uint32_t fip;
  7483. uint32_t abort_tag;
  7484. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7485. uint8_t cmnd;
  7486. uint16_t xritag;
  7487. uint16_t abrt_iotag;
  7488. struct lpfc_iocbq *abrtiocbq;
  7489. struct ulp_bde64 *bpl = NULL;
  7490. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7491. int numBdes, i;
  7492. struct ulp_bde64 bde;
  7493. struct lpfc_nodelist *ndlp;
  7494. uint32_t *pcmd;
  7495. uint32_t if_type;
  7496. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7497. /* The fcp commands will set command type */
  7498. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7499. command_type = FCP_COMMAND;
  7500. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7501. command_type = ELS_COMMAND_FIP;
  7502. else
  7503. command_type = ELS_COMMAND_NON_FIP;
  7504. if (phba->fcp_embed_io)
  7505. memset(wqe, 0, sizeof(union lpfc_wqe128));
  7506. /* Some of the fields are in the right position already */
  7507. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7508. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7509. wqe->generic.wqe_com.word10 = 0;
  7510. abort_tag = (uint32_t) iocbq->iotag;
  7511. xritag = iocbq->sli4_xritag;
  7512. /* words0-2 bpl convert bde */
  7513. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7514. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7515. sizeof(struct ulp_bde64);
  7516. bpl = (struct ulp_bde64 *)
  7517. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7518. if (!bpl)
  7519. return IOCB_ERROR;
  7520. /* Should already be byte swapped. */
  7521. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7522. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7523. /* swap the size field back to the cpu so we
  7524. * can assign it to the sgl.
  7525. */
  7526. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7527. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7528. total_len = 0;
  7529. for (i = 0; i < numBdes; i++) {
  7530. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7531. total_len += bde.tus.f.bdeSize;
  7532. }
  7533. } else
  7534. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7535. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7536. cmnd = iocbq->iocb.ulpCommand;
  7537. switch (iocbq->iocb.ulpCommand) {
  7538. case CMD_ELS_REQUEST64_CR:
  7539. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7540. ndlp = iocbq->context_un.ndlp;
  7541. else
  7542. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7543. if (!iocbq->iocb.ulpLe) {
  7544. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7545. "2007 Only Limited Edition cmd Format"
  7546. " supported 0x%x\n",
  7547. iocbq->iocb.ulpCommand);
  7548. return IOCB_ERROR;
  7549. }
  7550. wqe->els_req.payload_len = xmit_len;
  7551. /* Els_reguest64 has a TMO */
  7552. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7553. iocbq->iocb.ulpTimeout);
  7554. /* Need a VF for word 4 set the vf bit*/
  7555. bf_set(els_req64_vf, &wqe->els_req, 0);
  7556. /* And a VFID for word 12 */
  7557. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7558. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7559. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7560. iocbq->iocb.ulpContext);
  7561. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7562. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7563. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7564. if (command_type == ELS_COMMAND_FIP)
  7565. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7566. >> LPFC_FIP_ELS_ID_SHIFT);
  7567. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7568. iocbq->context2)->virt);
  7569. if_type = bf_get(lpfc_sli_intf_if_type,
  7570. &phba->sli4_hba.sli_intf);
  7571. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7572. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7573. *pcmd == ELS_CMD_SCR ||
  7574. *pcmd == ELS_CMD_FDISC ||
  7575. *pcmd == ELS_CMD_LOGO ||
  7576. *pcmd == ELS_CMD_PLOGI)) {
  7577. bf_set(els_req64_sp, &wqe->els_req, 1);
  7578. bf_set(els_req64_sid, &wqe->els_req,
  7579. iocbq->vport->fc_myDID);
  7580. if ((*pcmd == ELS_CMD_FLOGI) &&
  7581. !(phba->fc_topology ==
  7582. LPFC_TOPOLOGY_LOOP))
  7583. bf_set(els_req64_sid, &wqe->els_req, 0);
  7584. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7585. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7586. phba->vpi_ids[iocbq->vport->vpi]);
  7587. } else if (pcmd && iocbq->context1) {
  7588. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7589. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7590. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7591. }
  7592. }
  7593. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7594. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7595. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7596. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7597. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7598. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7599. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7600. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7601. wqe->els_req.max_response_payload_len = total_len - xmit_len;
  7602. break;
  7603. case CMD_XMIT_SEQUENCE64_CX:
  7604. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7605. iocbq->iocb.un.ulpWord[3]);
  7606. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7607. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7608. /* The entire sequence is transmitted for this IOCB */
  7609. xmit_len = total_len;
  7610. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7611. if (phba->link_flag & LS_LOOPBACK_MODE)
  7612. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7613. case CMD_XMIT_SEQUENCE64_CR:
  7614. /* word3 iocb=io_tag32 wqe=reserved */
  7615. wqe->xmit_sequence.rsvd3 = 0;
  7616. /* word4 relative_offset memcpy */
  7617. /* word5 r_ctl/df_ctl memcpy */
  7618. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7619. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7620. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7621. LPFC_WQE_IOD_WRITE);
  7622. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7623. LPFC_WQE_LENLOC_WORD12);
  7624. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7625. wqe->xmit_sequence.xmit_len = xmit_len;
  7626. command_type = OTHER_COMMAND;
  7627. break;
  7628. case CMD_XMIT_BCAST64_CN:
  7629. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7630. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7631. /* word4 iocb=rsvd wqe=rsvd */
  7632. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7633. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7634. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7635. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7636. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7637. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7638. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7639. LPFC_WQE_LENLOC_WORD3);
  7640. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7641. break;
  7642. case CMD_FCP_IWRITE64_CR:
  7643. command_type = FCP_COMMAND_DATA_OUT;
  7644. /* word3 iocb=iotag wqe=payload_offset_len */
  7645. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7646. bf_set(payload_offset_len, &wqe->fcp_iwrite,
  7647. xmit_len + sizeof(struct fcp_rsp));
  7648. bf_set(cmd_buff_len, &wqe->fcp_iwrite,
  7649. 0);
  7650. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7651. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7652. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7653. iocbq->iocb.ulpFCP2Rcvy);
  7654. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7655. /* Always open the exchange */
  7656. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7657. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7658. LPFC_WQE_LENLOC_WORD4);
  7659. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7660. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7661. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7662. bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
  7663. bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
  7664. if (iocbq->priority) {
  7665. bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
  7666. (iocbq->priority << 1));
  7667. } else {
  7668. bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
  7669. (phba->cfg_XLanePriority << 1));
  7670. }
  7671. }
  7672. /* Note, word 10 is already initialized to 0 */
  7673. if (phba->fcp_embed_io) {
  7674. struct lpfc_scsi_buf *lpfc_cmd;
  7675. struct sli4_sge *sgl;
  7676. union lpfc_wqe128 *wqe128;
  7677. struct fcp_cmnd *fcp_cmnd;
  7678. uint32_t *ptr;
  7679. /* 128 byte wqe support here */
  7680. wqe128 = (union lpfc_wqe128 *)wqe;
  7681. lpfc_cmd = iocbq->context1;
  7682. sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  7683. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  7684. /* Word 0-2 - FCP_CMND */
  7685. wqe128->generic.bde.tus.f.bdeFlags =
  7686. BUFF_TYPE_BDE_IMMED;
  7687. wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
  7688. wqe128->generic.bde.addrHigh = 0;
  7689. wqe128->generic.bde.addrLow = 88; /* Word 22 */
  7690. bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1);
  7691. /* Word 22-29 FCP CMND Payload */
  7692. ptr = &wqe128->words[22];
  7693. memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
  7694. }
  7695. break;
  7696. case CMD_FCP_IREAD64_CR:
  7697. /* word3 iocb=iotag wqe=payload_offset_len */
  7698. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7699. bf_set(payload_offset_len, &wqe->fcp_iread,
  7700. xmit_len + sizeof(struct fcp_rsp));
  7701. bf_set(cmd_buff_len, &wqe->fcp_iread,
  7702. 0);
  7703. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7704. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7705. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7706. iocbq->iocb.ulpFCP2Rcvy);
  7707. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7708. /* Always open the exchange */
  7709. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7710. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7711. LPFC_WQE_LENLOC_WORD4);
  7712. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7713. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7714. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7715. bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
  7716. bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
  7717. if (iocbq->priority) {
  7718. bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
  7719. (iocbq->priority << 1));
  7720. } else {
  7721. bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
  7722. (phba->cfg_XLanePriority << 1));
  7723. }
  7724. }
  7725. /* Note, word 10 is already initialized to 0 */
  7726. if (phba->fcp_embed_io) {
  7727. struct lpfc_scsi_buf *lpfc_cmd;
  7728. struct sli4_sge *sgl;
  7729. union lpfc_wqe128 *wqe128;
  7730. struct fcp_cmnd *fcp_cmnd;
  7731. uint32_t *ptr;
  7732. /* 128 byte wqe support here */
  7733. wqe128 = (union lpfc_wqe128 *)wqe;
  7734. lpfc_cmd = iocbq->context1;
  7735. sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  7736. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  7737. /* Word 0-2 - FCP_CMND */
  7738. wqe128->generic.bde.tus.f.bdeFlags =
  7739. BUFF_TYPE_BDE_IMMED;
  7740. wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
  7741. wqe128->generic.bde.addrHigh = 0;
  7742. wqe128->generic.bde.addrLow = 88; /* Word 22 */
  7743. bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1);
  7744. /* Word 22-29 FCP CMND Payload */
  7745. ptr = &wqe128->words[22];
  7746. memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
  7747. }
  7748. break;
  7749. case CMD_FCP_ICMND64_CR:
  7750. /* word3 iocb=iotag wqe=payload_offset_len */
  7751. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7752. bf_set(payload_offset_len, &wqe->fcp_icmd,
  7753. xmit_len + sizeof(struct fcp_rsp));
  7754. bf_set(cmd_buff_len, &wqe->fcp_icmd,
  7755. 0);
  7756. /* word3 iocb=IO_TAG wqe=reserved */
  7757. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7758. /* Always open the exchange */
  7759. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7760. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7761. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7762. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7763. LPFC_WQE_LENLOC_NONE);
  7764. bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
  7765. iocbq->iocb.ulpFCP2Rcvy);
  7766. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7767. bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
  7768. bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
  7769. if (iocbq->priority) {
  7770. bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
  7771. (iocbq->priority << 1));
  7772. } else {
  7773. bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
  7774. (phba->cfg_XLanePriority << 1));
  7775. }
  7776. }
  7777. /* Note, word 10 is already initialized to 0 */
  7778. if (phba->fcp_embed_io) {
  7779. struct lpfc_scsi_buf *lpfc_cmd;
  7780. struct sli4_sge *sgl;
  7781. union lpfc_wqe128 *wqe128;
  7782. struct fcp_cmnd *fcp_cmnd;
  7783. uint32_t *ptr;
  7784. /* 128 byte wqe support here */
  7785. wqe128 = (union lpfc_wqe128 *)wqe;
  7786. lpfc_cmd = iocbq->context1;
  7787. sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  7788. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  7789. /* Word 0-2 - FCP_CMND */
  7790. wqe128->generic.bde.tus.f.bdeFlags =
  7791. BUFF_TYPE_BDE_IMMED;
  7792. wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
  7793. wqe128->generic.bde.addrHigh = 0;
  7794. wqe128->generic.bde.addrLow = 88; /* Word 22 */
  7795. bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1);
  7796. /* Word 22-29 FCP CMND Payload */
  7797. ptr = &wqe128->words[22];
  7798. memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
  7799. }
  7800. break;
  7801. case CMD_GEN_REQUEST64_CR:
  7802. /* For this command calculate the xmit length of the
  7803. * request bde.
  7804. */
  7805. xmit_len = 0;
  7806. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7807. sizeof(struct ulp_bde64);
  7808. for (i = 0; i < numBdes; i++) {
  7809. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7810. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7811. break;
  7812. xmit_len += bde.tus.f.bdeSize;
  7813. }
  7814. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7815. wqe->gen_req.request_payload_len = xmit_len;
  7816. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7817. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7818. /* word6 context tag copied in memcpy */
  7819. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7820. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7821. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7822. "2015 Invalid CT %x command 0x%x\n",
  7823. ct, iocbq->iocb.ulpCommand);
  7824. return IOCB_ERROR;
  7825. }
  7826. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7827. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7828. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7829. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7830. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7831. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7832. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7833. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7834. wqe->gen_req.max_response_payload_len = total_len - xmit_len;
  7835. command_type = OTHER_COMMAND;
  7836. break;
  7837. case CMD_XMIT_ELS_RSP64_CX:
  7838. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7839. /* words0-2 BDE memcpy */
  7840. /* word3 iocb=iotag32 wqe=response_payload_len */
  7841. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7842. /* word4 */
  7843. wqe->xmit_els_rsp.word4 = 0;
  7844. /* word5 iocb=rsvd wge=did */
  7845. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7846. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7847. if_type = bf_get(lpfc_sli_intf_if_type,
  7848. &phba->sli4_hba.sli_intf);
  7849. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7850. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7851. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7852. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7853. iocbq->vport->fc_myDID);
  7854. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7855. bf_set(wqe_els_did,
  7856. &wqe->xmit_els_rsp.wqe_dest, 0);
  7857. }
  7858. }
  7859. }
  7860. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7861. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7862. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7863. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7864. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7865. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7866. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7867. phba->vpi_ids[iocbq->vport->vpi]);
  7868. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7869. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7870. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7871. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7872. LPFC_WQE_LENLOC_WORD3);
  7873. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7874. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7875. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7876. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7877. iocbq->context2)->virt);
  7878. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7879. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7880. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7881. iocbq->vport->fc_myDID);
  7882. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7883. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7884. phba->vpi_ids[phba->pport->vpi]);
  7885. }
  7886. command_type = OTHER_COMMAND;
  7887. break;
  7888. case CMD_CLOSE_XRI_CN:
  7889. case CMD_ABORT_XRI_CN:
  7890. case CMD_ABORT_XRI_CX:
  7891. /* words 0-2 memcpy should be 0 rserved */
  7892. /* port will send abts */
  7893. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7894. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7895. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7896. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7897. } else
  7898. fip = 0;
  7899. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7900. /*
  7901. * The link is down, or the command was ELS_FIP
  7902. * so the fw does not need to send abts
  7903. * on the wire.
  7904. */
  7905. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7906. else
  7907. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7908. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7909. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7910. wqe->abort_cmd.rsrvd5 = 0;
  7911. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7912. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7913. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7914. /*
  7915. * The abort handler will send us CMD_ABORT_XRI_CN or
  7916. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7917. */
  7918. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7919. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7920. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7921. LPFC_WQE_LENLOC_NONE);
  7922. cmnd = CMD_ABORT_XRI_CX;
  7923. command_type = OTHER_COMMAND;
  7924. xritag = 0;
  7925. break;
  7926. case CMD_XMIT_BLS_RSP64_CX:
  7927. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7928. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7929. * we re-construct this WQE here based on information in
  7930. * iocbq from scratch.
  7931. */
  7932. memset(wqe, 0, sizeof(union lpfc_wqe));
  7933. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7934. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7935. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7936. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7937. LPFC_ABTS_UNSOL_INT) {
  7938. /* ABTS sent by initiator to CT exchange, the
  7939. * RX_ID field will be filled with the newly
  7940. * allocated responder XRI.
  7941. */
  7942. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7943. iocbq->sli4_xritag);
  7944. } else {
  7945. /* ABTS sent by responder to CT exchange, the
  7946. * RX_ID field will be filled with the responder
  7947. * RX_ID from ABTS.
  7948. */
  7949. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7950. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7951. }
  7952. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7953. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7954. /* Use CT=VPI */
  7955. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7956. ndlp->nlp_DID);
  7957. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7958. iocbq->iocb.ulpContext);
  7959. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7960. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7961. phba->vpi_ids[phba->pport->vpi]);
  7962. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7963. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7964. LPFC_WQE_LENLOC_NONE);
  7965. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7966. command_type = OTHER_COMMAND;
  7967. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7968. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7969. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7970. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7971. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7972. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7973. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7974. }
  7975. break;
  7976. case CMD_XRI_ABORTED_CX:
  7977. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7978. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7979. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7980. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7981. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7982. default:
  7983. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7984. "2014 Invalid command 0x%x\n",
  7985. iocbq->iocb.ulpCommand);
  7986. return IOCB_ERROR;
  7987. break;
  7988. }
  7989. if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
  7990. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
  7991. else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
  7992. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
  7993. else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
  7994. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
  7995. iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
  7996. LPFC_IO_DIF_INSERT);
  7997. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7998. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7999. wqe->generic.wqe_com.abort_tag = abort_tag;
  8000. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  8001. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  8002. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  8003. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  8004. return 0;
  8005. }
  8006. /**
  8007. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  8008. * @phba: Pointer to HBA context object.
  8009. * @ring_number: SLI ring number to issue iocb on.
  8010. * @piocb: Pointer to command iocb.
  8011. * @flag: Flag indicating if this command can be put into txq.
  8012. *
  8013. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  8014. * an iocb command to an HBA with SLI-4 interface spec.
  8015. *
  8016. * This function is called with hbalock held. The function will return success
  8017. * after it successfully submit the iocb to firmware or after adding to the
  8018. * txq.
  8019. **/
  8020. static int
  8021. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  8022. struct lpfc_iocbq *piocb, uint32_t flag)
  8023. {
  8024. struct lpfc_sglq *sglq;
  8025. union lpfc_wqe *wqe;
  8026. union lpfc_wqe128 wqe128;
  8027. struct lpfc_queue *wq;
  8028. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  8029. lockdep_assert_held(&phba->hbalock);
  8030. /*
  8031. * The WQE can be either 64 or 128 bytes,
  8032. * so allocate space on the stack assuming the largest.
  8033. */
  8034. wqe = (union lpfc_wqe *)&wqe128;
  8035. if (piocb->sli4_xritag == NO_XRI) {
  8036. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  8037. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  8038. sglq = NULL;
  8039. else {
  8040. if (!list_empty(&pring->txq)) {
  8041. if (!(flag & SLI_IOCB_RET_IOCB)) {
  8042. __lpfc_sli_ringtx_put(phba,
  8043. pring, piocb);
  8044. return IOCB_SUCCESS;
  8045. } else {
  8046. return IOCB_BUSY;
  8047. }
  8048. } else {
  8049. sglq = __lpfc_sli_get_sglq(phba, piocb);
  8050. if (!sglq) {
  8051. if (!(flag & SLI_IOCB_RET_IOCB)) {
  8052. __lpfc_sli_ringtx_put(phba,
  8053. pring,
  8054. piocb);
  8055. return IOCB_SUCCESS;
  8056. } else
  8057. return IOCB_BUSY;
  8058. }
  8059. }
  8060. }
  8061. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  8062. /* These IO's already have an XRI and a mapped sgl. */
  8063. sglq = NULL;
  8064. } else {
  8065. /*
  8066. * This is a continuation of a commandi,(CX) so this
  8067. * sglq is on the active list
  8068. */
  8069. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
  8070. if (!sglq)
  8071. return IOCB_ERROR;
  8072. }
  8073. if (sglq) {
  8074. piocb->sli4_lxritag = sglq->sli4_lxritag;
  8075. piocb->sli4_xritag = sglq->sli4_xritag;
  8076. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  8077. return IOCB_ERROR;
  8078. }
  8079. if (lpfc_sli4_iocb2wqe(phba, piocb, wqe))
  8080. return IOCB_ERROR;
  8081. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  8082. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  8083. if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) {
  8084. wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx];
  8085. } else {
  8086. wq = phba->sli4_hba.oas_wq;
  8087. }
  8088. if (lpfc_sli4_wq_put(wq, wqe))
  8089. return IOCB_ERROR;
  8090. } else {
  8091. if (unlikely(!phba->sli4_hba.els_wq))
  8092. return IOCB_ERROR;
  8093. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe))
  8094. return IOCB_ERROR;
  8095. }
  8096. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  8097. return 0;
  8098. }
  8099. /**
  8100. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  8101. *
  8102. * This routine wraps the actual lockless version for issusing IOCB function
  8103. * pointer from the lpfc_hba struct.
  8104. *
  8105. * Return codes:
  8106. * IOCB_ERROR - Error
  8107. * IOCB_SUCCESS - Success
  8108. * IOCB_BUSY - Busy
  8109. **/
  8110. int
  8111. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  8112. struct lpfc_iocbq *piocb, uint32_t flag)
  8113. {
  8114. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  8115. }
  8116. /**
  8117. * lpfc_sli_api_table_setup - Set up sli api function jump table
  8118. * @phba: The hba struct for which this call is being executed.
  8119. * @dev_grp: The HBA PCI-Device group number.
  8120. *
  8121. * This routine sets up the SLI interface API function jump table in @phba
  8122. * struct.
  8123. * Returns: 0 - success, -ENODEV - failure.
  8124. **/
  8125. int
  8126. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  8127. {
  8128. switch (dev_grp) {
  8129. case LPFC_PCI_DEV_LP:
  8130. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  8131. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  8132. break;
  8133. case LPFC_PCI_DEV_OC:
  8134. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  8135. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  8136. break;
  8137. default:
  8138. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8139. "1419 Invalid HBA PCI-device group: 0x%x\n",
  8140. dev_grp);
  8141. return -ENODEV;
  8142. break;
  8143. }
  8144. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  8145. return 0;
  8146. }
  8147. /**
  8148. * lpfc_sli_calc_ring - Calculates which ring to use
  8149. * @phba: Pointer to HBA context object.
  8150. * @ring_number: Initial ring
  8151. * @piocb: Pointer to command iocb.
  8152. *
  8153. * For SLI4, FCP IO can deferred to one fo many WQs, based on
  8154. * fcp_wqidx, thus we need to calculate the corresponding ring.
  8155. * Since ABORTS must go on the same WQ of the command they are
  8156. * aborting, we use command's fcp_wqidx.
  8157. */
  8158. static int
  8159. lpfc_sli_calc_ring(struct lpfc_hba *phba, uint32_t ring_number,
  8160. struct lpfc_iocbq *piocb)
  8161. {
  8162. if (phba->sli_rev < LPFC_SLI_REV4)
  8163. return ring_number;
  8164. if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
  8165. if (!(phba->cfg_fof) ||
  8166. (!(piocb->iocb_flag & LPFC_IO_FOF))) {
  8167. if (unlikely(!phba->sli4_hba.fcp_wq))
  8168. return LPFC_HBA_ERROR;
  8169. /*
  8170. * for abort iocb fcp_wqidx should already
  8171. * be setup based on what work queue we used.
  8172. */
  8173. if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX))
  8174. piocb->fcp_wqidx =
  8175. lpfc_sli4_scmd_to_wqidx_distr(phba,
  8176. piocb->context1);
  8177. ring_number = MAX_SLI3_CONFIGURED_RINGS +
  8178. piocb->fcp_wqidx;
  8179. } else {
  8180. if (unlikely(!phba->sli4_hba.oas_wq))
  8181. return LPFC_HBA_ERROR;
  8182. piocb->fcp_wqidx = 0;
  8183. ring_number = LPFC_FCP_OAS_RING;
  8184. }
  8185. }
  8186. return ring_number;
  8187. }
  8188. /**
  8189. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  8190. * @phba: Pointer to HBA context object.
  8191. * @pring: Pointer to driver SLI ring object.
  8192. * @piocb: Pointer to command iocb.
  8193. * @flag: Flag indicating if this command can be put into txq.
  8194. *
  8195. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  8196. * function. This function gets the hbalock and calls
  8197. * __lpfc_sli_issue_iocb function and will return the error returned
  8198. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  8199. * functions which do not hold hbalock.
  8200. **/
  8201. int
  8202. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  8203. struct lpfc_iocbq *piocb, uint32_t flag)
  8204. {
  8205. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8206. struct lpfc_sli_ring *pring;
  8207. struct lpfc_queue *fpeq;
  8208. struct lpfc_eqe *eqe;
  8209. unsigned long iflags;
  8210. int rc, idx;
  8211. if (phba->sli_rev == LPFC_SLI_REV4) {
  8212. ring_number = lpfc_sli_calc_ring(phba, ring_number, piocb);
  8213. if (unlikely(ring_number == LPFC_HBA_ERROR))
  8214. return IOCB_ERROR;
  8215. idx = piocb->fcp_wqidx;
  8216. pring = &phba->sli.ring[ring_number];
  8217. spin_lock_irqsave(&pring->ring_lock, iflags);
  8218. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  8219. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  8220. if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) {
  8221. fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
  8222. if (atomic_dec_and_test(&fcp_eq_hdl->
  8223. fcp_eq_in_use)) {
  8224. /* Get associated EQ with this index */
  8225. fpeq = phba->sli4_hba.hba_eq[idx];
  8226. /* Turn off interrupts from this EQ */
  8227. lpfc_sli4_eq_clr_intr(fpeq);
  8228. /*
  8229. * Process all the events on FCP EQ
  8230. */
  8231. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8232. lpfc_sli4_hba_handle_eqe(phba,
  8233. eqe, idx);
  8234. fpeq->EQ_processed++;
  8235. }
  8236. /* Always clear and re-arm the EQ */
  8237. lpfc_sli4_eq_release(fpeq,
  8238. LPFC_QUEUE_REARM);
  8239. }
  8240. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  8241. }
  8242. } else {
  8243. /* For now, SLI2/3 will still use hbalock */
  8244. spin_lock_irqsave(&phba->hbalock, iflags);
  8245. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  8246. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8247. }
  8248. return rc;
  8249. }
  8250. /**
  8251. * lpfc_extra_ring_setup - Extra ring setup function
  8252. * @phba: Pointer to HBA context object.
  8253. *
  8254. * This function is called while driver attaches with the
  8255. * HBA to setup the extra ring. The extra ring is used
  8256. * only when driver needs to support target mode functionality
  8257. * or IP over FC functionalities.
  8258. *
  8259. * This function is called with no lock held.
  8260. **/
  8261. static int
  8262. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  8263. {
  8264. struct lpfc_sli *psli;
  8265. struct lpfc_sli_ring *pring;
  8266. psli = &phba->sli;
  8267. /* Adjust cmd/rsp ring iocb entries more evenly */
  8268. /* Take some away from the FCP ring */
  8269. pring = &psli->ring[psli->fcp_ring];
  8270. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8271. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8272. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8273. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8274. /* and give them to the extra ring */
  8275. pring = &psli->ring[psli->extra_ring];
  8276. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8277. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8278. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8279. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8280. /* Setup default profile for this ring */
  8281. pring->iotag_max = 4096;
  8282. pring->num_mask = 1;
  8283. pring->prt[0].profile = 0; /* Mask 0 */
  8284. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  8285. pring->prt[0].type = phba->cfg_multi_ring_type;
  8286. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  8287. return 0;
  8288. }
  8289. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  8290. * @phba: Pointer to HBA context object.
  8291. * @iocbq: Pointer to iocb object.
  8292. *
  8293. * The async_event handler calls this routine when it receives
  8294. * an ASYNC_STATUS_CN event from the port. The port generates
  8295. * this event when an Abort Sequence request to an rport fails
  8296. * twice in succession. The abort could be originated by the
  8297. * driver or by the port. The ABTS could have been for an ELS
  8298. * or FCP IO. The port only generates this event when an ABTS
  8299. * fails to complete after one retry.
  8300. */
  8301. static void
  8302. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  8303. struct lpfc_iocbq *iocbq)
  8304. {
  8305. struct lpfc_nodelist *ndlp = NULL;
  8306. uint16_t rpi = 0, vpi = 0;
  8307. struct lpfc_vport *vport = NULL;
  8308. /* The rpi in the ulpContext is vport-sensitive. */
  8309. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  8310. rpi = iocbq->iocb.ulpContext;
  8311. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8312. "3092 Port generated ABTS async event "
  8313. "on vpi %d rpi %d status 0x%x\n",
  8314. vpi, rpi, iocbq->iocb.ulpStatus);
  8315. vport = lpfc_find_vport_by_vpid(phba, vpi);
  8316. if (!vport)
  8317. goto err_exit;
  8318. ndlp = lpfc_findnode_rpi(vport, rpi);
  8319. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  8320. goto err_exit;
  8321. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  8322. lpfc_sli_abts_recover_port(vport, ndlp);
  8323. return;
  8324. err_exit:
  8325. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8326. "3095 Event Context not found, no "
  8327. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  8328. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  8329. vpi, rpi);
  8330. }
  8331. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  8332. * @phba: pointer to HBA context object.
  8333. * @ndlp: nodelist pointer for the impacted rport.
  8334. * @axri: pointer to the wcqe containing the failed exchange.
  8335. *
  8336. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  8337. * port. The port generates this event when an abort exchange request to an
  8338. * rport fails twice in succession with no reply. The abort could be originated
  8339. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  8340. */
  8341. void
  8342. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  8343. struct lpfc_nodelist *ndlp,
  8344. struct sli4_wcqe_xri_aborted *axri)
  8345. {
  8346. struct lpfc_vport *vport;
  8347. uint32_t ext_status = 0;
  8348. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  8349. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8350. "3115 Node Context not found, driver "
  8351. "ignoring abts err event\n");
  8352. return;
  8353. }
  8354. vport = ndlp->vport;
  8355. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8356. "3116 Port generated FCP XRI ABORT event on "
  8357. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  8358. ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
  8359. bf_get(lpfc_wcqe_xa_xri, axri),
  8360. bf_get(lpfc_wcqe_xa_status, axri),
  8361. axri->parameter);
  8362. /*
  8363. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  8364. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  8365. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  8366. */
  8367. ext_status = axri->parameter & IOERR_PARAM_MASK;
  8368. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  8369. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  8370. lpfc_sli_abts_recover_port(vport, ndlp);
  8371. }
  8372. /**
  8373. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  8374. * @phba: Pointer to HBA context object.
  8375. * @pring: Pointer to driver SLI ring object.
  8376. * @iocbq: Pointer to iocb object.
  8377. *
  8378. * This function is called by the slow ring event handler
  8379. * function when there is an ASYNC event iocb in the ring.
  8380. * This function is called with no lock held.
  8381. * Currently this function handles only temperature related
  8382. * ASYNC events. The function decodes the temperature sensor
  8383. * event message and posts events for the management applications.
  8384. **/
  8385. static void
  8386. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  8387. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  8388. {
  8389. IOCB_t *icmd;
  8390. uint16_t evt_code;
  8391. struct temp_event temp_event_data;
  8392. struct Scsi_Host *shost;
  8393. uint32_t *iocb_w;
  8394. icmd = &iocbq->iocb;
  8395. evt_code = icmd->un.asyncstat.evt_code;
  8396. switch (evt_code) {
  8397. case ASYNC_TEMP_WARN:
  8398. case ASYNC_TEMP_SAFE:
  8399. temp_event_data.data = (uint32_t) icmd->ulpContext;
  8400. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  8401. if (evt_code == ASYNC_TEMP_WARN) {
  8402. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  8403. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  8404. "0347 Adapter is very hot, please take "
  8405. "corrective action. temperature : %d Celsius\n",
  8406. (uint32_t) icmd->ulpContext);
  8407. } else {
  8408. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  8409. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  8410. "0340 Adapter temperature is OK now. "
  8411. "temperature : %d Celsius\n",
  8412. (uint32_t) icmd->ulpContext);
  8413. }
  8414. /* Send temperature change event to applications */
  8415. shost = lpfc_shost_from_vport(phba->pport);
  8416. fc_host_post_vendor_event(shost, fc_get_event_number(),
  8417. sizeof(temp_event_data), (char *) &temp_event_data,
  8418. LPFC_NL_VENDOR_ID);
  8419. break;
  8420. case ASYNC_STATUS_CN:
  8421. lpfc_sli_abts_err_handler(phba, iocbq);
  8422. break;
  8423. default:
  8424. iocb_w = (uint32_t *) icmd;
  8425. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8426. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  8427. " evt_code 0x%x\n"
  8428. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  8429. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  8430. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  8431. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  8432. pring->ringno, icmd->un.asyncstat.evt_code,
  8433. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  8434. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  8435. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  8436. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  8437. break;
  8438. }
  8439. }
  8440. /**
  8441. * lpfc_sli_setup - SLI ring setup function
  8442. * @phba: Pointer to HBA context object.
  8443. *
  8444. * lpfc_sli_setup sets up rings of the SLI interface with
  8445. * number of iocbs per ring and iotags. This function is
  8446. * called while driver attach to the HBA and before the
  8447. * interrupts are enabled. So there is no need for locking.
  8448. *
  8449. * This function always returns 0.
  8450. **/
  8451. int
  8452. lpfc_sli_setup(struct lpfc_hba *phba)
  8453. {
  8454. int i, totiocbsize = 0;
  8455. struct lpfc_sli *psli = &phba->sli;
  8456. struct lpfc_sli_ring *pring;
  8457. psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
  8458. if (phba->sli_rev == LPFC_SLI_REV4)
  8459. psli->num_rings += phba->cfg_fcp_io_channel;
  8460. psli->sli_flag = 0;
  8461. psli->fcp_ring = LPFC_FCP_RING;
  8462. psli->next_ring = LPFC_FCP_NEXT_RING;
  8463. psli->extra_ring = LPFC_EXTRA_RING;
  8464. psli->iocbq_lookup = NULL;
  8465. psli->iocbq_lookup_len = 0;
  8466. psli->last_iotag = 0;
  8467. for (i = 0; i < psli->num_rings; i++) {
  8468. pring = &psli->ring[i];
  8469. switch (i) {
  8470. case LPFC_FCP_RING: /* ring 0 - FCP */
  8471. /* numCiocb and numRiocb are used in config_port */
  8472. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  8473. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  8474. pring->sli.sli3.numCiocb +=
  8475. SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8476. pring->sli.sli3.numRiocb +=
  8477. SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8478. pring->sli.sli3.numCiocb +=
  8479. SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8480. pring->sli.sli3.numRiocb +=
  8481. SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8482. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8483. SLI3_IOCB_CMD_SIZE :
  8484. SLI2_IOCB_CMD_SIZE;
  8485. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8486. SLI3_IOCB_RSP_SIZE :
  8487. SLI2_IOCB_RSP_SIZE;
  8488. pring->iotag_ctr = 0;
  8489. pring->iotag_max =
  8490. (phba->cfg_hba_queue_depth * 2);
  8491. pring->fast_iotag = pring->iotag_max;
  8492. pring->num_mask = 0;
  8493. break;
  8494. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  8495. /* numCiocb and numRiocb are used in config_port */
  8496. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  8497. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  8498. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8499. SLI3_IOCB_CMD_SIZE :
  8500. SLI2_IOCB_CMD_SIZE;
  8501. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8502. SLI3_IOCB_RSP_SIZE :
  8503. SLI2_IOCB_RSP_SIZE;
  8504. pring->iotag_max = phba->cfg_hba_queue_depth;
  8505. pring->num_mask = 0;
  8506. break;
  8507. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  8508. /* numCiocb and numRiocb are used in config_port */
  8509. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  8510. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  8511. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8512. SLI3_IOCB_CMD_SIZE :
  8513. SLI2_IOCB_CMD_SIZE;
  8514. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8515. SLI3_IOCB_RSP_SIZE :
  8516. SLI2_IOCB_RSP_SIZE;
  8517. pring->fast_iotag = 0;
  8518. pring->iotag_ctr = 0;
  8519. pring->iotag_max = 4096;
  8520. pring->lpfc_sli_rcv_async_status =
  8521. lpfc_sli_async_event_handler;
  8522. pring->num_mask = LPFC_MAX_RING_MASK;
  8523. pring->prt[0].profile = 0; /* Mask 0 */
  8524. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  8525. pring->prt[0].type = FC_TYPE_ELS;
  8526. pring->prt[0].lpfc_sli_rcv_unsol_event =
  8527. lpfc_els_unsol_event;
  8528. pring->prt[1].profile = 0; /* Mask 1 */
  8529. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  8530. pring->prt[1].type = FC_TYPE_ELS;
  8531. pring->prt[1].lpfc_sli_rcv_unsol_event =
  8532. lpfc_els_unsol_event;
  8533. pring->prt[2].profile = 0; /* Mask 2 */
  8534. /* NameServer Inquiry */
  8535. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  8536. /* NameServer */
  8537. pring->prt[2].type = FC_TYPE_CT;
  8538. pring->prt[2].lpfc_sli_rcv_unsol_event =
  8539. lpfc_ct_unsol_event;
  8540. pring->prt[3].profile = 0; /* Mask 3 */
  8541. /* NameServer response */
  8542. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8543. /* NameServer */
  8544. pring->prt[3].type = FC_TYPE_CT;
  8545. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8546. lpfc_ct_unsol_event;
  8547. break;
  8548. }
  8549. totiocbsize += (pring->sli.sli3.numCiocb *
  8550. pring->sli.sli3.sizeCiocb) +
  8551. (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
  8552. }
  8553. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8554. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8555. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8556. "SLI2 SLIM Data: x%x x%lx\n",
  8557. phba->brd_no, totiocbsize,
  8558. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8559. }
  8560. if (phba->cfg_multi_ring_support == 2)
  8561. lpfc_extra_ring_setup(phba);
  8562. return 0;
  8563. }
  8564. /**
  8565. * lpfc_sli_queue_setup - Queue initialization function
  8566. * @phba: Pointer to HBA context object.
  8567. *
  8568. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8569. * ring. This function also initializes ring indices of each ring.
  8570. * This function is called during the initialization of the SLI
  8571. * interface of an HBA.
  8572. * This function is called with no lock held and always returns
  8573. * 1.
  8574. **/
  8575. int
  8576. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8577. {
  8578. struct lpfc_sli *psli;
  8579. struct lpfc_sli_ring *pring;
  8580. int i;
  8581. psli = &phba->sli;
  8582. spin_lock_irq(&phba->hbalock);
  8583. INIT_LIST_HEAD(&psli->mboxq);
  8584. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8585. /* Initialize list headers for txq and txcmplq as double linked lists */
  8586. for (i = 0; i < psli->num_rings; i++) {
  8587. pring = &psli->ring[i];
  8588. pring->ringno = i;
  8589. pring->sli.sli3.next_cmdidx = 0;
  8590. pring->sli.sli3.local_getidx = 0;
  8591. pring->sli.sli3.cmdidx = 0;
  8592. pring->flag = 0;
  8593. INIT_LIST_HEAD(&pring->txq);
  8594. INIT_LIST_HEAD(&pring->txcmplq);
  8595. INIT_LIST_HEAD(&pring->iocb_continueq);
  8596. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8597. INIT_LIST_HEAD(&pring->postbufq);
  8598. spin_lock_init(&pring->ring_lock);
  8599. }
  8600. spin_unlock_irq(&phba->hbalock);
  8601. return 1;
  8602. }
  8603. /**
  8604. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8605. * @phba: Pointer to HBA context object.
  8606. *
  8607. * This routine flushes the mailbox command subsystem. It will unconditionally
  8608. * flush all the mailbox commands in the three possible stages in the mailbox
  8609. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8610. * command; and completed mailbox command queue. It is caller's responsibility
  8611. * to make sure that the driver is in the proper state to flush the mailbox
  8612. * command sub-system. Namely, the posting of mailbox commands into the
  8613. * pending mailbox command queue from the various clients must be stopped;
  8614. * either the HBA is in a state that it will never works on the outstanding
  8615. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8616. * mailbox command has been completed.
  8617. **/
  8618. static void
  8619. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8620. {
  8621. LIST_HEAD(completions);
  8622. struct lpfc_sli *psli = &phba->sli;
  8623. LPFC_MBOXQ_t *pmb;
  8624. unsigned long iflag;
  8625. /* Flush all the mailbox commands in the mbox system */
  8626. spin_lock_irqsave(&phba->hbalock, iflag);
  8627. /* The pending mailbox command queue */
  8628. list_splice_init(&phba->sli.mboxq, &completions);
  8629. /* The outstanding active mailbox command */
  8630. if (psli->mbox_active) {
  8631. list_add_tail(&psli->mbox_active->list, &completions);
  8632. psli->mbox_active = NULL;
  8633. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8634. }
  8635. /* The completed mailbox command queue */
  8636. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8637. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8638. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8639. while (!list_empty(&completions)) {
  8640. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8641. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8642. if (pmb->mbox_cmpl)
  8643. pmb->mbox_cmpl(phba, pmb);
  8644. }
  8645. }
  8646. /**
  8647. * lpfc_sli_host_down - Vport cleanup function
  8648. * @vport: Pointer to virtual port object.
  8649. *
  8650. * lpfc_sli_host_down is called to clean up the resources
  8651. * associated with a vport before destroying virtual
  8652. * port data structures.
  8653. * This function does following operations:
  8654. * - Free discovery resources associated with this virtual
  8655. * port.
  8656. * - Free iocbs associated with this virtual port in
  8657. * the txq.
  8658. * - Send abort for all iocb commands associated with this
  8659. * vport in txcmplq.
  8660. *
  8661. * This function is called with no lock held and always returns 1.
  8662. **/
  8663. int
  8664. lpfc_sli_host_down(struct lpfc_vport *vport)
  8665. {
  8666. LIST_HEAD(completions);
  8667. struct lpfc_hba *phba = vport->phba;
  8668. struct lpfc_sli *psli = &phba->sli;
  8669. struct lpfc_sli_ring *pring;
  8670. struct lpfc_iocbq *iocb, *next_iocb;
  8671. int i;
  8672. unsigned long flags = 0;
  8673. uint16_t prev_pring_flag;
  8674. lpfc_cleanup_discovery_resources(vport);
  8675. spin_lock_irqsave(&phba->hbalock, flags);
  8676. for (i = 0; i < psli->num_rings; i++) {
  8677. pring = &psli->ring[i];
  8678. prev_pring_flag = pring->flag;
  8679. /* Only slow rings */
  8680. if (pring->ringno == LPFC_ELS_RING) {
  8681. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8682. /* Set the lpfc data pending flag */
  8683. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8684. }
  8685. /*
  8686. * Error everything on the txq since these iocbs have not been
  8687. * given to the FW yet.
  8688. */
  8689. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8690. if (iocb->vport != vport)
  8691. continue;
  8692. list_move_tail(&iocb->list, &completions);
  8693. }
  8694. /* Next issue ABTS for everything on the txcmplq */
  8695. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8696. list) {
  8697. if (iocb->vport != vport)
  8698. continue;
  8699. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8700. }
  8701. pring->flag = prev_pring_flag;
  8702. }
  8703. spin_unlock_irqrestore(&phba->hbalock, flags);
  8704. /* Cancel all the IOCBs from the completions list */
  8705. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8706. IOERR_SLI_DOWN);
  8707. return 1;
  8708. }
  8709. /**
  8710. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8711. * @phba: Pointer to HBA context object.
  8712. *
  8713. * This function cleans up all iocb, buffers, mailbox commands
  8714. * while shutting down the HBA. This function is called with no
  8715. * lock held and always returns 1.
  8716. * This function does the following to cleanup driver resources:
  8717. * - Free discovery resources for each virtual port
  8718. * - Cleanup any pending fabric iocbs
  8719. * - Iterate through the iocb txq and free each entry
  8720. * in the list.
  8721. * - Free up any buffer posted to the HBA
  8722. * - Free mailbox commands in the mailbox queue.
  8723. **/
  8724. int
  8725. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8726. {
  8727. LIST_HEAD(completions);
  8728. struct lpfc_sli *psli = &phba->sli;
  8729. struct lpfc_sli_ring *pring;
  8730. struct lpfc_dmabuf *buf_ptr;
  8731. unsigned long flags = 0;
  8732. int i;
  8733. /* Shutdown the mailbox command sub-system */
  8734. lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
  8735. lpfc_hba_down_prep(phba);
  8736. lpfc_fabric_abort_hba(phba);
  8737. spin_lock_irqsave(&phba->hbalock, flags);
  8738. for (i = 0; i < psli->num_rings; i++) {
  8739. pring = &psli->ring[i];
  8740. /* Only slow rings */
  8741. if (pring->ringno == LPFC_ELS_RING) {
  8742. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8743. /* Set the lpfc data pending flag */
  8744. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8745. }
  8746. /*
  8747. * Error everything on the txq since these iocbs have not been
  8748. * given to the FW yet.
  8749. */
  8750. list_splice_init(&pring->txq, &completions);
  8751. }
  8752. spin_unlock_irqrestore(&phba->hbalock, flags);
  8753. /* Cancel all the IOCBs from the completions list */
  8754. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8755. IOERR_SLI_DOWN);
  8756. spin_lock_irqsave(&phba->hbalock, flags);
  8757. list_splice_init(&phba->elsbuf, &completions);
  8758. phba->elsbuf_cnt = 0;
  8759. phba->elsbuf_prev_cnt = 0;
  8760. spin_unlock_irqrestore(&phba->hbalock, flags);
  8761. while (!list_empty(&completions)) {
  8762. list_remove_head(&completions, buf_ptr,
  8763. struct lpfc_dmabuf, list);
  8764. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8765. kfree(buf_ptr);
  8766. }
  8767. /* Return any active mbox cmds */
  8768. del_timer_sync(&psli->mbox_tmo);
  8769. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8770. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8771. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8772. return 1;
  8773. }
  8774. /**
  8775. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8776. * @srcp: Source memory pointer.
  8777. * @destp: Destination memory pointer.
  8778. * @cnt: Number of words required to be copied.
  8779. *
  8780. * This function is used for copying data between driver memory
  8781. * and the SLI memory. This function also changes the endianness
  8782. * of each word if native endianness is different from SLI
  8783. * endianness. This function can be called with or without
  8784. * lock.
  8785. **/
  8786. void
  8787. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8788. {
  8789. uint32_t *src = srcp;
  8790. uint32_t *dest = destp;
  8791. uint32_t ldata;
  8792. int i;
  8793. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8794. ldata = *src;
  8795. ldata = le32_to_cpu(ldata);
  8796. *dest = ldata;
  8797. src++;
  8798. dest++;
  8799. }
  8800. }
  8801. /**
  8802. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8803. * @srcp: Source memory pointer.
  8804. * @destp: Destination memory pointer.
  8805. * @cnt: Number of words required to be copied.
  8806. *
  8807. * This function is used for copying data between a data structure
  8808. * with big endian representation to local endianness.
  8809. * This function can be called with or without lock.
  8810. **/
  8811. void
  8812. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8813. {
  8814. uint32_t *src = srcp;
  8815. uint32_t *dest = destp;
  8816. uint32_t ldata;
  8817. int i;
  8818. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8819. ldata = *src;
  8820. ldata = be32_to_cpu(ldata);
  8821. *dest = ldata;
  8822. src++;
  8823. dest++;
  8824. }
  8825. }
  8826. /**
  8827. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8828. * @phba: Pointer to HBA context object.
  8829. * @pring: Pointer to driver SLI ring object.
  8830. * @mp: Pointer to driver buffer object.
  8831. *
  8832. * This function is called with no lock held.
  8833. * It always return zero after adding the buffer to the postbufq
  8834. * buffer list.
  8835. **/
  8836. int
  8837. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8838. struct lpfc_dmabuf *mp)
  8839. {
  8840. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8841. later */
  8842. spin_lock_irq(&phba->hbalock);
  8843. list_add_tail(&mp->list, &pring->postbufq);
  8844. pring->postbufq_cnt++;
  8845. spin_unlock_irq(&phba->hbalock);
  8846. return 0;
  8847. }
  8848. /**
  8849. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8850. * @phba: Pointer to HBA context object.
  8851. *
  8852. * When HBQ is enabled, buffers are searched based on tags. This function
  8853. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8854. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8855. * does not conflict with tags of buffer posted for unsolicited events.
  8856. * The function returns the allocated tag. The function is called with
  8857. * no locks held.
  8858. **/
  8859. uint32_t
  8860. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8861. {
  8862. spin_lock_irq(&phba->hbalock);
  8863. phba->buffer_tag_count++;
  8864. /*
  8865. * Always set the QUE_BUFTAG_BIT to distiguish between
  8866. * a tag assigned by HBQ.
  8867. */
  8868. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8869. spin_unlock_irq(&phba->hbalock);
  8870. return phba->buffer_tag_count;
  8871. }
  8872. /**
  8873. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8874. * @phba: Pointer to HBA context object.
  8875. * @pring: Pointer to driver SLI ring object.
  8876. * @tag: Buffer tag.
  8877. *
  8878. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8879. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8880. * iocb is posted to the response ring with the tag of the buffer.
  8881. * This function searches the pring->postbufq list using the tag
  8882. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8883. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8884. * buffer is returned to the caller else NULL is returned.
  8885. * This function is called with no lock held.
  8886. **/
  8887. struct lpfc_dmabuf *
  8888. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8889. uint32_t tag)
  8890. {
  8891. struct lpfc_dmabuf *mp, *next_mp;
  8892. struct list_head *slp = &pring->postbufq;
  8893. /* Search postbufq, from the beginning, looking for a match on tag */
  8894. spin_lock_irq(&phba->hbalock);
  8895. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8896. if (mp->buffer_tag == tag) {
  8897. list_del_init(&mp->list);
  8898. pring->postbufq_cnt--;
  8899. spin_unlock_irq(&phba->hbalock);
  8900. return mp;
  8901. }
  8902. }
  8903. spin_unlock_irq(&phba->hbalock);
  8904. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8905. "0402 Cannot find virtual addr for buffer tag on "
  8906. "ring %d Data x%lx x%p x%p x%x\n",
  8907. pring->ringno, (unsigned long) tag,
  8908. slp->next, slp->prev, pring->postbufq_cnt);
  8909. return NULL;
  8910. }
  8911. /**
  8912. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8913. * @phba: Pointer to HBA context object.
  8914. * @pring: Pointer to driver SLI ring object.
  8915. * @phys: DMA address of the buffer.
  8916. *
  8917. * This function searches the buffer list using the dma_address
  8918. * of unsolicited event to find the driver's lpfc_dmabuf object
  8919. * corresponding to the dma_address. The function returns the
  8920. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8921. * This function is called by the ct and els unsolicited event
  8922. * handlers to get the buffer associated with the unsolicited
  8923. * event.
  8924. *
  8925. * This function is called with no lock held.
  8926. **/
  8927. struct lpfc_dmabuf *
  8928. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8929. dma_addr_t phys)
  8930. {
  8931. struct lpfc_dmabuf *mp, *next_mp;
  8932. struct list_head *slp = &pring->postbufq;
  8933. /* Search postbufq, from the beginning, looking for a match on phys */
  8934. spin_lock_irq(&phba->hbalock);
  8935. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8936. if (mp->phys == phys) {
  8937. list_del_init(&mp->list);
  8938. pring->postbufq_cnt--;
  8939. spin_unlock_irq(&phba->hbalock);
  8940. return mp;
  8941. }
  8942. }
  8943. spin_unlock_irq(&phba->hbalock);
  8944. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8945. "0410 Cannot find virtual addr for mapped buf on "
  8946. "ring %d Data x%llx x%p x%p x%x\n",
  8947. pring->ringno, (unsigned long long)phys,
  8948. slp->next, slp->prev, pring->postbufq_cnt);
  8949. return NULL;
  8950. }
  8951. /**
  8952. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8953. * @phba: Pointer to HBA context object.
  8954. * @cmdiocb: Pointer to driver command iocb object.
  8955. * @rspiocb: Pointer to driver response iocb object.
  8956. *
  8957. * This function is the completion handler for the abort iocbs for
  8958. * ELS commands. This function is called from the ELS ring event
  8959. * handler with no lock held. This function frees memory resources
  8960. * associated with the abort iocb.
  8961. **/
  8962. static void
  8963. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8964. struct lpfc_iocbq *rspiocb)
  8965. {
  8966. IOCB_t *irsp = &rspiocb->iocb;
  8967. uint16_t abort_iotag, abort_context;
  8968. struct lpfc_iocbq *abort_iocb = NULL;
  8969. if (irsp->ulpStatus) {
  8970. /*
  8971. * Assume that the port already completed and returned, or
  8972. * will return the iocb. Just Log the message.
  8973. */
  8974. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8975. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8976. spin_lock_irq(&phba->hbalock);
  8977. if (phba->sli_rev < LPFC_SLI_REV4) {
  8978. if (abort_iotag != 0 &&
  8979. abort_iotag <= phba->sli.last_iotag)
  8980. abort_iocb =
  8981. phba->sli.iocbq_lookup[abort_iotag];
  8982. } else
  8983. /* For sli4 the abort_tag is the XRI,
  8984. * so the abort routine puts the iotag of the iocb
  8985. * being aborted in the context field of the abort
  8986. * IOCB.
  8987. */
  8988. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8989. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8990. "0327 Cannot abort els iocb %p "
  8991. "with tag %x context %x, abort status %x, "
  8992. "abort code %x\n",
  8993. abort_iocb, abort_iotag, abort_context,
  8994. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8995. spin_unlock_irq(&phba->hbalock);
  8996. }
  8997. lpfc_sli_release_iocbq(phba, cmdiocb);
  8998. return;
  8999. }
  9000. /**
  9001. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  9002. * @phba: Pointer to HBA context object.
  9003. * @cmdiocb: Pointer to driver command iocb object.
  9004. * @rspiocb: Pointer to driver response iocb object.
  9005. *
  9006. * The function is called from SLI ring event handler with no
  9007. * lock held. This function is the completion handler for ELS commands
  9008. * which are aborted. The function frees memory resources used for
  9009. * the aborted ELS commands.
  9010. **/
  9011. static void
  9012. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  9013. struct lpfc_iocbq *rspiocb)
  9014. {
  9015. IOCB_t *irsp = &rspiocb->iocb;
  9016. /* ELS cmd tag <ulpIoTag> completes */
  9017. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  9018. "0139 Ignoring ELS cmd tag x%x completion Data: "
  9019. "x%x x%x x%x\n",
  9020. irsp->ulpIoTag, irsp->ulpStatus,
  9021. irsp->un.ulpWord[4], irsp->ulpTimeout);
  9022. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  9023. lpfc_ct_free_iocb(phba, cmdiocb);
  9024. else
  9025. lpfc_els_free_iocb(phba, cmdiocb);
  9026. return;
  9027. }
  9028. /**
  9029. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  9030. * @phba: Pointer to HBA context object.
  9031. * @pring: Pointer to driver SLI ring object.
  9032. * @cmdiocb: Pointer to driver command iocb object.
  9033. *
  9034. * This function issues an abort iocb for the provided command iocb down to
  9035. * the port. Other than the case the outstanding command iocb is an abort
  9036. * request, this function issues abort out unconditionally. This function is
  9037. * called with hbalock held. The function returns 0 when it fails due to
  9038. * memory allocation failure or when the command iocb is an abort request.
  9039. **/
  9040. static int
  9041. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  9042. struct lpfc_iocbq *cmdiocb)
  9043. {
  9044. struct lpfc_vport *vport = cmdiocb->vport;
  9045. struct lpfc_iocbq *abtsiocbp;
  9046. IOCB_t *icmd = NULL;
  9047. IOCB_t *iabt = NULL;
  9048. int ring_number;
  9049. int retval;
  9050. unsigned long iflags;
  9051. lockdep_assert_held(&phba->hbalock);
  9052. /*
  9053. * There are certain command types we don't want to abort. And we
  9054. * don't want to abort commands that are already in the process of
  9055. * being aborted.
  9056. */
  9057. icmd = &cmdiocb->iocb;
  9058. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  9059. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  9060. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  9061. return 0;
  9062. /* issue ABTS for this IOCB based on iotag */
  9063. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  9064. if (abtsiocbp == NULL)
  9065. return 0;
  9066. /* This signals the response to set the correct status
  9067. * before calling the completion handler
  9068. */
  9069. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  9070. iabt = &abtsiocbp->iocb;
  9071. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  9072. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  9073. if (phba->sli_rev == LPFC_SLI_REV4) {
  9074. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  9075. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  9076. }
  9077. else
  9078. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  9079. iabt->ulpLe = 1;
  9080. iabt->ulpClass = icmd->ulpClass;
  9081. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  9082. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  9083. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  9084. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  9085. if (cmdiocb->iocb_flag & LPFC_IO_FOF)
  9086. abtsiocbp->iocb_flag |= LPFC_IO_FOF;
  9087. if (phba->link_state >= LPFC_LINK_UP)
  9088. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  9089. else
  9090. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  9091. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  9092. abtsiocbp->vport = vport;
  9093. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  9094. "0339 Abort xri x%x, original iotag x%x, "
  9095. "abort cmd iotag x%x\n",
  9096. iabt->un.acxri.abortIoTag,
  9097. iabt->un.acxri.abortContextTag,
  9098. abtsiocbp->iotag);
  9099. if (phba->sli_rev == LPFC_SLI_REV4) {
  9100. ring_number =
  9101. lpfc_sli_calc_ring(phba, pring->ringno, abtsiocbp);
  9102. if (unlikely(ring_number == LPFC_HBA_ERROR))
  9103. return 0;
  9104. pring = &phba->sli.ring[ring_number];
  9105. /* Note: both hbalock and ring_lock need to be set here */
  9106. spin_lock_irqsave(&pring->ring_lock, iflags);
  9107. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  9108. abtsiocbp, 0);
  9109. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  9110. } else {
  9111. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  9112. abtsiocbp, 0);
  9113. }
  9114. if (retval)
  9115. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  9116. /*
  9117. * Caller to this routine should check for IOCB_ERROR
  9118. * and handle it properly. This routine no longer removes
  9119. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  9120. */
  9121. return retval;
  9122. }
  9123. /**
  9124. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  9125. * @phba: Pointer to HBA context object.
  9126. * @pring: Pointer to driver SLI ring object.
  9127. * @cmdiocb: Pointer to driver command iocb object.
  9128. *
  9129. * This function issues an abort iocb for the provided command iocb. In case
  9130. * of unloading, the abort iocb will not be issued to commands on the ELS
  9131. * ring. Instead, the callback function shall be changed to those commands
  9132. * so that nothing happens when them finishes. This function is called with
  9133. * hbalock held. The function returns 0 when the command iocb is an abort
  9134. * request.
  9135. **/
  9136. int
  9137. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  9138. struct lpfc_iocbq *cmdiocb)
  9139. {
  9140. struct lpfc_vport *vport = cmdiocb->vport;
  9141. int retval = IOCB_ERROR;
  9142. IOCB_t *icmd = NULL;
  9143. lockdep_assert_held(&phba->hbalock);
  9144. /*
  9145. * There are certain command types we don't want to abort. And we
  9146. * don't want to abort commands that are already in the process of
  9147. * being aborted.
  9148. */
  9149. icmd = &cmdiocb->iocb;
  9150. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  9151. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  9152. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  9153. return 0;
  9154. /*
  9155. * If we're unloading, don't abort iocb on the ELS ring, but change
  9156. * the callback so that nothing happens when it finishes.
  9157. */
  9158. if ((vport->load_flag & FC_UNLOADING) &&
  9159. (pring->ringno == LPFC_ELS_RING)) {
  9160. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  9161. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  9162. else
  9163. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  9164. goto abort_iotag_exit;
  9165. }
  9166. /* Now, we try to issue the abort to the cmdiocb out */
  9167. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  9168. abort_iotag_exit:
  9169. /*
  9170. * Caller to this routine should check for IOCB_ERROR
  9171. * and handle it properly. This routine no longer removes
  9172. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  9173. */
  9174. return retval;
  9175. }
  9176. /**
  9177. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  9178. * @phba: pointer to lpfc HBA data structure.
  9179. *
  9180. * This routine will abort all pending and outstanding iocbs to an HBA.
  9181. **/
  9182. void
  9183. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  9184. {
  9185. struct lpfc_sli *psli = &phba->sli;
  9186. struct lpfc_sli_ring *pring;
  9187. int i;
  9188. for (i = 0; i < psli->num_rings; i++) {
  9189. pring = &psli->ring[i];
  9190. lpfc_sli_abort_iocb_ring(phba, pring);
  9191. }
  9192. }
  9193. /**
  9194. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  9195. * @iocbq: Pointer to driver iocb object.
  9196. * @vport: Pointer to driver virtual port object.
  9197. * @tgt_id: SCSI ID of the target.
  9198. * @lun_id: LUN ID of the scsi device.
  9199. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  9200. *
  9201. * This function acts as an iocb filter for functions which abort or count
  9202. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  9203. * 0 if the filtering criteria is met for the given iocb and will return
  9204. * 1 if the filtering criteria is not met.
  9205. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  9206. * given iocb is for the SCSI device specified by vport, tgt_id and
  9207. * lun_id parameter.
  9208. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  9209. * given iocb is for the SCSI target specified by vport and tgt_id
  9210. * parameters.
  9211. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  9212. * given iocb is for the SCSI host associated with the given vport.
  9213. * This function is called with no locks held.
  9214. **/
  9215. static int
  9216. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  9217. uint16_t tgt_id, uint64_t lun_id,
  9218. lpfc_ctx_cmd ctx_cmd)
  9219. {
  9220. struct lpfc_scsi_buf *lpfc_cmd;
  9221. int rc = 1;
  9222. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  9223. return rc;
  9224. if (iocbq->vport != vport)
  9225. return rc;
  9226. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  9227. if (lpfc_cmd->pCmd == NULL)
  9228. return rc;
  9229. switch (ctx_cmd) {
  9230. case LPFC_CTX_LUN:
  9231. if ((lpfc_cmd->rdata->pnode) &&
  9232. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  9233. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  9234. rc = 0;
  9235. break;
  9236. case LPFC_CTX_TGT:
  9237. if ((lpfc_cmd->rdata->pnode) &&
  9238. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  9239. rc = 0;
  9240. break;
  9241. case LPFC_CTX_HOST:
  9242. rc = 0;
  9243. break;
  9244. default:
  9245. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  9246. __func__, ctx_cmd);
  9247. break;
  9248. }
  9249. return rc;
  9250. }
  9251. /**
  9252. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  9253. * @vport: Pointer to virtual port.
  9254. * @tgt_id: SCSI ID of the target.
  9255. * @lun_id: LUN ID of the scsi device.
  9256. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9257. *
  9258. * This function returns number of FCP commands pending for the vport.
  9259. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  9260. * commands pending on the vport associated with SCSI device specified
  9261. * by tgt_id and lun_id parameters.
  9262. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  9263. * commands pending on the vport associated with SCSI target specified
  9264. * by tgt_id parameter.
  9265. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  9266. * commands pending on the vport.
  9267. * This function returns the number of iocbs which satisfy the filter.
  9268. * This function is called without any lock held.
  9269. **/
  9270. int
  9271. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  9272. lpfc_ctx_cmd ctx_cmd)
  9273. {
  9274. struct lpfc_hba *phba = vport->phba;
  9275. struct lpfc_iocbq *iocbq;
  9276. int sum, i;
  9277. spin_lock_irq(&phba->hbalock);
  9278. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  9279. iocbq = phba->sli.iocbq_lookup[i];
  9280. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  9281. ctx_cmd) == 0)
  9282. sum++;
  9283. }
  9284. spin_unlock_irq(&phba->hbalock);
  9285. return sum;
  9286. }
  9287. /**
  9288. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  9289. * @phba: Pointer to HBA context object
  9290. * @cmdiocb: Pointer to command iocb object.
  9291. * @rspiocb: Pointer to response iocb object.
  9292. *
  9293. * This function is called when an aborted FCP iocb completes. This
  9294. * function is called by the ring event handler with no lock held.
  9295. * This function frees the iocb.
  9296. **/
  9297. void
  9298. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  9299. struct lpfc_iocbq *rspiocb)
  9300. {
  9301. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9302. "3096 ABORT_XRI_CN completing on rpi x%x "
  9303. "original iotag x%x, abort cmd iotag x%x "
  9304. "status 0x%x, reason 0x%x\n",
  9305. cmdiocb->iocb.un.acxri.abortContextTag,
  9306. cmdiocb->iocb.un.acxri.abortIoTag,
  9307. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  9308. rspiocb->iocb.un.ulpWord[4]);
  9309. lpfc_sli_release_iocbq(phba, cmdiocb);
  9310. return;
  9311. }
  9312. /**
  9313. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  9314. * @vport: Pointer to virtual port.
  9315. * @pring: Pointer to driver SLI ring object.
  9316. * @tgt_id: SCSI ID of the target.
  9317. * @lun_id: LUN ID of the scsi device.
  9318. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9319. *
  9320. * This function sends an abort command for every SCSI command
  9321. * associated with the given virtual port pending on the ring
  9322. * filtered by lpfc_sli_validate_fcp_iocb function.
  9323. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  9324. * FCP iocbs associated with lun specified by tgt_id and lun_id
  9325. * parameters
  9326. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  9327. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  9328. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  9329. * FCP iocbs associated with virtual port.
  9330. * This function returns number of iocbs it failed to abort.
  9331. * This function is called with no locks held.
  9332. **/
  9333. int
  9334. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  9335. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  9336. {
  9337. struct lpfc_hba *phba = vport->phba;
  9338. struct lpfc_iocbq *iocbq;
  9339. struct lpfc_iocbq *abtsiocb;
  9340. IOCB_t *cmd = NULL;
  9341. int errcnt = 0, ret_val = 0;
  9342. int i;
  9343. for (i = 1; i <= phba->sli.last_iotag; i++) {
  9344. iocbq = phba->sli.iocbq_lookup[i];
  9345. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  9346. abort_cmd) != 0)
  9347. continue;
  9348. /*
  9349. * If the iocbq is already being aborted, don't take a second
  9350. * action, but do count it.
  9351. */
  9352. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  9353. continue;
  9354. /* issue ABTS for this IOCB based on iotag */
  9355. abtsiocb = lpfc_sli_get_iocbq(phba);
  9356. if (abtsiocb == NULL) {
  9357. errcnt++;
  9358. continue;
  9359. }
  9360. /* indicate the IO is being aborted by the driver. */
  9361. iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
  9362. cmd = &iocbq->iocb;
  9363. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  9364. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  9365. if (phba->sli_rev == LPFC_SLI_REV4)
  9366. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  9367. else
  9368. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  9369. abtsiocb->iocb.ulpLe = 1;
  9370. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  9371. abtsiocb->vport = vport;
  9372. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  9373. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  9374. if (iocbq->iocb_flag & LPFC_IO_FCP)
  9375. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  9376. if (iocbq->iocb_flag & LPFC_IO_FOF)
  9377. abtsiocb->iocb_flag |= LPFC_IO_FOF;
  9378. if (lpfc_is_link_up(phba))
  9379. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  9380. else
  9381. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  9382. /* Setup callback routine and issue the command. */
  9383. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  9384. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  9385. abtsiocb, 0);
  9386. if (ret_val == IOCB_ERROR) {
  9387. lpfc_sli_release_iocbq(phba, abtsiocb);
  9388. errcnt++;
  9389. continue;
  9390. }
  9391. }
  9392. return errcnt;
  9393. }
  9394. /**
  9395. * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
  9396. * @vport: Pointer to virtual port.
  9397. * @pring: Pointer to driver SLI ring object.
  9398. * @tgt_id: SCSI ID of the target.
  9399. * @lun_id: LUN ID of the scsi device.
  9400. * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9401. *
  9402. * This function sends an abort command for every SCSI command
  9403. * associated with the given virtual port pending on the ring
  9404. * filtered by lpfc_sli_validate_fcp_iocb function.
  9405. * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
  9406. * FCP iocbs associated with lun specified by tgt_id and lun_id
  9407. * parameters
  9408. * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
  9409. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  9410. * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
  9411. * FCP iocbs associated with virtual port.
  9412. * This function returns number of iocbs it aborted .
  9413. * This function is called with no locks held right after a taskmgmt
  9414. * command is sent.
  9415. **/
  9416. int
  9417. lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  9418. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
  9419. {
  9420. struct lpfc_hba *phba = vport->phba;
  9421. struct lpfc_scsi_buf *lpfc_cmd;
  9422. struct lpfc_iocbq *abtsiocbq;
  9423. struct lpfc_nodelist *ndlp;
  9424. struct lpfc_iocbq *iocbq;
  9425. IOCB_t *icmd;
  9426. int sum, i, ret_val;
  9427. unsigned long iflags;
  9428. struct lpfc_sli_ring *pring_s4;
  9429. uint32_t ring_number;
  9430. spin_lock_irq(&phba->hbalock);
  9431. /* all I/Os are in process of being flushed */
  9432. if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
  9433. spin_unlock_irq(&phba->hbalock);
  9434. return 0;
  9435. }
  9436. sum = 0;
  9437. for (i = 1; i <= phba->sli.last_iotag; i++) {
  9438. iocbq = phba->sli.iocbq_lookup[i];
  9439. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  9440. cmd) != 0)
  9441. continue;
  9442. /*
  9443. * If the iocbq is already being aborted, don't take a second
  9444. * action, but do count it.
  9445. */
  9446. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  9447. continue;
  9448. /* issue ABTS for this IOCB based on iotag */
  9449. abtsiocbq = __lpfc_sli_get_iocbq(phba);
  9450. if (abtsiocbq == NULL)
  9451. continue;
  9452. icmd = &iocbq->iocb;
  9453. abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  9454. abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
  9455. if (phba->sli_rev == LPFC_SLI_REV4)
  9456. abtsiocbq->iocb.un.acxri.abortIoTag =
  9457. iocbq->sli4_xritag;
  9458. else
  9459. abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
  9460. abtsiocbq->iocb.ulpLe = 1;
  9461. abtsiocbq->iocb.ulpClass = icmd->ulpClass;
  9462. abtsiocbq->vport = vport;
  9463. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  9464. abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx;
  9465. if (iocbq->iocb_flag & LPFC_IO_FCP)
  9466. abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
  9467. if (iocbq->iocb_flag & LPFC_IO_FOF)
  9468. abtsiocbq->iocb_flag |= LPFC_IO_FOF;
  9469. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  9470. ndlp = lpfc_cmd->rdata->pnode;
  9471. if (lpfc_is_link_up(phba) &&
  9472. (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
  9473. abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  9474. else
  9475. abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  9476. /* Setup callback routine and issue the command. */
  9477. abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  9478. /*
  9479. * Indicate the IO is being aborted by the driver and set
  9480. * the caller's flag into the aborted IO.
  9481. */
  9482. iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
  9483. if (phba->sli_rev == LPFC_SLI_REV4) {
  9484. ring_number = MAX_SLI3_CONFIGURED_RINGS +
  9485. iocbq->fcp_wqidx;
  9486. pring_s4 = &phba->sli.ring[ring_number];
  9487. /* Note: both hbalock and ring_lock must be set here */
  9488. spin_lock_irqsave(&pring_s4->ring_lock, iflags);
  9489. ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
  9490. abtsiocbq, 0);
  9491. spin_unlock_irqrestore(&pring_s4->ring_lock, iflags);
  9492. } else {
  9493. ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
  9494. abtsiocbq, 0);
  9495. }
  9496. if (ret_val == IOCB_ERROR)
  9497. __lpfc_sli_release_iocbq(phba, abtsiocbq);
  9498. else
  9499. sum++;
  9500. }
  9501. spin_unlock_irq(&phba->hbalock);
  9502. return sum;
  9503. }
  9504. /**
  9505. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  9506. * @phba: Pointer to HBA context object.
  9507. * @cmdiocbq: Pointer to command iocb.
  9508. * @rspiocbq: Pointer to response iocb.
  9509. *
  9510. * This function is the completion handler for iocbs issued using
  9511. * lpfc_sli_issue_iocb_wait function. This function is called by the
  9512. * ring event handler function without any lock held. This function
  9513. * can be called from both worker thread context and interrupt
  9514. * context. This function also can be called from other thread which
  9515. * cleans up the SLI layer objects.
  9516. * This function copy the contents of the response iocb to the
  9517. * response iocb memory object provided by the caller of
  9518. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  9519. * sleeps for the iocb completion.
  9520. **/
  9521. static void
  9522. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  9523. struct lpfc_iocbq *cmdiocbq,
  9524. struct lpfc_iocbq *rspiocbq)
  9525. {
  9526. wait_queue_head_t *pdone_q;
  9527. unsigned long iflags;
  9528. struct lpfc_scsi_buf *lpfc_cmd;
  9529. spin_lock_irqsave(&phba->hbalock, iflags);
  9530. if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
  9531. /*
  9532. * A time out has occurred for the iocb. If a time out
  9533. * completion handler has been supplied, call it. Otherwise,
  9534. * just free the iocbq.
  9535. */
  9536. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9537. cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
  9538. cmdiocbq->wait_iocb_cmpl = NULL;
  9539. if (cmdiocbq->iocb_cmpl)
  9540. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
  9541. else
  9542. lpfc_sli_release_iocbq(phba, cmdiocbq);
  9543. return;
  9544. }
  9545. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  9546. if (cmdiocbq->context2 && rspiocbq)
  9547. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  9548. &rspiocbq->iocb, sizeof(IOCB_t));
  9549. /* Set the exchange busy flag for task management commands */
  9550. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  9551. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  9552. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  9553. cur_iocbq);
  9554. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  9555. }
  9556. pdone_q = cmdiocbq->context_un.wait_queue;
  9557. if (pdone_q)
  9558. wake_up(pdone_q);
  9559. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9560. return;
  9561. }
  9562. /**
  9563. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  9564. * @phba: Pointer to HBA context object..
  9565. * @piocbq: Pointer to command iocb.
  9566. * @flag: Flag to test.
  9567. *
  9568. * This routine grabs the hbalock and then test the iocb_flag to
  9569. * see if the passed in flag is set.
  9570. * Returns:
  9571. * 1 if flag is set.
  9572. * 0 if flag is not set.
  9573. **/
  9574. static int
  9575. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  9576. struct lpfc_iocbq *piocbq, uint32_t flag)
  9577. {
  9578. unsigned long iflags;
  9579. int ret;
  9580. spin_lock_irqsave(&phba->hbalock, iflags);
  9581. ret = piocbq->iocb_flag & flag;
  9582. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9583. return ret;
  9584. }
  9585. /**
  9586. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  9587. * @phba: Pointer to HBA context object..
  9588. * @pring: Pointer to sli ring.
  9589. * @piocb: Pointer to command iocb.
  9590. * @prspiocbq: Pointer to response iocb.
  9591. * @timeout: Timeout in number of seconds.
  9592. *
  9593. * This function issues the iocb to firmware and waits for the
  9594. * iocb to complete. The iocb_cmpl field of the shall be used
  9595. * to handle iocbs which time out. If the field is NULL, the
  9596. * function shall free the iocbq structure. If more clean up is
  9597. * needed, the caller is expected to provide a completion function
  9598. * that will provide the needed clean up. If the iocb command is
  9599. * not completed within timeout seconds, the function will either
  9600. * free the iocbq structure (if iocb_cmpl == NULL) or execute the
  9601. * completion function set in the iocb_cmpl field and then return
  9602. * a status of IOCB_TIMEDOUT. The caller should not free the iocb
  9603. * resources if this function returns IOCB_TIMEDOUT.
  9604. * The function waits for the iocb completion using an
  9605. * non-interruptible wait.
  9606. * This function will sleep while waiting for iocb completion.
  9607. * So, this function should not be called from any context which
  9608. * does not allow sleeping. Due to the same reason, this function
  9609. * cannot be called with interrupt disabled.
  9610. * This function assumes that the iocb completions occur while
  9611. * this function sleep. So, this function cannot be called from
  9612. * the thread which process iocb completion for this ring.
  9613. * This function clears the iocb_flag of the iocb object before
  9614. * issuing the iocb and the iocb completion handler sets this
  9615. * flag and wakes this thread when the iocb completes.
  9616. * The contents of the response iocb will be copied to prspiocbq
  9617. * by the completion handler when the command completes.
  9618. * This function returns IOCB_SUCCESS when success.
  9619. * This function is called with no lock held.
  9620. **/
  9621. int
  9622. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  9623. uint32_t ring_number,
  9624. struct lpfc_iocbq *piocb,
  9625. struct lpfc_iocbq *prspiocbq,
  9626. uint32_t timeout)
  9627. {
  9628. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9629. long timeleft, timeout_req = 0;
  9630. int retval = IOCB_SUCCESS;
  9631. uint32_t creg_val;
  9632. struct lpfc_iocbq *iocb;
  9633. int txq_cnt = 0;
  9634. int txcmplq_cnt = 0;
  9635. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9636. unsigned long iflags;
  9637. bool iocb_completed = true;
  9638. /*
  9639. * If the caller has provided a response iocbq buffer, then context2
  9640. * is NULL or its an error.
  9641. */
  9642. if (prspiocbq) {
  9643. if (piocb->context2)
  9644. return IOCB_ERROR;
  9645. piocb->context2 = prspiocbq;
  9646. }
  9647. piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
  9648. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  9649. piocb->context_un.wait_queue = &done_q;
  9650. piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
  9651. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9652. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9653. return IOCB_ERROR;
  9654. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  9655. writel(creg_val, phba->HCregaddr);
  9656. readl(phba->HCregaddr); /* flush */
  9657. }
  9658. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  9659. SLI_IOCB_RET_IOCB);
  9660. if (retval == IOCB_SUCCESS) {
  9661. timeout_req = msecs_to_jiffies(timeout * 1000);
  9662. timeleft = wait_event_timeout(done_q,
  9663. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  9664. timeout_req);
  9665. spin_lock_irqsave(&phba->hbalock, iflags);
  9666. if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
  9667. /*
  9668. * IOCB timed out. Inform the wake iocb wait
  9669. * completion function and set local status
  9670. */
  9671. iocb_completed = false;
  9672. piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
  9673. }
  9674. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9675. if (iocb_completed) {
  9676. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9677. "0331 IOCB wake signaled\n");
  9678. /* Note: we are not indicating if the IOCB has a success
  9679. * status or not - that's for the caller to check.
  9680. * IOCB_SUCCESS means just that the command was sent and
  9681. * completed. Not that it completed successfully.
  9682. * */
  9683. } else if (timeleft == 0) {
  9684. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9685. "0338 IOCB wait timeout error - no "
  9686. "wake response Data x%x\n", timeout);
  9687. retval = IOCB_TIMEDOUT;
  9688. } else {
  9689. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9690. "0330 IOCB wake NOT set, "
  9691. "Data x%x x%lx\n",
  9692. timeout, (timeleft / jiffies));
  9693. retval = IOCB_TIMEDOUT;
  9694. }
  9695. } else if (retval == IOCB_BUSY) {
  9696. if (phba->cfg_log_verbose & LOG_SLI) {
  9697. list_for_each_entry(iocb, &pring->txq, list) {
  9698. txq_cnt++;
  9699. }
  9700. list_for_each_entry(iocb, &pring->txcmplq, list) {
  9701. txcmplq_cnt++;
  9702. }
  9703. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9704. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9705. phba->iocb_cnt, txq_cnt, txcmplq_cnt);
  9706. }
  9707. return retval;
  9708. } else {
  9709. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9710. "0332 IOCB wait issue failed, Data x%x\n",
  9711. retval);
  9712. retval = IOCB_ERROR;
  9713. }
  9714. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9715. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9716. return IOCB_ERROR;
  9717. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9718. writel(creg_val, phba->HCregaddr);
  9719. readl(phba->HCregaddr); /* flush */
  9720. }
  9721. if (prspiocbq)
  9722. piocb->context2 = NULL;
  9723. piocb->context_un.wait_queue = NULL;
  9724. piocb->iocb_cmpl = NULL;
  9725. return retval;
  9726. }
  9727. /**
  9728. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9729. * @phba: Pointer to HBA context object.
  9730. * @pmboxq: Pointer to driver mailbox object.
  9731. * @timeout: Timeout in number of seconds.
  9732. *
  9733. * This function issues the mailbox to firmware and waits for the
  9734. * mailbox command to complete. If the mailbox command is not
  9735. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9736. * The function waits for the mailbox completion using an
  9737. * interruptible wait. If the thread is woken up due to a
  9738. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9739. * should not free the mailbox resources, if this function returns
  9740. * MBX_TIMEOUT.
  9741. * This function will sleep while waiting for mailbox completion.
  9742. * So, this function should not be called from any context which
  9743. * does not allow sleeping. Due to the same reason, this function
  9744. * cannot be called with interrupt disabled.
  9745. * This function assumes that the mailbox completion occurs while
  9746. * this function sleep. So, this function cannot be called from
  9747. * the worker thread which processes mailbox completion.
  9748. * This function is called in the context of HBA management
  9749. * applications.
  9750. * This function returns MBX_SUCCESS when successful.
  9751. * This function is called with no lock held.
  9752. **/
  9753. int
  9754. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9755. uint32_t timeout)
  9756. {
  9757. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9758. MAILBOX_t *mb = NULL;
  9759. int retval;
  9760. unsigned long flag;
  9761. /* The caller might set context1 for extended buffer */
  9762. if (pmboxq->context1)
  9763. mb = (MAILBOX_t *)pmboxq->context1;
  9764. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9765. /* setup wake call as IOCB callback */
  9766. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9767. /* setup context field to pass wait_queue pointer to wake function */
  9768. pmboxq->context1 = &done_q;
  9769. /* now issue the command */
  9770. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9771. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9772. wait_event_interruptible_timeout(done_q,
  9773. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9774. msecs_to_jiffies(timeout * 1000));
  9775. spin_lock_irqsave(&phba->hbalock, flag);
  9776. /* restore the possible extended buffer for free resource */
  9777. pmboxq->context1 = (uint8_t *)mb;
  9778. /*
  9779. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9780. * else do not free the resources.
  9781. */
  9782. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9783. retval = MBX_SUCCESS;
  9784. } else {
  9785. retval = MBX_TIMEOUT;
  9786. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9787. }
  9788. spin_unlock_irqrestore(&phba->hbalock, flag);
  9789. } else {
  9790. /* restore the possible extended buffer for free resource */
  9791. pmboxq->context1 = (uint8_t *)mb;
  9792. }
  9793. return retval;
  9794. }
  9795. /**
  9796. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9797. * @phba: Pointer to HBA context.
  9798. *
  9799. * This function is called to shutdown the driver's mailbox sub-system.
  9800. * It first marks the mailbox sub-system is in a block state to prevent
  9801. * the asynchronous mailbox command from issued off the pending mailbox
  9802. * command queue. If the mailbox command sub-system shutdown is due to
  9803. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9804. * the mailbox sub-system flush routine to forcefully bring down the
  9805. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9806. * as with offline or HBA function reset), this routine will wait for the
  9807. * outstanding mailbox command to complete before invoking the mailbox
  9808. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9809. **/
  9810. void
  9811. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
  9812. {
  9813. struct lpfc_sli *psli = &phba->sli;
  9814. unsigned long timeout;
  9815. if (mbx_action == LPFC_MBX_NO_WAIT) {
  9816. /* delay 100ms for port state */
  9817. msleep(100);
  9818. lpfc_sli_mbox_sys_flush(phba);
  9819. return;
  9820. }
  9821. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9822. spin_lock_irq(&phba->hbalock);
  9823. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9824. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9825. /* Determine how long we might wait for the active mailbox
  9826. * command to be gracefully completed by firmware.
  9827. */
  9828. if (phba->sli.mbox_active)
  9829. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9830. phba->sli.mbox_active) *
  9831. 1000) + jiffies;
  9832. spin_unlock_irq(&phba->hbalock);
  9833. while (phba->sli.mbox_active) {
  9834. /* Check active mailbox complete status every 2ms */
  9835. msleep(2);
  9836. if (time_after(jiffies, timeout))
  9837. /* Timeout, let the mailbox flush routine to
  9838. * forcefully release active mailbox command
  9839. */
  9840. break;
  9841. }
  9842. } else
  9843. spin_unlock_irq(&phba->hbalock);
  9844. lpfc_sli_mbox_sys_flush(phba);
  9845. }
  9846. /**
  9847. * lpfc_sli_eratt_read - read sli-3 error attention events
  9848. * @phba: Pointer to HBA context.
  9849. *
  9850. * This function is called to read the SLI3 device error attention registers
  9851. * for possible error attention events. The caller must hold the hostlock
  9852. * with spin_lock_irq().
  9853. *
  9854. * This function returns 1 when there is Error Attention in the Host Attention
  9855. * Register and returns 0 otherwise.
  9856. **/
  9857. static int
  9858. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9859. {
  9860. uint32_t ha_copy;
  9861. /* Read chip Host Attention (HA) register */
  9862. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9863. goto unplug_err;
  9864. if (ha_copy & HA_ERATT) {
  9865. /* Read host status register to retrieve error event */
  9866. if (lpfc_sli_read_hs(phba))
  9867. goto unplug_err;
  9868. /* Check if there is a deferred error condition is active */
  9869. if ((HS_FFER1 & phba->work_hs) &&
  9870. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9871. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9872. phba->hba_flag |= DEFER_ERATT;
  9873. /* Clear all interrupt enable conditions */
  9874. writel(0, phba->HCregaddr);
  9875. readl(phba->HCregaddr);
  9876. }
  9877. /* Set the driver HA work bitmap */
  9878. phba->work_ha |= HA_ERATT;
  9879. /* Indicate polling handles this ERATT */
  9880. phba->hba_flag |= HBA_ERATT_HANDLED;
  9881. return 1;
  9882. }
  9883. return 0;
  9884. unplug_err:
  9885. /* Set the driver HS work bitmap */
  9886. phba->work_hs |= UNPLUG_ERR;
  9887. /* Set the driver HA work bitmap */
  9888. phba->work_ha |= HA_ERATT;
  9889. /* Indicate polling handles this ERATT */
  9890. phba->hba_flag |= HBA_ERATT_HANDLED;
  9891. return 1;
  9892. }
  9893. /**
  9894. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9895. * @phba: Pointer to HBA context.
  9896. *
  9897. * This function is called to read the SLI4 device error attention registers
  9898. * for possible error attention events. The caller must hold the hostlock
  9899. * with spin_lock_irq().
  9900. *
  9901. * This function returns 1 when there is Error Attention in the Host Attention
  9902. * Register and returns 0 otherwise.
  9903. **/
  9904. static int
  9905. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9906. {
  9907. uint32_t uerr_sta_hi, uerr_sta_lo;
  9908. uint32_t if_type, portsmphr;
  9909. struct lpfc_register portstat_reg;
  9910. /*
  9911. * For now, use the SLI4 device internal unrecoverable error
  9912. * registers for error attention. This can be changed later.
  9913. */
  9914. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9915. switch (if_type) {
  9916. case LPFC_SLI_INTF_IF_TYPE_0:
  9917. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9918. &uerr_sta_lo) ||
  9919. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9920. &uerr_sta_hi)) {
  9921. phba->work_hs |= UNPLUG_ERR;
  9922. phba->work_ha |= HA_ERATT;
  9923. phba->hba_flag |= HBA_ERATT_HANDLED;
  9924. return 1;
  9925. }
  9926. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9927. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9928. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9929. "1423 HBA Unrecoverable error: "
  9930. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9931. "ue_mask_lo_reg=0x%x, "
  9932. "ue_mask_hi_reg=0x%x\n",
  9933. uerr_sta_lo, uerr_sta_hi,
  9934. phba->sli4_hba.ue_mask_lo,
  9935. phba->sli4_hba.ue_mask_hi);
  9936. phba->work_status[0] = uerr_sta_lo;
  9937. phba->work_status[1] = uerr_sta_hi;
  9938. phba->work_ha |= HA_ERATT;
  9939. phba->hba_flag |= HBA_ERATT_HANDLED;
  9940. return 1;
  9941. }
  9942. break;
  9943. case LPFC_SLI_INTF_IF_TYPE_2:
  9944. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9945. &portstat_reg.word0) ||
  9946. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9947. &portsmphr)){
  9948. phba->work_hs |= UNPLUG_ERR;
  9949. phba->work_ha |= HA_ERATT;
  9950. phba->hba_flag |= HBA_ERATT_HANDLED;
  9951. return 1;
  9952. }
  9953. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9954. phba->work_status[0] =
  9955. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9956. phba->work_status[1] =
  9957. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9958. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9959. "2885 Port Status Event: "
  9960. "port status reg 0x%x, "
  9961. "port smphr reg 0x%x, "
  9962. "error 1=0x%x, error 2=0x%x\n",
  9963. portstat_reg.word0,
  9964. portsmphr,
  9965. phba->work_status[0],
  9966. phba->work_status[1]);
  9967. phba->work_ha |= HA_ERATT;
  9968. phba->hba_flag |= HBA_ERATT_HANDLED;
  9969. return 1;
  9970. }
  9971. break;
  9972. case LPFC_SLI_INTF_IF_TYPE_1:
  9973. default:
  9974. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9975. "2886 HBA Error Attention on unsupported "
  9976. "if type %d.", if_type);
  9977. return 1;
  9978. }
  9979. return 0;
  9980. }
  9981. /**
  9982. * lpfc_sli_check_eratt - check error attention events
  9983. * @phba: Pointer to HBA context.
  9984. *
  9985. * This function is called from timer soft interrupt context to check HBA's
  9986. * error attention register bit for error attention events.
  9987. *
  9988. * This function returns 1 when there is Error Attention in the Host Attention
  9989. * Register and returns 0 otherwise.
  9990. **/
  9991. int
  9992. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9993. {
  9994. uint32_t ha_copy;
  9995. /* If somebody is waiting to handle an eratt, don't process it
  9996. * here. The brdkill function will do this.
  9997. */
  9998. if (phba->link_flag & LS_IGNORE_ERATT)
  9999. return 0;
  10000. /* Check if interrupt handler handles this ERATT */
  10001. spin_lock_irq(&phba->hbalock);
  10002. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  10003. /* Interrupt handler has handled ERATT */
  10004. spin_unlock_irq(&phba->hbalock);
  10005. return 0;
  10006. }
  10007. /*
  10008. * If there is deferred error attention, do not check for error
  10009. * attention
  10010. */
  10011. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10012. spin_unlock_irq(&phba->hbalock);
  10013. return 0;
  10014. }
  10015. /* If PCI channel is offline, don't process it */
  10016. if (unlikely(pci_channel_offline(phba->pcidev))) {
  10017. spin_unlock_irq(&phba->hbalock);
  10018. return 0;
  10019. }
  10020. switch (phba->sli_rev) {
  10021. case LPFC_SLI_REV2:
  10022. case LPFC_SLI_REV3:
  10023. /* Read chip Host Attention (HA) register */
  10024. ha_copy = lpfc_sli_eratt_read(phba);
  10025. break;
  10026. case LPFC_SLI_REV4:
  10027. /* Read device Uncoverable Error (UERR) registers */
  10028. ha_copy = lpfc_sli4_eratt_read(phba);
  10029. break;
  10030. default:
  10031. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10032. "0299 Invalid SLI revision (%d)\n",
  10033. phba->sli_rev);
  10034. ha_copy = 0;
  10035. break;
  10036. }
  10037. spin_unlock_irq(&phba->hbalock);
  10038. return ha_copy;
  10039. }
  10040. /**
  10041. * lpfc_intr_state_check - Check device state for interrupt handling
  10042. * @phba: Pointer to HBA context.
  10043. *
  10044. * This inline routine checks whether a device or its PCI slot is in a state
  10045. * that the interrupt should be handled.
  10046. *
  10047. * This function returns 0 if the device or the PCI slot is in a state that
  10048. * interrupt should be handled, otherwise -EIO.
  10049. */
  10050. static inline int
  10051. lpfc_intr_state_check(struct lpfc_hba *phba)
  10052. {
  10053. /* If the pci channel is offline, ignore all the interrupts */
  10054. if (unlikely(pci_channel_offline(phba->pcidev)))
  10055. return -EIO;
  10056. /* Update device level interrupt statistics */
  10057. phba->sli.slistat.sli_intr++;
  10058. /* Ignore all interrupts during initialization. */
  10059. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  10060. return -EIO;
  10061. return 0;
  10062. }
  10063. /**
  10064. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  10065. * @irq: Interrupt number.
  10066. * @dev_id: The device context pointer.
  10067. *
  10068. * This function is directly called from the PCI layer as an interrupt
  10069. * service routine when device with SLI-3 interface spec is enabled with
  10070. * MSI-X multi-message interrupt mode and there are slow-path events in
  10071. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  10072. * interrupt mode, this function is called as part of the device-level
  10073. * interrupt handler. When the PCI slot is in error recovery or the HBA
  10074. * is undergoing initialization, the interrupt handler will not process
  10075. * the interrupt. The link attention and ELS ring attention events are
  10076. * handled by the worker thread. The interrupt handler signals the worker
  10077. * thread and returns for these events. This function is called without
  10078. * any lock held. It gets the hbalock to access and update SLI data
  10079. * structures.
  10080. *
  10081. * This function returns IRQ_HANDLED when interrupt is handled else it
  10082. * returns IRQ_NONE.
  10083. **/
  10084. irqreturn_t
  10085. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  10086. {
  10087. struct lpfc_hba *phba;
  10088. uint32_t ha_copy, hc_copy;
  10089. uint32_t work_ha_copy;
  10090. unsigned long status;
  10091. unsigned long iflag;
  10092. uint32_t control;
  10093. MAILBOX_t *mbox, *pmbox;
  10094. struct lpfc_vport *vport;
  10095. struct lpfc_nodelist *ndlp;
  10096. struct lpfc_dmabuf *mp;
  10097. LPFC_MBOXQ_t *pmb;
  10098. int rc;
  10099. /*
  10100. * Get the driver's phba structure from the dev_id and
  10101. * assume the HBA is not interrupting.
  10102. */
  10103. phba = (struct lpfc_hba *)dev_id;
  10104. if (unlikely(!phba))
  10105. return IRQ_NONE;
  10106. /*
  10107. * Stuff needs to be attented to when this function is invoked as an
  10108. * individual interrupt handler in MSI-X multi-message interrupt mode
  10109. */
  10110. if (phba->intr_type == MSIX) {
  10111. /* Check device state for handling interrupt */
  10112. if (lpfc_intr_state_check(phba))
  10113. return IRQ_NONE;
  10114. /* Need to read HA REG for slow-path events */
  10115. spin_lock_irqsave(&phba->hbalock, iflag);
  10116. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  10117. goto unplug_error;
  10118. /* If somebody is waiting to handle an eratt don't process it
  10119. * here. The brdkill function will do this.
  10120. */
  10121. if (phba->link_flag & LS_IGNORE_ERATT)
  10122. ha_copy &= ~HA_ERATT;
  10123. /* Check the need for handling ERATT in interrupt handler */
  10124. if (ha_copy & HA_ERATT) {
  10125. if (phba->hba_flag & HBA_ERATT_HANDLED)
  10126. /* ERATT polling has handled ERATT */
  10127. ha_copy &= ~HA_ERATT;
  10128. else
  10129. /* Indicate interrupt handler handles ERATT */
  10130. phba->hba_flag |= HBA_ERATT_HANDLED;
  10131. }
  10132. /*
  10133. * If there is deferred error attention, do not check for any
  10134. * interrupt.
  10135. */
  10136. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10137. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10138. return IRQ_NONE;
  10139. }
  10140. /* Clear up only attention source related to slow-path */
  10141. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  10142. goto unplug_error;
  10143. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  10144. HC_LAINT_ENA | HC_ERINT_ENA),
  10145. phba->HCregaddr);
  10146. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  10147. phba->HAregaddr);
  10148. writel(hc_copy, phba->HCregaddr);
  10149. readl(phba->HAregaddr); /* flush */
  10150. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10151. } else
  10152. ha_copy = phba->ha_copy;
  10153. work_ha_copy = ha_copy & phba->work_ha_mask;
  10154. if (work_ha_copy) {
  10155. if (work_ha_copy & HA_LATT) {
  10156. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  10157. /*
  10158. * Turn off Link Attention interrupts
  10159. * until CLEAR_LA done
  10160. */
  10161. spin_lock_irqsave(&phba->hbalock, iflag);
  10162. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  10163. if (lpfc_readl(phba->HCregaddr, &control))
  10164. goto unplug_error;
  10165. control &= ~HC_LAINT_ENA;
  10166. writel(control, phba->HCregaddr);
  10167. readl(phba->HCregaddr); /* flush */
  10168. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10169. }
  10170. else
  10171. work_ha_copy &= ~HA_LATT;
  10172. }
  10173. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  10174. /*
  10175. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  10176. * the only slow ring.
  10177. */
  10178. status = (work_ha_copy &
  10179. (HA_RXMASK << (4*LPFC_ELS_RING)));
  10180. status >>= (4*LPFC_ELS_RING);
  10181. if (status & HA_RXMASK) {
  10182. spin_lock_irqsave(&phba->hbalock, iflag);
  10183. if (lpfc_readl(phba->HCregaddr, &control))
  10184. goto unplug_error;
  10185. lpfc_debugfs_slow_ring_trc(phba,
  10186. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  10187. control, status,
  10188. (uint32_t)phba->sli.slistat.sli_intr);
  10189. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  10190. lpfc_debugfs_slow_ring_trc(phba,
  10191. "ISR Disable ring:"
  10192. "pwork:x%x hawork:x%x wait:x%x",
  10193. phba->work_ha, work_ha_copy,
  10194. (uint32_t)((unsigned long)
  10195. &phba->work_waitq));
  10196. control &=
  10197. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  10198. writel(control, phba->HCregaddr);
  10199. readl(phba->HCregaddr); /* flush */
  10200. }
  10201. else {
  10202. lpfc_debugfs_slow_ring_trc(phba,
  10203. "ISR slow ring: pwork:"
  10204. "x%x hawork:x%x wait:x%x",
  10205. phba->work_ha, work_ha_copy,
  10206. (uint32_t)((unsigned long)
  10207. &phba->work_waitq));
  10208. }
  10209. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10210. }
  10211. }
  10212. spin_lock_irqsave(&phba->hbalock, iflag);
  10213. if (work_ha_copy & HA_ERATT) {
  10214. if (lpfc_sli_read_hs(phba))
  10215. goto unplug_error;
  10216. /*
  10217. * Check if there is a deferred error condition
  10218. * is active
  10219. */
  10220. if ((HS_FFER1 & phba->work_hs) &&
  10221. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  10222. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  10223. phba->work_hs)) {
  10224. phba->hba_flag |= DEFER_ERATT;
  10225. /* Clear all interrupt enable conditions */
  10226. writel(0, phba->HCregaddr);
  10227. readl(phba->HCregaddr);
  10228. }
  10229. }
  10230. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  10231. pmb = phba->sli.mbox_active;
  10232. pmbox = &pmb->u.mb;
  10233. mbox = phba->mbox;
  10234. vport = pmb->vport;
  10235. /* First check out the status word */
  10236. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  10237. if (pmbox->mbxOwner != OWN_HOST) {
  10238. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10239. /*
  10240. * Stray Mailbox Interrupt, mbxCommand <cmd>
  10241. * mbxStatus <status>
  10242. */
  10243. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10244. LOG_SLI,
  10245. "(%d):0304 Stray Mailbox "
  10246. "Interrupt mbxCommand x%x "
  10247. "mbxStatus x%x\n",
  10248. (vport ? vport->vpi : 0),
  10249. pmbox->mbxCommand,
  10250. pmbox->mbxStatus);
  10251. /* clear mailbox attention bit */
  10252. work_ha_copy &= ~HA_MBATT;
  10253. } else {
  10254. phba->sli.mbox_active = NULL;
  10255. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10256. phba->last_completion_time = jiffies;
  10257. del_timer(&phba->sli.mbox_tmo);
  10258. if (pmb->mbox_cmpl) {
  10259. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  10260. MAILBOX_CMD_SIZE);
  10261. if (pmb->out_ext_byte_len &&
  10262. pmb->context2)
  10263. lpfc_sli_pcimem_bcopy(
  10264. phba->mbox_ext,
  10265. pmb->context2,
  10266. pmb->out_ext_byte_len);
  10267. }
  10268. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10269. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10270. lpfc_debugfs_disc_trc(vport,
  10271. LPFC_DISC_TRC_MBOX_VPORT,
  10272. "MBOX dflt rpi: : "
  10273. "status:x%x rpi:x%x",
  10274. (uint32_t)pmbox->mbxStatus,
  10275. pmbox->un.varWords[0], 0);
  10276. if (!pmbox->mbxStatus) {
  10277. mp = (struct lpfc_dmabuf *)
  10278. (pmb->context1);
  10279. ndlp = (struct lpfc_nodelist *)
  10280. pmb->context2;
  10281. /* Reg_LOGIN of dflt RPI was
  10282. * successful. new lets get
  10283. * rid of the RPI using the
  10284. * same mbox buffer.
  10285. */
  10286. lpfc_unreg_login(phba,
  10287. vport->vpi,
  10288. pmbox->un.varWords[0],
  10289. pmb);
  10290. pmb->mbox_cmpl =
  10291. lpfc_mbx_cmpl_dflt_rpi;
  10292. pmb->context1 = mp;
  10293. pmb->context2 = ndlp;
  10294. pmb->vport = vport;
  10295. rc = lpfc_sli_issue_mbox(phba,
  10296. pmb,
  10297. MBX_NOWAIT);
  10298. if (rc != MBX_BUSY)
  10299. lpfc_printf_log(phba,
  10300. KERN_ERR,
  10301. LOG_MBOX | LOG_SLI,
  10302. "0350 rc should have"
  10303. "been MBX_BUSY\n");
  10304. if (rc != MBX_NOT_FINISHED)
  10305. goto send_current_mbox;
  10306. }
  10307. }
  10308. spin_lock_irqsave(
  10309. &phba->pport->work_port_lock,
  10310. iflag);
  10311. phba->pport->work_port_events &=
  10312. ~WORKER_MBOX_TMO;
  10313. spin_unlock_irqrestore(
  10314. &phba->pport->work_port_lock,
  10315. iflag);
  10316. lpfc_mbox_cmpl_put(phba, pmb);
  10317. }
  10318. } else
  10319. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10320. if ((work_ha_copy & HA_MBATT) &&
  10321. (phba->sli.mbox_active == NULL)) {
  10322. send_current_mbox:
  10323. /* Process next mailbox command if there is one */
  10324. do {
  10325. rc = lpfc_sli_issue_mbox(phba, NULL,
  10326. MBX_NOWAIT);
  10327. } while (rc == MBX_NOT_FINISHED);
  10328. if (rc != MBX_SUCCESS)
  10329. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10330. LOG_SLI, "0349 rc should be "
  10331. "MBX_SUCCESS\n");
  10332. }
  10333. spin_lock_irqsave(&phba->hbalock, iflag);
  10334. phba->work_ha |= work_ha_copy;
  10335. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10336. lpfc_worker_wake_up(phba);
  10337. }
  10338. return IRQ_HANDLED;
  10339. unplug_error:
  10340. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10341. return IRQ_HANDLED;
  10342. } /* lpfc_sli_sp_intr_handler */
  10343. /**
  10344. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  10345. * @irq: Interrupt number.
  10346. * @dev_id: The device context pointer.
  10347. *
  10348. * This function is directly called from the PCI layer as an interrupt
  10349. * service routine when device with SLI-3 interface spec is enabled with
  10350. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10351. * ring event in the HBA. However, when the device is enabled with either
  10352. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10353. * device-level interrupt handler. When the PCI slot is in error recovery
  10354. * or the HBA is undergoing initialization, the interrupt handler will not
  10355. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10356. * the intrrupt context. This function is called without any lock held.
  10357. * It gets the hbalock to access and update SLI data structures.
  10358. *
  10359. * This function returns IRQ_HANDLED when interrupt is handled else it
  10360. * returns IRQ_NONE.
  10361. **/
  10362. irqreturn_t
  10363. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  10364. {
  10365. struct lpfc_hba *phba;
  10366. uint32_t ha_copy;
  10367. unsigned long status;
  10368. unsigned long iflag;
  10369. /* Get the driver's phba structure from the dev_id and
  10370. * assume the HBA is not interrupting.
  10371. */
  10372. phba = (struct lpfc_hba *) dev_id;
  10373. if (unlikely(!phba))
  10374. return IRQ_NONE;
  10375. /*
  10376. * Stuff needs to be attented to when this function is invoked as an
  10377. * individual interrupt handler in MSI-X multi-message interrupt mode
  10378. */
  10379. if (phba->intr_type == MSIX) {
  10380. /* Check device state for handling interrupt */
  10381. if (lpfc_intr_state_check(phba))
  10382. return IRQ_NONE;
  10383. /* Need to read HA REG for FCP ring and other ring events */
  10384. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  10385. return IRQ_HANDLED;
  10386. /* Clear up only attention source related to fast-path */
  10387. spin_lock_irqsave(&phba->hbalock, iflag);
  10388. /*
  10389. * If there is deferred error attention, do not check for
  10390. * any interrupt.
  10391. */
  10392. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10393. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10394. return IRQ_NONE;
  10395. }
  10396. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  10397. phba->HAregaddr);
  10398. readl(phba->HAregaddr); /* flush */
  10399. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10400. } else
  10401. ha_copy = phba->ha_copy;
  10402. /*
  10403. * Process all events on FCP ring. Take the optimized path for FCP IO.
  10404. */
  10405. ha_copy &= ~(phba->work_ha_mask);
  10406. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  10407. status >>= (4*LPFC_FCP_RING);
  10408. if (status & HA_RXMASK)
  10409. lpfc_sli_handle_fast_ring_event(phba,
  10410. &phba->sli.ring[LPFC_FCP_RING],
  10411. status);
  10412. if (phba->cfg_multi_ring_support == 2) {
  10413. /*
  10414. * Process all events on extra ring. Take the optimized path
  10415. * for extra ring IO.
  10416. */
  10417. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  10418. status >>= (4*LPFC_EXTRA_RING);
  10419. if (status & HA_RXMASK) {
  10420. lpfc_sli_handle_fast_ring_event(phba,
  10421. &phba->sli.ring[LPFC_EXTRA_RING],
  10422. status);
  10423. }
  10424. }
  10425. return IRQ_HANDLED;
  10426. } /* lpfc_sli_fp_intr_handler */
  10427. /**
  10428. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  10429. * @irq: Interrupt number.
  10430. * @dev_id: The device context pointer.
  10431. *
  10432. * This function is the HBA device-level interrupt handler to device with
  10433. * SLI-3 interface spec, called from the PCI layer when either MSI or
  10434. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  10435. * requires driver attention. This function invokes the slow-path interrupt
  10436. * attention handling function and fast-path interrupt attention handling
  10437. * function in turn to process the relevant HBA attention events. This
  10438. * function is called without any lock held. It gets the hbalock to access
  10439. * and update SLI data structures.
  10440. *
  10441. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10442. * returns IRQ_NONE.
  10443. **/
  10444. irqreturn_t
  10445. lpfc_sli_intr_handler(int irq, void *dev_id)
  10446. {
  10447. struct lpfc_hba *phba;
  10448. irqreturn_t sp_irq_rc, fp_irq_rc;
  10449. unsigned long status1, status2;
  10450. uint32_t hc_copy;
  10451. /*
  10452. * Get the driver's phba structure from the dev_id and
  10453. * assume the HBA is not interrupting.
  10454. */
  10455. phba = (struct lpfc_hba *) dev_id;
  10456. if (unlikely(!phba))
  10457. return IRQ_NONE;
  10458. /* Check device state for handling interrupt */
  10459. if (lpfc_intr_state_check(phba))
  10460. return IRQ_NONE;
  10461. spin_lock(&phba->hbalock);
  10462. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  10463. spin_unlock(&phba->hbalock);
  10464. return IRQ_HANDLED;
  10465. }
  10466. if (unlikely(!phba->ha_copy)) {
  10467. spin_unlock(&phba->hbalock);
  10468. return IRQ_NONE;
  10469. } else if (phba->ha_copy & HA_ERATT) {
  10470. if (phba->hba_flag & HBA_ERATT_HANDLED)
  10471. /* ERATT polling has handled ERATT */
  10472. phba->ha_copy &= ~HA_ERATT;
  10473. else
  10474. /* Indicate interrupt handler handles ERATT */
  10475. phba->hba_flag |= HBA_ERATT_HANDLED;
  10476. }
  10477. /*
  10478. * If there is deferred error attention, do not check for any interrupt.
  10479. */
  10480. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10481. spin_unlock(&phba->hbalock);
  10482. return IRQ_NONE;
  10483. }
  10484. /* Clear attention sources except link and error attentions */
  10485. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  10486. spin_unlock(&phba->hbalock);
  10487. return IRQ_HANDLED;
  10488. }
  10489. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  10490. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  10491. phba->HCregaddr);
  10492. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  10493. writel(hc_copy, phba->HCregaddr);
  10494. readl(phba->HAregaddr); /* flush */
  10495. spin_unlock(&phba->hbalock);
  10496. /*
  10497. * Invokes slow-path host attention interrupt handling as appropriate.
  10498. */
  10499. /* status of events with mailbox and link attention */
  10500. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  10501. /* status of events with ELS ring */
  10502. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  10503. status2 >>= (4*LPFC_ELS_RING);
  10504. if (status1 || (status2 & HA_RXMASK))
  10505. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  10506. else
  10507. sp_irq_rc = IRQ_NONE;
  10508. /*
  10509. * Invoke fast-path host attention interrupt handling as appropriate.
  10510. */
  10511. /* status of events with FCP ring */
  10512. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  10513. status1 >>= (4*LPFC_FCP_RING);
  10514. /* status of events with extra ring */
  10515. if (phba->cfg_multi_ring_support == 2) {
  10516. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  10517. status2 >>= (4*LPFC_EXTRA_RING);
  10518. } else
  10519. status2 = 0;
  10520. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  10521. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  10522. else
  10523. fp_irq_rc = IRQ_NONE;
  10524. /* Return device-level interrupt handling status */
  10525. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  10526. } /* lpfc_sli_intr_handler */
  10527. /**
  10528. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  10529. * @phba: pointer to lpfc hba data structure.
  10530. *
  10531. * This routine is invoked by the worker thread to process all the pending
  10532. * SLI4 FCP abort XRI events.
  10533. **/
  10534. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  10535. {
  10536. struct lpfc_cq_event *cq_event;
  10537. /* First, declare the fcp xri abort event has been handled */
  10538. spin_lock_irq(&phba->hbalock);
  10539. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  10540. spin_unlock_irq(&phba->hbalock);
  10541. /* Now, handle all the fcp xri abort events */
  10542. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  10543. /* Get the first event from the head of the event queue */
  10544. spin_lock_irq(&phba->hbalock);
  10545. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  10546. cq_event, struct lpfc_cq_event, list);
  10547. spin_unlock_irq(&phba->hbalock);
  10548. /* Notify aborted XRI for FCP work queue */
  10549. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10550. /* Free the event processed back to the free pool */
  10551. lpfc_sli4_cq_event_release(phba, cq_event);
  10552. }
  10553. }
  10554. /**
  10555. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  10556. * @phba: pointer to lpfc hba data structure.
  10557. *
  10558. * This routine is invoked by the worker thread to process all the pending
  10559. * SLI4 els abort xri events.
  10560. **/
  10561. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  10562. {
  10563. struct lpfc_cq_event *cq_event;
  10564. /* First, declare the els xri abort event has been handled */
  10565. spin_lock_irq(&phba->hbalock);
  10566. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  10567. spin_unlock_irq(&phba->hbalock);
  10568. /* Now, handle all the els xri abort events */
  10569. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  10570. /* Get the first event from the head of the event queue */
  10571. spin_lock_irq(&phba->hbalock);
  10572. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  10573. cq_event, struct lpfc_cq_event, list);
  10574. spin_unlock_irq(&phba->hbalock);
  10575. /* Notify aborted XRI for ELS work queue */
  10576. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10577. /* Free the event processed back to the free pool */
  10578. lpfc_sli4_cq_event_release(phba, cq_event);
  10579. }
  10580. }
  10581. /**
  10582. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  10583. * @phba: pointer to lpfc hba data structure
  10584. * @pIocbIn: pointer to the rspiocbq
  10585. * @pIocbOut: pointer to the cmdiocbq
  10586. * @wcqe: pointer to the complete wcqe
  10587. *
  10588. * This routine transfers the fields of a command iocbq to a response iocbq
  10589. * by copying all the IOCB fields from command iocbq and transferring the
  10590. * completion status information from the complete wcqe.
  10591. **/
  10592. static void
  10593. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  10594. struct lpfc_iocbq *pIocbIn,
  10595. struct lpfc_iocbq *pIocbOut,
  10596. struct lpfc_wcqe_complete *wcqe)
  10597. {
  10598. int numBdes, i;
  10599. unsigned long iflags;
  10600. uint32_t status, max_response;
  10601. struct lpfc_dmabuf *dmabuf;
  10602. struct ulp_bde64 *bpl, bde;
  10603. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  10604. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  10605. sizeof(struct lpfc_iocbq) - offset);
  10606. /* Map WCQE parameters into irspiocb parameters */
  10607. status = bf_get(lpfc_wcqe_c_status, wcqe);
  10608. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  10609. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  10610. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  10611. pIocbIn->iocb.un.fcpi.fcpi_parm =
  10612. pIocbOut->iocb.un.fcpi.fcpi_parm -
  10613. wcqe->total_data_placed;
  10614. else
  10615. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10616. else {
  10617. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10618. switch (pIocbOut->iocb.ulpCommand) {
  10619. case CMD_ELS_REQUEST64_CR:
  10620. dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
  10621. bpl = (struct ulp_bde64 *)dmabuf->virt;
  10622. bde.tus.w = le32_to_cpu(bpl[1].tus.w);
  10623. max_response = bde.tus.f.bdeSize;
  10624. break;
  10625. case CMD_GEN_REQUEST64_CR:
  10626. max_response = 0;
  10627. if (!pIocbOut->context3)
  10628. break;
  10629. numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
  10630. sizeof(struct ulp_bde64);
  10631. dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
  10632. bpl = (struct ulp_bde64 *)dmabuf->virt;
  10633. for (i = 0; i < numBdes; i++) {
  10634. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  10635. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  10636. max_response += bde.tus.f.bdeSize;
  10637. }
  10638. break;
  10639. default:
  10640. max_response = wcqe->total_data_placed;
  10641. break;
  10642. }
  10643. if (max_response < wcqe->total_data_placed)
  10644. pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
  10645. else
  10646. pIocbIn->iocb.un.genreq64.bdl.bdeSize =
  10647. wcqe->total_data_placed;
  10648. }
  10649. /* Convert BG errors for completion status */
  10650. if (status == CQE_STATUS_DI_ERROR) {
  10651. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  10652. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  10653. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  10654. else
  10655. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  10656. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  10657. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  10658. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10659. BGS_GUARD_ERR_MASK;
  10660. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  10661. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10662. BGS_APPTAG_ERR_MASK;
  10663. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  10664. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10665. BGS_REFTAG_ERR_MASK;
  10666. /* Check to see if there was any good data before the error */
  10667. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  10668. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10669. BGS_HI_WATER_MARK_PRESENT_MASK;
  10670. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  10671. wcqe->total_data_placed;
  10672. }
  10673. /*
  10674. * Set ALL the error bits to indicate we don't know what
  10675. * type of error it is.
  10676. */
  10677. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  10678. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10679. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  10680. BGS_GUARD_ERR_MASK);
  10681. }
  10682. /* Pick up HBA exchange busy condition */
  10683. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  10684. spin_lock_irqsave(&phba->hbalock, iflags);
  10685. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  10686. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10687. }
  10688. }
  10689. /**
  10690. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  10691. * @phba: Pointer to HBA context object.
  10692. * @wcqe: Pointer to work-queue completion queue entry.
  10693. *
  10694. * This routine handles an ELS work-queue completion event and construct
  10695. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  10696. * discovery engine to handle.
  10697. *
  10698. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  10699. **/
  10700. static struct lpfc_iocbq *
  10701. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  10702. struct lpfc_iocbq *irspiocbq)
  10703. {
  10704. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  10705. struct lpfc_iocbq *cmdiocbq;
  10706. struct lpfc_wcqe_complete *wcqe;
  10707. unsigned long iflags;
  10708. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  10709. spin_lock_irqsave(&pring->ring_lock, iflags);
  10710. pring->stats.iocb_event++;
  10711. /* Look up the ELS command IOCB and create pseudo response IOCB */
  10712. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10713. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10714. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10715. if (unlikely(!cmdiocbq)) {
  10716. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10717. "0386 ELS complete with no corresponding "
  10718. "cmdiocb: iotag (%d)\n",
  10719. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10720. lpfc_sli_release_iocbq(phba, irspiocbq);
  10721. return NULL;
  10722. }
  10723. /* Fake the irspiocbq and copy necessary response information */
  10724. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  10725. return irspiocbq;
  10726. }
  10727. /**
  10728. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  10729. * @phba: Pointer to HBA context object.
  10730. * @cqe: Pointer to mailbox completion queue entry.
  10731. *
  10732. * This routine process a mailbox completion queue entry with asynchrous
  10733. * event.
  10734. *
  10735. * Return: true if work posted to worker thread, otherwise false.
  10736. **/
  10737. static bool
  10738. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10739. {
  10740. struct lpfc_cq_event *cq_event;
  10741. unsigned long iflags;
  10742. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10743. "0392 Async Event: word0:x%x, word1:x%x, "
  10744. "word2:x%x, word3:x%x\n", mcqe->word0,
  10745. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10746. /* Allocate a new internal CQ_EVENT entry */
  10747. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10748. if (!cq_event) {
  10749. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10750. "0394 Failed to allocate CQ_EVENT entry\n");
  10751. return false;
  10752. }
  10753. /* Move the CQE into an asynchronous event entry */
  10754. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10755. spin_lock_irqsave(&phba->hbalock, iflags);
  10756. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10757. /* Set the async event flag */
  10758. phba->hba_flag |= ASYNC_EVENT;
  10759. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10760. return true;
  10761. }
  10762. /**
  10763. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10764. * @phba: Pointer to HBA context object.
  10765. * @cqe: Pointer to mailbox completion queue entry.
  10766. *
  10767. * This routine process a mailbox completion queue entry with mailbox
  10768. * completion event.
  10769. *
  10770. * Return: true if work posted to worker thread, otherwise false.
  10771. **/
  10772. static bool
  10773. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10774. {
  10775. uint32_t mcqe_status;
  10776. MAILBOX_t *mbox, *pmbox;
  10777. struct lpfc_mqe *mqe;
  10778. struct lpfc_vport *vport;
  10779. struct lpfc_nodelist *ndlp;
  10780. struct lpfc_dmabuf *mp;
  10781. unsigned long iflags;
  10782. LPFC_MBOXQ_t *pmb;
  10783. bool workposted = false;
  10784. int rc;
  10785. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10786. if (!bf_get(lpfc_trailer_completed, mcqe))
  10787. goto out_no_mqe_complete;
  10788. /* Get the reference to the active mbox command */
  10789. spin_lock_irqsave(&phba->hbalock, iflags);
  10790. pmb = phba->sli.mbox_active;
  10791. if (unlikely(!pmb)) {
  10792. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10793. "1832 No pending MBOX command to handle\n");
  10794. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10795. goto out_no_mqe_complete;
  10796. }
  10797. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10798. mqe = &pmb->u.mqe;
  10799. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10800. mbox = phba->mbox;
  10801. vport = pmb->vport;
  10802. /* Reset heartbeat timer */
  10803. phba->last_completion_time = jiffies;
  10804. del_timer(&phba->sli.mbox_tmo);
  10805. /* Move mbox data to caller's mailbox region, do endian swapping */
  10806. if (pmb->mbox_cmpl && mbox)
  10807. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10808. /*
  10809. * For mcqe errors, conditionally move a modified error code to
  10810. * the mbox so that the error will not be missed.
  10811. */
  10812. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10813. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10814. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10815. bf_set(lpfc_mqe_status, mqe,
  10816. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10817. }
  10818. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10819. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10820. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10821. "MBOX dflt rpi: status:x%x rpi:x%x",
  10822. mcqe_status,
  10823. pmbox->un.varWords[0], 0);
  10824. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10825. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10826. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10827. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10828. * RID of the PPI using the same mbox buffer.
  10829. */
  10830. lpfc_unreg_login(phba, vport->vpi,
  10831. pmbox->un.varWords[0], pmb);
  10832. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10833. pmb->context1 = mp;
  10834. pmb->context2 = ndlp;
  10835. pmb->vport = vport;
  10836. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10837. if (rc != MBX_BUSY)
  10838. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10839. LOG_SLI, "0385 rc should "
  10840. "have been MBX_BUSY\n");
  10841. if (rc != MBX_NOT_FINISHED)
  10842. goto send_current_mbox;
  10843. }
  10844. }
  10845. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10846. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10847. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10848. /* There is mailbox completion work to do */
  10849. spin_lock_irqsave(&phba->hbalock, iflags);
  10850. __lpfc_mbox_cmpl_put(phba, pmb);
  10851. phba->work_ha |= HA_MBATT;
  10852. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10853. workposted = true;
  10854. send_current_mbox:
  10855. spin_lock_irqsave(&phba->hbalock, iflags);
  10856. /* Release the mailbox command posting token */
  10857. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10858. /* Setting active mailbox pointer need to be in sync to flag clear */
  10859. phba->sli.mbox_active = NULL;
  10860. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10861. /* Wake up worker thread to post the next pending mailbox command */
  10862. lpfc_worker_wake_up(phba);
  10863. out_no_mqe_complete:
  10864. if (bf_get(lpfc_trailer_consumed, mcqe))
  10865. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10866. return workposted;
  10867. }
  10868. /**
  10869. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10870. * @phba: Pointer to HBA context object.
  10871. * @cqe: Pointer to mailbox completion queue entry.
  10872. *
  10873. * This routine process a mailbox completion queue entry, it invokes the
  10874. * proper mailbox complete handling or asynchrous event handling routine
  10875. * according to the MCQE's async bit.
  10876. *
  10877. * Return: true if work posted to worker thread, otherwise false.
  10878. **/
  10879. static bool
  10880. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10881. {
  10882. struct lpfc_mcqe mcqe;
  10883. bool workposted;
  10884. /* Copy the mailbox MCQE and convert endian order as needed */
  10885. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10886. /* Invoke the proper event handling routine */
  10887. if (!bf_get(lpfc_trailer_async, &mcqe))
  10888. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10889. else
  10890. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10891. return workposted;
  10892. }
  10893. /**
  10894. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10895. * @phba: Pointer to HBA context object.
  10896. * @cq: Pointer to associated CQ
  10897. * @wcqe: Pointer to work-queue completion queue entry.
  10898. *
  10899. * This routine handles an ELS work-queue completion event.
  10900. *
  10901. * Return: true if work posted to worker thread, otherwise false.
  10902. **/
  10903. static bool
  10904. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10905. struct lpfc_wcqe_complete *wcqe)
  10906. {
  10907. struct lpfc_iocbq *irspiocbq;
  10908. unsigned long iflags;
  10909. struct lpfc_sli_ring *pring = cq->pring;
  10910. int txq_cnt = 0;
  10911. int txcmplq_cnt = 0;
  10912. int fcp_txcmplq_cnt = 0;
  10913. /* Get an irspiocbq for later ELS response processing use */
  10914. irspiocbq = lpfc_sli_get_iocbq(phba);
  10915. if (!irspiocbq) {
  10916. if (!list_empty(&pring->txq))
  10917. txq_cnt++;
  10918. if (!list_empty(&pring->txcmplq))
  10919. txcmplq_cnt++;
  10920. if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
  10921. fcp_txcmplq_cnt++;
  10922. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10923. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10924. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10925. txq_cnt, phba->iocb_cnt,
  10926. fcp_txcmplq_cnt,
  10927. txcmplq_cnt);
  10928. return false;
  10929. }
  10930. /* Save off the slow-path queue event for work thread to process */
  10931. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10932. spin_lock_irqsave(&phba->hbalock, iflags);
  10933. list_add_tail(&irspiocbq->cq_event.list,
  10934. &phba->sli4_hba.sp_queue_event);
  10935. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10936. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10937. return true;
  10938. }
  10939. /**
  10940. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10941. * @phba: Pointer to HBA context object.
  10942. * @wcqe: Pointer to work-queue completion queue entry.
  10943. *
  10944. * This routine handles slow-path WQ entry comsumed event by invoking the
  10945. * proper WQ release routine to the slow-path WQ.
  10946. **/
  10947. static void
  10948. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10949. struct lpfc_wcqe_release *wcqe)
  10950. {
  10951. /* sanity check on queue memory */
  10952. if (unlikely(!phba->sli4_hba.els_wq))
  10953. return;
  10954. /* Check for the slow-path ELS work queue */
  10955. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10956. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10957. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10958. else
  10959. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10960. "2579 Slow-path wqe consume event carries "
  10961. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10962. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10963. phba->sli4_hba.els_wq->queue_id);
  10964. }
  10965. /**
  10966. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10967. * @phba: Pointer to HBA context object.
  10968. * @cq: Pointer to a WQ completion queue.
  10969. * @wcqe: Pointer to work-queue completion queue entry.
  10970. *
  10971. * This routine handles an XRI abort event.
  10972. *
  10973. * Return: true if work posted to worker thread, otherwise false.
  10974. **/
  10975. static bool
  10976. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10977. struct lpfc_queue *cq,
  10978. struct sli4_wcqe_xri_aborted *wcqe)
  10979. {
  10980. bool workposted = false;
  10981. struct lpfc_cq_event *cq_event;
  10982. unsigned long iflags;
  10983. /* Allocate a new internal CQ_EVENT entry */
  10984. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10985. if (!cq_event) {
  10986. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10987. "0602 Failed to allocate CQ_EVENT entry\n");
  10988. return false;
  10989. }
  10990. /* Move the CQE into the proper xri abort event list */
  10991. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10992. switch (cq->subtype) {
  10993. case LPFC_FCP:
  10994. spin_lock_irqsave(&phba->hbalock, iflags);
  10995. list_add_tail(&cq_event->list,
  10996. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10997. /* Set the fcp xri abort event flag */
  10998. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10999. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11000. workposted = true;
  11001. break;
  11002. case LPFC_ELS:
  11003. spin_lock_irqsave(&phba->hbalock, iflags);
  11004. list_add_tail(&cq_event->list,
  11005. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  11006. /* Set the els xri abort event flag */
  11007. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  11008. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11009. workposted = true;
  11010. break;
  11011. default:
  11012. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11013. "0603 Invalid work queue CQE subtype (x%x)\n",
  11014. cq->subtype);
  11015. workposted = false;
  11016. break;
  11017. }
  11018. return workposted;
  11019. }
  11020. /**
  11021. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  11022. * @phba: Pointer to HBA context object.
  11023. * @rcqe: Pointer to receive-queue completion queue entry.
  11024. *
  11025. * This routine process a receive-queue completion queue entry.
  11026. *
  11027. * Return: true if work posted to worker thread, otherwise false.
  11028. **/
  11029. static bool
  11030. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  11031. {
  11032. bool workposted = false;
  11033. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  11034. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  11035. struct hbq_dmabuf *dma_buf;
  11036. uint32_t status, rq_id;
  11037. unsigned long iflags;
  11038. /* sanity check on queue memory */
  11039. if (unlikely(!hrq) || unlikely(!drq))
  11040. return workposted;
  11041. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  11042. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  11043. else
  11044. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  11045. if (rq_id != hrq->queue_id)
  11046. goto out;
  11047. status = bf_get(lpfc_rcqe_status, rcqe);
  11048. switch (status) {
  11049. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  11050. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11051. "2537 Receive Frame Truncated!!\n");
  11052. hrq->RQ_buf_trunc++;
  11053. case FC_STATUS_RQ_SUCCESS:
  11054. lpfc_sli4_rq_release(hrq, drq);
  11055. spin_lock_irqsave(&phba->hbalock, iflags);
  11056. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  11057. if (!dma_buf) {
  11058. hrq->RQ_no_buf_found++;
  11059. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11060. goto out;
  11061. }
  11062. hrq->RQ_rcv_buf++;
  11063. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  11064. /* save off the frame for the word thread to process */
  11065. list_add_tail(&dma_buf->cq_event.list,
  11066. &phba->sli4_hba.sp_queue_event);
  11067. /* Frame received */
  11068. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  11069. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11070. workposted = true;
  11071. break;
  11072. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  11073. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  11074. hrq->RQ_no_posted_buf++;
  11075. /* Post more buffers if possible */
  11076. spin_lock_irqsave(&phba->hbalock, iflags);
  11077. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  11078. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11079. workposted = true;
  11080. break;
  11081. }
  11082. out:
  11083. return workposted;
  11084. }
  11085. /**
  11086. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  11087. * @phba: Pointer to HBA context object.
  11088. * @cq: Pointer to the completion queue.
  11089. * @wcqe: Pointer to a completion queue entry.
  11090. *
  11091. * This routine process a slow-path work-queue or receive queue completion queue
  11092. * entry.
  11093. *
  11094. * Return: true if work posted to worker thread, otherwise false.
  11095. **/
  11096. static bool
  11097. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11098. struct lpfc_cqe *cqe)
  11099. {
  11100. struct lpfc_cqe cqevt;
  11101. bool workposted = false;
  11102. /* Copy the work queue CQE and convert endian order if needed */
  11103. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  11104. /* Check and process for different type of WCQE and dispatch */
  11105. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  11106. case CQE_CODE_COMPL_WQE:
  11107. /* Process the WQ/RQ complete event */
  11108. phba->last_completion_time = jiffies;
  11109. workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
  11110. (struct lpfc_wcqe_complete *)&cqevt);
  11111. break;
  11112. case CQE_CODE_RELEASE_WQE:
  11113. /* Process the WQ release event */
  11114. lpfc_sli4_sp_handle_rel_wcqe(phba,
  11115. (struct lpfc_wcqe_release *)&cqevt);
  11116. break;
  11117. case CQE_CODE_XRI_ABORTED:
  11118. /* Process the WQ XRI abort event */
  11119. phba->last_completion_time = jiffies;
  11120. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  11121. (struct sli4_wcqe_xri_aborted *)&cqevt);
  11122. break;
  11123. case CQE_CODE_RECEIVE:
  11124. case CQE_CODE_RECEIVE_V1:
  11125. /* Process the RQ event */
  11126. phba->last_completion_time = jiffies;
  11127. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  11128. (struct lpfc_rcqe *)&cqevt);
  11129. break;
  11130. default:
  11131. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11132. "0388 Not a valid WCQE code: x%x\n",
  11133. bf_get(lpfc_cqe_code, &cqevt));
  11134. break;
  11135. }
  11136. return workposted;
  11137. }
  11138. /**
  11139. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  11140. * @phba: Pointer to HBA context object.
  11141. * @eqe: Pointer to fast-path event queue entry.
  11142. *
  11143. * This routine process a event queue entry from the slow-path event queue.
  11144. * It will check the MajorCode and MinorCode to determine this is for a
  11145. * completion event on a completion queue, if not, an error shall be logged
  11146. * and just return. Otherwise, it will get to the corresponding completion
  11147. * queue and process all the entries on that completion queue, rearm the
  11148. * completion queue, and then return.
  11149. *
  11150. **/
  11151. static void
  11152. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  11153. struct lpfc_queue *speq)
  11154. {
  11155. struct lpfc_queue *cq = NULL, *childq;
  11156. struct lpfc_cqe *cqe;
  11157. bool workposted = false;
  11158. int ecount = 0;
  11159. uint16_t cqid;
  11160. /* Get the reference to the corresponding CQ */
  11161. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11162. list_for_each_entry(childq, &speq->child_list, list) {
  11163. if (childq->queue_id == cqid) {
  11164. cq = childq;
  11165. break;
  11166. }
  11167. }
  11168. if (unlikely(!cq)) {
  11169. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11170. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11171. "0365 Slow-path CQ identifier "
  11172. "(%d) does not exist\n", cqid);
  11173. return;
  11174. }
  11175. /* Process all the entries to the CQ */
  11176. switch (cq->type) {
  11177. case LPFC_MCQ:
  11178. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11179. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  11180. if (!(++ecount % cq->entry_repost))
  11181. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11182. cq->CQ_mbox++;
  11183. }
  11184. break;
  11185. case LPFC_WCQ:
  11186. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11187. if (cq->subtype == LPFC_FCP)
  11188. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  11189. cqe);
  11190. else
  11191. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  11192. cqe);
  11193. if (!(++ecount % cq->entry_repost))
  11194. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11195. }
  11196. /* Track the max number of CQEs processed in 1 EQ */
  11197. if (ecount > cq->CQ_max_cqe)
  11198. cq->CQ_max_cqe = ecount;
  11199. break;
  11200. default:
  11201. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11202. "0370 Invalid completion queue type (%d)\n",
  11203. cq->type);
  11204. return;
  11205. }
  11206. /* Catch the no cq entry condition, log an error */
  11207. if (unlikely(ecount == 0))
  11208. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11209. "0371 No entry from the CQ: identifier "
  11210. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  11211. /* In any case, flash and re-arm the RCQ */
  11212. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11213. /* wake up worker thread if there are works to be done */
  11214. if (workposted)
  11215. lpfc_worker_wake_up(phba);
  11216. }
  11217. /**
  11218. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  11219. * @phba: Pointer to HBA context object.
  11220. * @cq: Pointer to associated CQ
  11221. * @wcqe: Pointer to work-queue completion queue entry.
  11222. *
  11223. * This routine process a fast-path work queue completion entry from fast-path
  11224. * event queue for FCP command response completion.
  11225. **/
  11226. static void
  11227. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11228. struct lpfc_wcqe_complete *wcqe)
  11229. {
  11230. struct lpfc_sli_ring *pring = cq->pring;
  11231. struct lpfc_iocbq *cmdiocbq;
  11232. struct lpfc_iocbq irspiocbq;
  11233. unsigned long iflags;
  11234. /* Check for response status */
  11235. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  11236. /* If resource errors reported from HBA, reduce queue
  11237. * depth of the SCSI device.
  11238. */
  11239. if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
  11240. IOSTAT_LOCAL_REJECT)) &&
  11241. ((wcqe->parameter & IOERR_PARAM_MASK) ==
  11242. IOERR_NO_RESOURCES))
  11243. phba->lpfc_rampdown_queue_depth(phba);
  11244. /* Log the error status */
  11245. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11246. "0373 FCP complete error: status=x%x, "
  11247. "hw_status=x%x, total_data_specified=%d, "
  11248. "parameter=x%x, word3=x%x\n",
  11249. bf_get(lpfc_wcqe_c_status, wcqe),
  11250. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  11251. wcqe->total_data_placed, wcqe->parameter,
  11252. wcqe->word3);
  11253. }
  11254. /* Look up the FCP command IOCB and create pseudo response IOCB */
  11255. spin_lock_irqsave(&pring->ring_lock, iflags);
  11256. pring->stats.iocb_event++;
  11257. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  11258. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11259. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  11260. if (unlikely(!cmdiocbq)) {
  11261. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11262. "0374 FCP complete with no corresponding "
  11263. "cmdiocb: iotag (%d)\n",
  11264. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11265. return;
  11266. }
  11267. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  11268. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11269. "0375 FCP cmdiocb not callback function "
  11270. "iotag: (%d)\n",
  11271. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11272. return;
  11273. }
  11274. /* Fake the irspiocb and copy necessary response information */
  11275. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  11276. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  11277. spin_lock_irqsave(&phba->hbalock, iflags);
  11278. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  11279. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11280. }
  11281. /* Pass the cmd_iocb and the rsp state to the upper layer */
  11282. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  11283. }
  11284. /**
  11285. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  11286. * @phba: Pointer to HBA context object.
  11287. * @cq: Pointer to completion queue.
  11288. * @wcqe: Pointer to work-queue completion queue entry.
  11289. *
  11290. * This routine handles an fast-path WQ entry comsumed event by invoking the
  11291. * proper WQ release routine to the slow-path WQ.
  11292. **/
  11293. static void
  11294. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11295. struct lpfc_wcqe_release *wcqe)
  11296. {
  11297. struct lpfc_queue *childwq;
  11298. bool wqid_matched = false;
  11299. uint16_t fcp_wqid;
  11300. /* Check for fast-path FCP work queue release */
  11301. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  11302. list_for_each_entry(childwq, &cq->child_list, list) {
  11303. if (childwq->queue_id == fcp_wqid) {
  11304. lpfc_sli4_wq_release(childwq,
  11305. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  11306. wqid_matched = true;
  11307. break;
  11308. }
  11309. }
  11310. /* Report warning log message if no match found */
  11311. if (wqid_matched != true)
  11312. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11313. "2580 Fast-path wqe consume event carries "
  11314. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  11315. }
  11316. /**
  11317. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  11318. * @cq: Pointer to the completion queue.
  11319. * @eqe: Pointer to fast-path completion queue entry.
  11320. *
  11321. * This routine process a fast-path work queue completion entry from fast-path
  11322. * event queue for FCP command response completion.
  11323. **/
  11324. static int
  11325. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11326. struct lpfc_cqe *cqe)
  11327. {
  11328. struct lpfc_wcqe_release wcqe;
  11329. bool workposted = false;
  11330. /* Copy the work queue CQE and convert endian order if needed */
  11331. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  11332. /* Check and process for different type of WCQE and dispatch */
  11333. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  11334. case CQE_CODE_COMPL_WQE:
  11335. cq->CQ_wq++;
  11336. /* Process the WQ complete event */
  11337. phba->last_completion_time = jiffies;
  11338. lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
  11339. (struct lpfc_wcqe_complete *)&wcqe);
  11340. break;
  11341. case CQE_CODE_RELEASE_WQE:
  11342. cq->CQ_release_wqe++;
  11343. /* Process the WQ release event */
  11344. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  11345. (struct lpfc_wcqe_release *)&wcqe);
  11346. break;
  11347. case CQE_CODE_XRI_ABORTED:
  11348. cq->CQ_xri_aborted++;
  11349. /* Process the WQ XRI abort event */
  11350. phba->last_completion_time = jiffies;
  11351. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  11352. (struct sli4_wcqe_xri_aborted *)&wcqe);
  11353. break;
  11354. default:
  11355. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11356. "0144 Not a valid WCQE code: x%x\n",
  11357. bf_get(lpfc_wcqe_c_code, &wcqe));
  11358. break;
  11359. }
  11360. return workposted;
  11361. }
  11362. /**
  11363. * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
  11364. * @phba: Pointer to HBA context object.
  11365. * @eqe: Pointer to fast-path event queue entry.
  11366. *
  11367. * This routine process a event queue entry from the fast-path event queue.
  11368. * It will check the MajorCode and MinorCode to determine this is for a
  11369. * completion event on a completion queue, if not, an error shall be logged
  11370. * and just return. Otherwise, it will get to the corresponding completion
  11371. * queue and process all the entries on the completion queue, rearm the
  11372. * completion queue, and then return.
  11373. **/
  11374. static void
  11375. lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  11376. uint32_t qidx)
  11377. {
  11378. struct lpfc_queue *cq;
  11379. struct lpfc_cqe *cqe;
  11380. bool workposted = false;
  11381. uint16_t cqid;
  11382. int ecount = 0;
  11383. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  11384. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11385. "0366 Not a valid completion "
  11386. "event: majorcode=x%x, minorcode=x%x\n",
  11387. bf_get_le32(lpfc_eqe_major_code, eqe),
  11388. bf_get_le32(lpfc_eqe_minor_code, eqe));
  11389. return;
  11390. }
  11391. /* Get the reference to the corresponding CQ */
  11392. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11393. /* Check if this is a Slow path event */
  11394. if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
  11395. lpfc_sli4_sp_handle_eqe(phba, eqe,
  11396. phba->sli4_hba.hba_eq[qidx]);
  11397. return;
  11398. }
  11399. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  11400. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11401. "3146 Fast-path completion queues "
  11402. "does not exist\n");
  11403. return;
  11404. }
  11405. cq = phba->sli4_hba.fcp_cq[qidx];
  11406. if (unlikely(!cq)) {
  11407. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11408. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11409. "0367 Fast-path completion queue "
  11410. "(%d) does not exist\n", qidx);
  11411. return;
  11412. }
  11413. if (unlikely(cqid != cq->queue_id)) {
  11414. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11415. "0368 Miss-matched fast-path completion "
  11416. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  11417. cqid, cq->queue_id);
  11418. return;
  11419. }
  11420. /* Process all the entries to the CQ */
  11421. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11422. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  11423. if (!(++ecount % cq->entry_repost))
  11424. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11425. }
  11426. /* Track the max number of CQEs processed in 1 EQ */
  11427. if (ecount > cq->CQ_max_cqe)
  11428. cq->CQ_max_cqe = ecount;
  11429. /* Catch the no cq entry condition */
  11430. if (unlikely(ecount == 0))
  11431. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11432. "0369 No entry from fast-path completion "
  11433. "queue fcpcqid=%d\n", cq->queue_id);
  11434. /* In any case, flash and re-arm the CQ */
  11435. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11436. /* wake up worker thread if there are works to be done */
  11437. if (workposted)
  11438. lpfc_worker_wake_up(phba);
  11439. }
  11440. static void
  11441. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11442. {
  11443. struct lpfc_eqe *eqe;
  11444. /* walk all the EQ entries and drop on the floor */
  11445. while ((eqe = lpfc_sli4_eq_get(eq)))
  11446. ;
  11447. /* Clear and re-arm the EQ */
  11448. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  11449. }
  11450. /**
  11451. * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
  11452. * entry
  11453. * @phba: Pointer to HBA context object.
  11454. * @eqe: Pointer to fast-path event queue entry.
  11455. *
  11456. * This routine process a event queue entry from the Flash Optimized Fabric
  11457. * event queue. It will check the MajorCode and MinorCode to determine this
  11458. * is for a completion event on a completion queue, if not, an error shall be
  11459. * logged and just return. Otherwise, it will get to the corresponding
  11460. * completion queue and process all the entries on the completion queue, rearm
  11461. * the completion queue, and then return.
  11462. **/
  11463. static void
  11464. lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  11465. {
  11466. struct lpfc_queue *cq;
  11467. struct lpfc_cqe *cqe;
  11468. bool workposted = false;
  11469. uint16_t cqid;
  11470. int ecount = 0;
  11471. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  11472. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11473. "9147 Not a valid completion "
  11474. "event: majorcode=x%x, minorcode=x%x\n",
  11475. bf_get_le32(lpfc_eqe_major_code, eqe),
  11476. bf_get_le32(lpfc_eqe_minor_code, eqe));
  11477. return;
  11478. }
  11479. /* Get the reference to the corresponding CQ */
  11480. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11481. /* Next check for OAS */
  11482. cq = phba->sli4_hba.oas_cq;
  11483. if (unlikely(!cq)) {
  11484. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11485. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11486. "9148 OAS completion queue "
  11487. "does not exist\n");
  11488. return;
  11489. }
  11490. if (unlikely(cqid != cq->queue_id)) {
  11491. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11492. "9149 Miss-matched fast-path compl "
  11493. "queue id: eqcqid=%d, fcpcqid=%d\n",
  11494. cqid, cq->queue_id);
  11495. return;
  11496. }
  11497. /* Process all the entries to the OAS CQ */
  11498. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11499. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  11500. if (!(++ecount % cq->entry_repost))
  11501. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11502. }
  11503. /* Track the max number of CQEs processed in 1 EQ */
  11504. if (ecount > cq->CQ_max_cqe)
  11505. cq->CQ_max_cqe = ecount;
  11506. /* Catch the no cq entry condition */
  11507. if (unlikely(ecount == 0))
  11508. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11509. "9153 No entry from fast-path completion "
  11510. "queue fcpcqid=%d\n", cq->queue_id);
  11511. /* In any case, flash and re-arm the CQ */
  11512. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11513. /* wake up worker thread if there are works to be done */
  11514. if (workposted)
  11515. lpfc_worker_wake_up(phba);
  11516. }
  11517. /**
  11518. * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
  11519. * @irq: Interrupt number.
  11520. * @dev_id: The device context pointer.
  11521. *
  11522. * This function is directly called from the PCI layer as an interrupt
  11523. * service routine when device with SLI-4 interface spec is enabled with
  11524. * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
  11525. * IOCB ring event in the HBA. However, when the device is enabled with either
  11526. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  11527. * device-level interrupt handler. When the PCI slot is in error recovery
  11528. * or the HBA is undergoing initialization, the interrupt handler will not
  11529. * process the interrupt. The Flash Optimized Fabric ring event are handled in
  11530. * the intrrupt context. This function is called without any lock held.
  11531. * It gets the hbalock to access and update SLI data structures. Note that,
  11532. * the EQ to CQ are one-to-one map such that the EQ index is
  11533. * equal to that of CQ index.
  11534. *
  11535. * This function returns IRQ_HANDLED when interrupt is handled else it
  11536. * returns IRQ_NONE.
  11537. **/
  11538. irqreturn_t
  11539. lpfc_sli4_fof_intr_handler(int irq, void *dev_id)
  11540. {
  11541. struct lpfc_hba *phba;
  11542. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  11543. struct lpfc_queue *eq;
  11544. struct lpfc_eqe *eqe;
  11545. unsigned long iflag;
  11546. int ecount = 0;
  11547. /* Get the driver's phba structure from the dev_id */
  11548. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  11549. phba = fcp_eq_hdl->phba;
  11550. if (unlikely(!phba))
  11551. return IRQ_NONE;
  11552. /* Get to the EQ struct associated with this vector */
  11553. eq = phba->sli4_hba.fof_eq;
  11554. if (unlikely(!eq))
  11555. return IRQ_NONE;
  11556. /* Check device state for handling interrupt */
  11557. if (unlikely(lpfc_intr_state_check(phba))) {
  11558. eq->EQ_badstate++;
  11559. /* Check again for link_state with lock held */
  11560. spin_lock_irqsave(&phba->hbalock, iflag);
  11561. if (phba->link_state < LPFC_LINK_DOWN)
  11562. /* Flush, clear interrupt, and rearm the EQ */
  11563. lpfc_sli4_eq_flush(phba, eq);
  11564. spin_unlock_irqrestore(&phba->hbalock, iflag);
  11565. return IRQ_NONE;
  11566. }
  11567. /*
  11568. * Process all the event on FCP fast-path EQ
  11569. */
  11570. while ((eqe = lpfc_sli4_eq_get(eq))) {
  11571. lpfc_sli4_fof_handle_eqe(phba, eqe);
  11572. if (!(++ecount % eq->entry_repost))
  11573. lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM);
  11574. eq->EQ_processed++;
  11575. }
  11576. /* Track the max number of EQEs processed in 1 intr */
  11577. if (ecount > eq->EQ_max_eqe)
  11578. eq->EQ_max_eqe = ecount;
  11579. if (unlikely(ecount == 0)) {
  11580. eq->EQ_no_entry++;
  11581. if (phba->intr_type == MSIX)
  11582. /* MSI-X treated interrupt served as no EQ share INT */
  11583. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11584. "9145 MSI-X interrupt with no EQE\n");
  11585. else {
  11586. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11587. "9146 ISR interrupt with no EQE\n");
  11588. /* Non MSI-X treated on interrupt as EQ share INT */
  11589. return IRQ_NONE;
  11590. }
  11591. }
  11592. /* Always clear and re-arm the fast-path EQ */
  11593. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  11594. return IRQ_HANDLED;
  11595. }
  11596. /**
  11597. * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
  11598. * @irq: Interrupt number.
  11599. * @dev_id: The device context pointer.
  11600. *
  11601. * This function is directly called from the PCI layer as an interrupt
  11602. * service routine when device with SLI-4 interface spec is enabled with
  11603. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  11604. * ring event in the HBA. However, when the device is enabled with either
  11605. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  11606. * device-level interrupt handler. When the PCI slot is in error recovery
  11607. * or the HBA is undergoing initialization, the interrupt handler will not
  11608. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  11609. * the intrrupt context. This function is called without any lock held.
  11610. * It gets the hbalock to access and update SLI data structures. Note that,
  11611. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  11612. * equal to that of FCP CQ index.
  11613. *
  11614. * The link attention and ELS ring attention events are handled
  11615. * by the worker thread. The interrupt handler signals the worker thread
  11616. * and returns for these events. This function is called without any lock
  11617. * held. It gets the hbalock to access and update SLI data structures.
  11618. *
  11619. * This function returns IRQ_HANDLED when interrupt is handled else it
  11620. * returns IRQ_NONE.
  11621. **/
  11622. irqreturn_t
  11623. lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
  11624. {
  11625. struct lpfc_hba *phba;
  11626. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  11627. struct lpfc_queue *fpeq;
  11628. struct lpfc_eqe *eqe;
  11629. unsigned long iflag;
  11630. int ecount = 0;
  11631. int fcp_eqidx;
  11632. /* Get the driver's phba structure from the dev_id */
  11633. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  11634. phba = fcp_eq_hdl->phba;
  11635. fcp_eqidx = fcp_eq_hdl->idx;
  11636. if (unlikely(!phba))
  11637. return IRQ_NONE;
  11638. if (unlikely(!phba->sli4_hba.hba_eq))
  11639. return IRQ_NONE;
  11640. /* Get to the EQ struct associated with this vector */
  11641. fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11642. if (unlikely(!fpeq))
  11643. return IRQ_NONE;
  11644. if (lpfc_fcp_look_ahead) {
  11645. if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
  11646. lpfc_sli4_eq_clr_intr(fpeq);
  11647. else {
  11648. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11649. return IRQ_NONE;
  11650. }
  11651. }
  11652. /* Check device state for handling interrupt */
  11653. if (unlikely(lpfc_intr_state_check(phba))) {
  11654. fpeq->EQ_badstate++;
  11655. /* Check again for link_state with lock held */
  11656. spin_lock_irqsave(&phba->hbalock, iflag);
  11657. if (phba->link_state < LPFC_LINK_DOWN)
  11658. /* Flush, clear interrupt, and rearm the EQ */
  11659. lpfc_sli4_eq_flush(phba, fpeq);
  11660. spin_unlock_irqrestore(&phba->hbalock, iflag);
  11661. if (lpfc_fcp_look_ahead)
  11662. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11663. return IRQ_NONE;
  11664. }
  11665. /*
  11666. * Process all the event on FCP fast-path EQ
  11667. */
  11668. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  11669. if (eqe == NULL)
  11670. break;
  11671. lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
  11672. if (!(++ecount % fpeq->entry_repost))
  11673. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  11674. fpeq->EQ_processed++;
  11675. }
  11676. /* Track the max number of EQEs processed in 1 intr */
  11677. if (ecount > fpeq->EQ_max_eqe)
  11678. fpeq->EQ_max_eqe = ecount;
  11679. /* Always clear and re-arm the fast-path EQ */
  11680. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  11681. if (unlikely(ecount == 0)) {
  11682. fpeq->EQ_no_entry++;
  11683. if (lpfc_fcp_look_ahead) {
  11684. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11685. return IRQ_NONE;
  11686. }
  11687. if (phba->intr_type == MSIX)
  11688. /* MSI-X treated interrupt served as no EQ share INT */
  11689. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11690. "0358 MSI-X interrupt with no EQE\n");
  11691. else
  11692. /* Non MSI-X treated on interrupt as EQ share INT */
  11693. return IRQ_NONE;
  11694. }
  11695. if (lpfc_fcp_look_ahead)
  11696. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11697. return IRQ_HANDLED;
  11698. } /* lpfc_sli4_fp_intr_handler */
  11699. /**
  11700. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  11701. * @irq: Interrupt number.
  11702. * @dev_id: The device context pointer.
  11703. *
  11704. * This function is the device-level interrupt handler to device with SLI-4
  11705. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  11706. * interrupt mode is enabled and there is an event in the HBA which requires
  11707. * driver attention. This function invokes the slow-path interrupt attention
  11708. * handling function and fast-path interrupt attention handling function in
  11709. * turn to process the relevant HBA attention events. This function is called
  11710. * without any lock held. It gets the hbalock to access and update SLI data
  11711. * structures.
  11712. *
  11713. * This function returns IRQ_HANDLED when interrupt is handled, else it
  11714. * returns IRQ_NONE.
  11715. **/
  11716. irqreturn_t
  11717. lpfc_sli4_intr_handler(int irq, void *dev_id)
  11718. {
  11719. struct lpfc_hba *phba;
  11720. irqreturn_t hba_irq_rc;
  11721. bool hba_handled = false;
  11722. int fcp_eqidx;
  11723. /* Get the driver's phba structure from the dev_id */
  11724. phba = (struct lpfc_hba *)dev_id;
  11725. if (unlikely(!phba))
  11726. return IRQ_NONE;
  11727. /*
  11728. * Invoke fast-path host attention interrupt handling as appropriate.
  11729. */
  11730. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  11731. hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
  11732. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  11733. if (hba_irq_rc == IRQ_HANDLED)
  11734. hba_handled |= true;
  11735. }
  11736. if (phba->cfg_fof) {
  11737. hba_irq_rc = lpfc_sli4_fof_intr_handler(irq,
  11738. &phba->sli4_hba.fcp_eq_hdl[0]);
  11739. if (hba_irq_rc == IRQ_HANDLED)
  11740. hba_handled |= true;
  11741. }
  11742. return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
  11743. } /* lpfc_sli4_intr_handler */
  11744. /**
  11745. * lpfc_sli4_queue_free - free a queue structure and associated memory
  11746. * @queue: The queue structure to free.
  11747. *
  11748. * This function frees a queue structure and the DMAable memory used for
  11749. * the host resident queue. This function must be called after destroying the
  11750. * queue on the HBA.
  11751. **/
  11752. void
  11753. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  11754. {
  11755. struct lpfc_dmabuf *dmabuf;
  11756. if (!queue)
  11757. return;
  11758. while (!list_empty(&queue->page_list)) {
  11759. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  11760. list);
  11761. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  11762. dmabuf->virt, dmabuf->phys);
  11763. kfree(dmabuf);
  11764. }
  11765. kfree(queue);
  11766. return;
  11767. }
  11768. /**
  11769. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  11770. * @phba: The HBA that this queue is being created on.
  11771. * @entry_size: The size of each queue entry for this queue.
  11772. * @entry count: The number of entries that this queue will handle.
  11773. *
  11774. * This function allocates a queue structure and the DMAable memory used for
  11775. * the host resident queue. This function must be called before creating the
  11776. * queue on the HBA.
  11777. **/
  11778. struct lpfc_queue *
  11779. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  11780. uint32_t entry_count)
  11781. {
  11782. struct lpfc_queue *queue;
  11783. struct lpfc_dmabuf *dmabuf;
  11784. int x, total_qe_count;
  11785. void *dma_pointer;
  11786. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11787. if (!phba->sli4_hba.pc_sli4_params.supported)
  11788. hw_page_size = SLI4_PAGE_SIZE;
  11789. queue = kzalloc(sizeof(struct lpfc_queue) +
  11790. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  11791. if (!queue)
  11792. return NULL;
  11793. queue->page_count = (ALIGN(entry_size * entry_count,
  11794. hw_page_size))/hw_page_size;
  11795. INIT_LIST_HEAD(&queue->list);
  11796. INIT_LIST_HEAD(&queue->page_list);
  11797. INIT_LIST_HEAD(&queue->child_list);
  11798. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  11799. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  11800. if (!dmabuf)
  11801. goto out_fail;
  11802. dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
  11803. hw_page_size, &dmabuf->phys,
  11804. GFP_KERNEL);
  11805. if (!dmabuf->virt) {
  11806. kfree(dmabuf);
  11807. goto out_fail;
  11808. }
  11809. dmabuf->buffer_tag = x;
  11810. list_add_tail(&dmabuf->list, &queue->page_list);
  11811. /* initialize queue's entry array */
  11812. dma_pointer = dmabuf->virt;
  11813. for (; total_qe_count < entry_count &&
  11814. dma_pointer < (hw_page_size + dmabuf->virt);
  11815. total_qe_count++, dma_pointer += entry_size) {
  11816. queue->qe[total_qe_count].address = dma_pointer;
  11817. }
  11818. }
  11819. queue->entry_size = entry_size;
  11820. queue->entry_count = entry_count;
  11821. /*
  11822. * entry_repost is calculated based on the number of entries in the
  11823. * queue. This works out except for RQs. If buffers are NOT initially
  11824. * posted for every RQE, entry_repost should be adjusted accordingly.
  11825. */
  11826. queue->entry_repost = (entry_count >> 3);
  11827. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  11828. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  11829. queue->phba = phba;
  11830. return queue;
  11831. out_fail:
  11832. lpfc_sli4_queue_free(queue);
  11833. return NULL;
  11834. }
  11835. /**
  11836. * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
  11837. * @phba: HBA structure that indicates port to create a queue on.
  11838. * @pci_barset: PCI BAR set flag.
  11839. *
  11840. * This function shall perform iomap of the specified PCI BAR address to host
  11841. * memory address if not already done so and return it. The returned host
  11842. * memory address can be NULL.
  11843. */
  11844. static void __iomem *
  11845. lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
  11846. {
  11847. if (!phba->pcidev)
  11848. return NULL;
  11849. switch (pci_barset) {
  11850. case WQ_PCI_BAR_0_AND_1:
  11851. return phba->pci_bar0_memmap_p;
  11852. case WQ_PCI_BAR_2_AND_3:
  11853. return phba->pci_bar2_memmap_p;
  11854. case WQ_PCI_BAR_4_AND_5:
  11855. return phba->pci_bar4_memmap_p;
  11856. default:
  11857. break;
  11858. }
  11859. return NULL;
  11860. }
  11861. /**
  11862. * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
  11863. * @phba: HBA structure that indicates port to create a queue on.
  11864. * @startq: The starting FCP EQ to modify
  11865. *
  11866. * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
  11867. *
  11868. * The @phba struct is used to send mailbox command to HBA. The @startq
  11869. * is used to get the starting FCP EQ to change.
  11870. * This function is asynchronous and will wait for the mailbox
  11871. * command to finish before continuing.
  11872. *
  11873. * On success this function will return a zero. If unable to allocate enough
  11874. * memory this function will return -ENOMEM. If the queue create mailbox command
  11875. * fails this function will return -ENXIO.
  11876. **/
  11877. int
  11878. lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint32_t startq)
  11879. {
  11880. struct lpfc_mbx_modify_eq_delay *eq_delay;
  11881. LPFC_MBOXQ_t *mbox;
  11882. struct lpfc_queue *eq;
  11883. int cnt, rc, length, status = 0;
  11884. uint32_t shdr_status, shdr_add_status;
  11885. uint32_t result;
  11886. int fcp_eqidx;
  11887. union lpfc_sli4_cfg_shdr *shdr;
  11888. uint16_t dmult;
  11889. if (startq >= phba->cfg_fcp_io_channel)
  11890. return 0;
  11891. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11892. if (!mbox)
  11893. return -ENOMEM;
  11894. length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
  11895. sizeof(struct lpfc_sli4_cfg_mhdr));
  11896. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11897. LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
  11898. length, LPFC_SLI4_MBX_EMBED);
  11899. eq_delay = &mbox->u.mqe.un.eq_delay;
  11900. /* Calculate delay multiper from maximum interrupt per second */
  11901. result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
  11902. if (result > LPFC_DMULT_CONST)
  11903. dmult = 0;
  11904. else
  11905. dmult = LPFC_DMULT_CONST/result - 1;
  11906. cnt = 0;
  11907. for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
  11908. fcp_eqidx++) {
  11909. eq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11910. if (!eq)
  11911. continue;
  11912. eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
  11913. eq_delay->u.request.eq[cnt].phase = 0;
  11914. eq_delay->u.request.eq[cnt].delay_multi = dmult;
  11915. cnt++;
  11916. if (cnt >= LPFC_MAX_EQ_DELAY)
  11917. break;
  11918. }
  11919. eq_delay->u.request.num_eq = cnt;
  11920. mbox->vport = phba->pport;
  11921. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11922. mbox->context1 = NULL;
  11923. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11924. shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
  11925. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11926. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11927. if (shdr_status || shdr_add_status || rc) {
  11928. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11929. "2512 MODIFY_EQ_DELAY mailbox failed with "
  11930. "status x%x add_status x%x, mbx status x%x\n",
  11931. shdr_status, shdr_add_status, rc);
  11932. status = -ENXIO;
  11933. }
  11934. mempool_free(mbox, phba->mbox_mem_pool);
  11935. return status;
  11936. }
  11937. /**
  11938. * lpfc_eq_create - Create an Event Queue on the HBA
  11939. * @phba: HBA structure that indicates port to create a queue on.
  11940. * @eq: The queue structure to use to create the event queue.
  11941. * @imax: The maximum interrupt per second limit.
  11942. *
  11943. * This function creates an event queue, as detailed in @eq, on a port,
  11944. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  11945. *
  11946. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  11947. * is used to get the entry count and entry size that are necessary to
  11948. * determine the number of pages to allocate and use for this queue. This
  11949. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  11950. * event queue. This function is asynchronous and will wait for the mailbox
  11951. * command to finish before continuing.
  11952. *
  11953. * On success this function will return a zero. If unable to allocate enough
  11954. * memory this function will return -ENOMEM. If the queue create mailbox command
  11955. * fails this function will return -ENXIO.
  11956. **/
  11957. int
  11958. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
  11959. {
  11960. struct lpfc_mbx_eq_create *eq_create;
  11961. LPFC_MBOXQ_t *mbox;
  11962. int rc, length, status = 0;
  11963. struct lpfc_dmabuf *dmabuf;
  11964. uint32_t shdr_status, shdr_add_status;
  11965. union lpfc_sli4_cfg_shdr *shdr;
  11966. uint16_t dmult;
  11967. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11968. /* sanity check on queue memory */
  11969. if (!eq)
  11970. return -ENODEV;
  11971. if (!phba->sli4_hba.pc_sli4_params.supported)
  11972. hw_page_size = SLI4_PAGE_SIZE;
  11973. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11974. if (!mbox)
  11975. return -ENOMEM;
  11976. length = (sizeof(struct lpfc_mbx_eq_create) -
  11977. sizeof(struct lpfc_sli4_cfg_mhdr));
  11978. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11979. LPFC_MBOX_OPCODE_EQ_CREATE,
  11980. length, LPFC_SLI4_MBX_EMBED);
  11981. eq_create = &mbox->u.mqe.un.eq_create;
  11982. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11983. eq->page_count);
  11984. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11985. LPFC_EQE_SIZE);
  11986. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11987. /* don't setup delay multiplier using EQ_CREATE */
  11988. dmult = 0;
  11989. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11990. dmult);
  11991. switch (eq->entry_count) {
  11992. default:
  11993. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11994. "0360 Unsupported EQ count. (%d)\n",
  11995. eq->entry_count);
  11996. if (eq->entry_count < 256)
  11997. return -EINVAL;
  11998. /* otherwise default to smallest count (drop through) */
  11999. case 256:
  12000. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12001. LPFC_EQ_CNT_256);
  12002. break;
  12003. case 512:
  12004. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12005. LPFC_EQ_CNT_512);
  12006. break;
  12007. case 1024:
  12008. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12009. LPFC_EQ_CNT_1024);
  12010. break;
  12011. case 2048:
  12012. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12013. LPFC_EQ_CNT_2048);
  12014. break;
  12015. case 4096:
  12016. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  12017. LPFC_EQ_CNT_4096);
  12018. break;
  12019. }
  12020. list_for_each_entry(dmabuf, &eq->page_list, list) {
  12021. memset(dmabuf->virt, 0, hw_page_size);
  12022. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12023. putPaddrLow(dmabuf->phys);
  12024. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12025. putPaddrHigh(dmabuf->phys);
  12026. }
  12027. mbox->vport = phba->pport;
  12028. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12029. mbox->context1 = NULL;
  12030. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12031. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  12032. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12033. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12034. if (shdr_status || shdr_add_status || rc) {
  12035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12036. "2500 EQ_CREATE mailbox failed with "
  12037. "status x%x add_status x%x, mbx status x%x\n",
  12038. shdr_status, shdr_add_status, rc);
  12039. status = -ENXIO;
  12040. }
  12041. eq->type = LPFC_EQ;
  12042. eq->subtype = LPFC_NONE;
  12043. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  12044. if (eq->queue_id == 0xFFFF)
  12045. status = -ENXIO;
  12046. eq->host_index = 0;
  12047. eq->hba_index = 0;
  12048. mempool_free(mbox, phba->mbox_mem_pool);
  12049. return status;
  12050. }
  12051. /**
  12052. * lpfc_cq_create - Create a Completion Queue on the HBA
  12053. * @phba: HBA structure that indicates port to create a queue on.
  12054. * @cq: The queue structure to use to create the completion queue.
  12055. * @eq: The event queue to bind this completion queue to.
  12056. *
  12057. * This function creates a completion queue, as detailed in @wq, on a port,
  12058. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  12059. *
  12060. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  12061. * is used to get the entry count and entry size that are necessary to
  12062. * determine the number of pages to allocate and use for this queue. The @eq
  12063. * is used to indicate which event queue to bind this completion queue to. This
  12064. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  12065. * completion queue. This function is asynchronous and will wait for the mailbox
  12066. * command to finish before continuing.
  12067. *
  12068. * On success this function will return a zero. If unable to allocate enough
  12069. * memory this function will return -ENOMEM. If the queue create mailbox command
  12070. * fails this function will return -ENXIO.
  12071. **/
  12072. int
  12073. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  12074. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  12075. {
  12076. struct lpfc_mbx_cq_create *cq_create;
  12077. struct lpfc_dmabuf *dmabuf;
  12078. LPFC_MBOXQ_t *mbox;
  12079. int rc, length, status = 0;
  12080. uint32_t shdr_status, shdr_add_status;
  12081. union lpfc_sli4_cfg_shdr *shdr;
  12082. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12083. /* sanity check on queue memory */
  12084. if (!cq || !eq)
  12085. return -ENODEV;
  12086. if (!phba->sli4_hba.pc_sli4_params.supported)
  12087. hw_page_size = SLI4_PAGE_SIZE;
  12088. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12089. if (!mbox)
  12090. return -ENOMEM;
  12091. length = (sizeof(struct lpfc_mbx_cq_create) -
  12092. sizeof(struct lpfc_sli4_cfg_mhdr));
  12093. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12094. LPFC_MBOX_OPCODE_CQ_CREATE,
  12095. length, LPFC_SLI4_MBX_EMBED);
  12096. cq_create = &mbox->u.mqe.un.cq_create;
  12097. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  12098. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  12099. cq->page_count);
  12100. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  12101. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  12102. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12103. phba->sli4_hba.pc_sli4_params.cqv);
  12104. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  12105. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  12106. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  12107. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  12108. eq->queue_id);
  12109. } else {
  12110. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  12111. eq->queue_id);
  12112. }
  12113. switch (cq->entry_count) {
  12114. default:
  12115. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12116. "0361 Unsupported CQ count. (%d)\n",
  12117. cq->entry_count);
  12118. if (cq->entry_count < 256) {
  12119. status = -EINVAL;
  12120. goto out;
  12121. }
  12122. /* otherwise default to smallest count (drop through) */
  12123. case 256:
  12124. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  12125. LPFC_CQ_CNT_256);
  12126. break;
  12127. case 512:
  12128. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  12129. LPFC_CQ_CNT_512);
  12130. break;
  12131. case 1024:
  12132. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  12133. LPFC_CQ_CNT_1024);
  12134. break;
  12135. }
  12136. list_for_each_entry(dmabuf, &cq->page_list, list) {
  12137. memset(dmabuf->virt, 0, hw_page_size);
  12138. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12139. putPaddrLow(dmabuf->phys);
  12140. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12141. putPaddrHigh(dmabuf->phys);
  12142. }
  12143. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12144. /* The IOCTL status is embedded in the mailbox subheader. */
  12145. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12146. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12147. if (shdr_status || shdr_add_status || rc) {
  12148. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12149. "2501 CQ_CREATE mailbox failed with "
  12150. "status x%x add_status x%x, mbx status x%x\n",
  12151. shdr_status, shdr_add_status, rc);
  12152. status = -ENXIO;
  12153. goto out;
  12154. }
  12155. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  12156. if (cq->queue_id == 0xFFFF) {
  12157. status = -ENXIO;
  12158. goto out;
  12159. }
  12160. /* link the cq onto the parent eq child list */
  12161. list_add_tail(&cq->list, &eq->child_list);
  12162. /* Set up completion queue's type and subtype */
  12163. cq->type = type;
  12164. cq->subtype = subtype;
  12165. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  12166. cq->assoc_qid = eq->queue_id;
  12167. cq->host_index = 0;
  12168. cq->hba_index = 0;
  12169. out:
  12170. mempool_free(mbox, phba->mbox_mem_pool);
  12171. return status;
  12172. }
  12173. /**
  12174. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  12175. * @phba: HBA structure that indicates port to create a queue on.
  12176. * @mq: The queue structure to use to create the mailbox queue.
  12177. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  12178. * @cq: The completion queue to associate with this cq.
  12179. *
  12180. * This function provides failback (fb) functionality when the
  12181. * mq_create_ext fails on older FW generations. It's purpose is identical
  12182. * to mq_create_ext otherwise.
  12183. *
  12184. * This routine cannot fail as all attributes were previously accessed and
  12185. * initialized in mq_create_ext.
  12186. **/
  12187. static void
  12188. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  12189. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  12190. {
  12191. struct lpfc_mbx_mq_create *mq_create;
  12192. struct lpfc_dmabuf *dmabuf;
  12193. int length;
  12194. length = (sizeof(struct lpfc_mbx_mq_create) -
  12195. sizeof(struct lpfc_sli4_cfg_mhdr));
  12196. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12197. LPFC_MBOX_OPCODE_MQ_CREATE,
  12198. length, LPFC_SLI4_MBX_EMBED);
  12199. mq_create = &mbox->u.mqe.un.mq_create;
  12200. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  12201. mq->page_count);
  12202. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  12203. cq->queue_id);
  12204. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  12205. switch (mq->entry_count) {
  12206. case 16:
  12207. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12208. LPFC_MQ_RING_SIZE_16);
  12209. break;
  12210. case 32:
  12211. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12212. LPFC_MQ_RING_SIZE_32);
  12213. break;
  12214. case 64:
  12215. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12216. LPFC_MQ_RING_SIZE_64);
  12217. break;
  12218. case 128:
  12219. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12220. LPFC_MQ_RING_SIZE_128);
  12221. break;
  12222. }
  12223. list_for_each_entry(dmabuf, &mq->page_list, list) {
  12224. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12225. putPaddrLow(dmabuf->phys);
  12226. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12227. putPaddrHigh(dmabuf->phys);
  12228. }
  12229. }
  12230. /**
  12231. * lpfc_mq_create - Create a mailbox Queue on the HBA
  12232. * @phba: HBA structure that indicates port to create a queue on.
  12233. * @mq: The queue structure to use to create the mailbox queue.
  12234. * @cq: The completion queue to associate with this cq.
  12235. * @subtype: The queue's subtype.
  12236. *
  12237. * This function creates a mailbox queue, as detailed in @mq, on a port,
  12238. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  12239. *
  12240. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  12241. * is used to get the entry count and entry size that are necessary to
  12242. * determine the number of pages to allocate and use for this queue. This
  12243. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  12244. * mailbox queue. This function is asynchronous and will wait for the mailbox
  12245. * command to finish before continuing.
  12246. *
  12247. * On success this function will return a zero. If unable to allocate enough
  12248. * memory this function will return -ENOMEM. If the queue create mailbox command
  12249. * fails this function will return -ENXIO.
  12250. **/
  12251. int32_t
  12252. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  12253. struct lpfc_queue *cq, uint32_t subtype)
  12254. {
  12255. struct lpfc_mbx_mq_create *mq_create;
  12256. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  12257. struct lpfc_dmabuf *dmabuf;
  12258. LPFC_MBOXQ_t *mbox;
  12259. int rc, length, status = 0;
  12260. uint32_t shdr_status, shdr_add_status;
  12261. union lpfc_sli4_cfg_shdr *shdr;
  12262. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12263. /* sanity check on queue memory */
  12264. if (!mq || !cq)
  12265. return -ENODEV;
  12266. if (!phba->sli4_hba.pc_sli4_params.supported)
  12267. hw_page_size = SLI4_PAGE_SIZE;
  12268. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12269. if (!mbox)
  12270. return -ENOMEM;
  12271. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  12272. sizeof(struct lpfc_sli4_cfg_mhdr));
  12273. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12274. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  12275. length, LPFC_SLI4_MBX_EMBED);
  12276. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  12277. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  12278. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  12279. &mq_create_ext->u.request, mq->page_count);
  12280. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  12281. &mq_create_ext->u.request, 1);
  12282. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  12283. &mq_create_ext->u.request, 1);
  12284. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  12285. &mq_create_ext->u.request, 1);
  12286. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  12287. &mq_create_ext->u.request, 1);
  12288. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  12289. &mq_create_ext->u.request, 1);
  12290. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  12291. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12292. phba->sli4_hba.pc_sli4_params.mqv);
  12293. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  12294. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  12295. cq->queue_id);
  12296. else
  12297. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  12298. cq->queue_id);
  12299. switch (mq->entry_count) {
  12300. default:
  12301. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12302. "0362 Unsupported MQ count. (%d)\n",
  12303. mq->entry_count);
  12304. if (mq->entry_count < 16) {
  12305. status = -EINVAL;
  12306. goto out;
  12307. }
  12308. /* otherwise default to smallest count (drop through) */
  12309. case 16:
  12310. bf_set(lpfc_mq_context_ring_size,
  12311. &mq_create_ext->u.request.context,
  12312. LPFC_MQ_RING_SIZE_16);
  12313. break;
  12314. case 32:
  12315. bf_set(lpfc_mq_context_ring_size,
  12316. &mq_create_ext->u.request.context,
  12317. LPFC_MQ_RING_SIZE_32);
  12318. break;
  12319. case 64:
  12320. bf_set(lpfc_mq_context_ring_size,
  12321. &mq_create_ext->u.request.context,
  12322. LPFC_MQ_RING_SIZE_64);
  12323. break;
  12324. case 128:
  12325. bf_set(lpfc_mq_context_ring_size,
  12326. &mq_create_ext->u.request.context,
  12327. LPFC_MQ_RING_SIZE_128);
  12328. break;
  12329. }
  12330. list_for_each_entry(dmabuf, &mq->page_list, list) {
  12331. memset(dmabuf->virt, 0, hw_page_size);
  12332. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  12333. putPaddrLow(dmabuf->phys);
  12334. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  12335. putPaddrHigh(dmabuf->phys);
  12336. }
  12337. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12338. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  12339. &mq_create_ext->u.response);
  12340. if (rc != MBX_SUCCESS) {
  12341. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12342. "2795 MQ_CREATE_EXT failed with "
  12343. "status x%x. Failback to MQ_CREATE.\n",
  12344. rc);
  12345. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  12346. mq_create = &mbox->u.mqe.un.mq_create;
  12347. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12348. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  12349. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  12350. &mq_create->u.response);
  12351. }
  12352. /* The IOCTL status is embedded in the mailbox subheader. */
  12353. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12354. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12355. if (shdr_status || shdr_add_status || rc) {
  12356. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12357. "2502 MQ_CREATE mailbox failed with "
  12358. "status x%x add_status x%x, mbx status x%x\n",
  12359. shdr_status, shdr_add_status, rc);
  12360. status = -ENXIO;
  12361. goto out;
  12362. }
  12363. if (mq->queue_id == 0xFFFF) {
  12364. status = -ENXIO;
  12365. goto out;
  12366. }
  12367. mq->type = LPFC_MQ;
  12368. mq->assoc_qid = cq->queue_id;
  12369. mq->subtype = subtype;
  12370. mq->host_index = 0;
  12371. mq->hba_index = 0;
  12372. /* link the mq onto the parent cq child list */
  12373. list_add_tail(&mq->list, &cq->child_list);
  12374. out:
  12375. mempool_free(mbox, phba->mbox_mem_pool);
  12376. return status;
  12377. }
  12378. /**
  12379. * lpfc_wq_create - Create a Work Queue on the HBA
  12380. * @phba: HBA structure that indicates port to create a queue on.
  12381. * @wq: The queue structure to use to create the work queue.
  12382. * @cq: The completion queue to bind this work queue to.
  12383. * @subtype: The subtype of the work queue indicating its functionality.
  12384. *
  12385. * This function creates a work queue, as detailed in @wq, on a port, described
  12386. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  12387. *
  12388. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  12389. * is used to get the entry count and entry size that are necessary to
  12390. * determine the number of pages to allocate and use for this queue. The @cq
  12391. * is used to indicate which completion queue to bind this work queue to. This
  12392. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  12393. * work queue. This function is asynchronous and will wait for the mailbox
  12394. * command to finish before continuing.
  12395. *
  12396. * On success this function will return a zero. If unable to allocate enough
  12397. * memory this function will return -ENOMEM. If the queue create mailbox command
  12398. * fails this function will return -ENXIO.
  12399. **/
  12400. int
  12401. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  12402. struct lpfc_queue *cq, uint32_t subtype)
  12403. {
  12404. struct lpfc_mbx_wq_create *wq_create;
  12405. struct lpfc_dmabuf *dmabuf;
  12406. LPFC_MBOXQ_t *mbox;
  12407. int rc, length, status = 0;
  12408. uint32_t shdr_status, shdr_add_status;
  12409. union lpfc_sli4_cfg_shdr *shdr;
  12410. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12411. struct dma_address *page;
  12412. void __iomem *bar_memmap_p;
  12413. uint32_t db_offset;
  12414. uint16_t pci_barset;
  12415. /* sanity check on queue memory */
  12416. if (!wq || !cq)
  12417. return -ENODEV;
  12418. if (!phba->sli4_hba.pc_sli4_params.supported)
  12419. hw_page_size = SLI4_PAGE_SIZE;
  12420. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12421. if (!mbox)
  12422. return -ENOMEM;
  12423. length = (sizeof(struct lpfc_mbx_wq_create) -
  12424. sizeof(struct lpfc_sli4_cfg_mhdr));
  12425. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12426. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  12427. length, LPFC_SLI4_MBX_EMBED);
  12428. wq_create = &mbox->u.mqe.un.wq_create;
  12429. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  12430. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  12431. wq->page_count);
  12432. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  12433. cq->queue_id);
  12434. /* wqv is the earliest version supported, NOT the latest */
  12435. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12436. phba->sli4_hba.pc_sli4_params.wqv);
  12437. switch (phba->sli4_hba.pc_sli4_params.wqv) {
  12438. case LPFC_Q_CREATE_VERSION_0:
  12439. switch (wq->entry_size) {
  12440. default:
  12441. case 64:
  12442. /* Nothing to do, version 0 ONLY supports 64 byte */
  12443. page = wq_create->u.request.page;
  12444. break;
  12445. case 128:
  12446. if (!(phba->sli4_hba.pc_sli4_params.wqsize &
  12447. LPFC_WQ_SZ128_SUPPORT)) {
  12448. status = -ERANGE;
  12449. goto out;
  12450. }
  12451. /* If we get here the HBA MUST also support V1 and
  12452. * we MUST use it
  12453. */
  12454. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12455. LPFC_Q_CREATE_VERSION_1);
  12456. bf_set(lpfc_mbx_wq_create_wqe_count,
  12457. &wq_create->u.request_1, wq->entry_count);
  12458. bf_set(lpfc_mbx_wq_create_wqe_size,
  12459. &wq_create->u.request_1,
  12460. LPFC_WQ_WQE_SIZE_128);
  12461. bf_set(lpfc_mbx_wq_create_page_size,
  12462. &wq_create->u.request_1,
  12463. LPFC_WQ_PAGE_SIZE_4096);
  12464. page = wq_create->u.request_1.page;
  12465. break;
  12466. }
  12467. break;
  12468. case LPFC_Q_CREATE_VERSION_1:
  12469. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  12470. wq->entry_count);
  12471. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12472. LPFC_Q_CREATE_VERSION_1);
  12473. switch (wq->entry_size) {
  12474. default:
  12475. case 64:
  12476. bf_set(lpfc_mbx_wq_create_wqe_size,
  12477. &wq_create->u.request_1,
  12478. LPFC_WQ_WQE_SIZE_64);
  12479. break;
  12480. case 128:
  12481. if (!(phba->sli4_hba.pc_sli4_params.wqsize &
  12482. LPFC_WQ_SZ128_SUPPORT)) {
  12483. status = -ERANGE;
  12484. goto out;
  12485. }
  12486. bf_set(lpfc_mbx_wq_create_wqe_size,
  12487. &wq_create->u.request_1,
  12488. LPFC_WQ_WQE_SIZE_128);
  12489. break;
  12490. }
  12491. bf_set(lpfc_mbx_wq_create_page_size,
  12492. &wq_create->u.request_1,
  12493. LPFC_WQ_PAGE_SIZE_4096);
  12494. page = wq_create->u.request_1.page;
  12495. break;
  12496. default:
  12497. status = -ERANGE;
  12498. goto out;
  12499. }
  12500. list_for_each_entry(dmabuf, &wq->page_list, list) {
  12501. memset(dmabuf->virt, 0, hw_page_size);
  12502. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  12503. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  12504. }
  12505. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12506. bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
  12507. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12508. /* The IOCTL status is embedded in the mailbox subheader. */
  12509. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12510. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12511. if (shdr_status || shdr_add_status || rc) {
  12512. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12513. "2503 WQ_CREATE mailbox failed with "
  12514. "status x%x add_status x%x, mbx status x%x\n",
  12515. shdr_status, shdr_add_status, rc);
  12516. status = -ENXIO;
  12517. goto out;
  12518. }
  12519. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  12520. if (wq->queue_id == 0xFFFF) {
  12521. status = -ENXIO;
  12522. goto out;
  12523. }
  12524. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  12525. wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
  12526. &wq_create->u.response);
  12527. if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
  12528. (wq->db_format != LPFC_DB_RING_FORMAT)) {
  12529. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12530. "3265 WQ[%d] doorbell format not "
  12531. "supported: x%x\n", wq->queue_id,
  12532. wq->db_format);
  12533. status = -EINVAL;
  12534. goto out;
  12535. }
  12536. pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
  12537. &wq_create->u.response);
  12538. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  12539. if (!bar_memmap_p) {
  12540. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12541. "3263 WQ[%d] failed to memmap pci "
  12542. "barset:x%x\n", wq->queue_id,
  12543. pci_barset);
  12544. status = -ENOMEM;
  12545. goto out;
  12546. }
  12547. db_offset = wq_create->u.response.doorbell_offset;
  12548. if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
  12549. (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
  12550. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12551. "3252 WQ[%d] doorbell offset not "
  12552. "supported: x%x\n", wq->queue_id,
  12553. db_offset);
  12554. status = -EINVAL;
  12555. goto out;
  12556. }
  12557. wq->db_regaddr = bar_memmap_p + db_offset;
  12558. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12559. "3264 WQ[%d]: barset:x%x, offset:x%x, "
  12560. "format:x%x\n", wq->queue_id, pci_barset,
  12561. db_offset, wq->db_format);
  12562. } else {
  12563. wq->db_format = LPFC_DB_LIST_FORMAT;
  12564. wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
  12565. }
  12566. wq->type = LPFC_WQ;
  12567. wq->assoc_qid = cq->queue_id;
  12568. wq->subtype = subtype;
  12569. wq->host_index = 0;
  12570. wq->hba_index = 0;
  12571. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  12572. /* link the wq onto the parent cq child list */
  12573. list_add_tail(&wq->list, &cq->child_list);
  12574. out:
  12575. mempool_free(mbox, phba->mbox_mem_pool);
  12576. return status;
  12577. }
  12578. /**
  12579. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  12580. * @phba: HBA structure that indicates port to create a queue on.
  12581. * @rq: The queue structure to use for the receive queue.
  12582. * @qno: The associated HBQ number
  12583. *
  12584. *
  12585. * For SLI4 we need to adjust the RQ repost value based on
  12586. * the number of buffers that are initially posted to the RQ.
  12587. */
  12588. void
  12589. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  12590. {
  12591. uint32_t cnt;
  12592. /* sanity check on queue memory */
  12593. if (!rq)
  12594. return;
  12595. cnt = lpfc_hbq_defs[qno]->entry_count;
  12596. /* Recalc repost for RQs based on buffers initially posted */
  12597. cnt = (cnt >> 3);
  12598. if (cnt < LPFC_QUEUE_MIN_REPOST)
  12599. cnt = LPFC_QUEUE_MIN_REPOST;
  12600. rq->entry_repost = cnt;
  12601. }
  12602. /**
  12603. * lpfc_rq_create - Create a Receive Queue on the HBA
  12604. * @phba: HBA structure that indicates port to create a queue on.
  12605. * @hrq: The queue structure to use to create the header receive queue.
  12606. * @drq: The queue structure to use to create the data receive queue.
  12607. * @cq: The completion queue to bind this work queue to.
  12608. *
  12609. * This function creates a receive buffer queue pair , as detailed in @hrq and
  12610. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  12611. * to the HBA.
  12612. *
  12613. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  12614. * struct is used to get the entry count that is necessary to determine the
  12615. * number of pages to use for this queue. The @cq is used to indicate which
  12616. * completion queue to bind received buffers that are posted to these queues to.
  12617. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  12618. * receive queue pair. This function is asynchronous and will wait for the
  12619. * mailbox command to finish before continuing.
  12620. *
  12621. * On success this function will return a zero. If unable to allocate enough
  12622. * memory this function will return -ENOMEM. If the queue create mailbox command
  12623. * fails this function will return -ENXIO.
  12624. **/
  12625. int
  12626. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  12627. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  12628. {
  12629. struct lpfc_mbx_rq_create *rq_create;
  12630. struct lpfc_dmabuf *dmabuf;
  12631. LPFC_MBOXQ_t *mbox;
  12632. int rc, length, status = 0;
  12633. uint32_t shdr_status, shdr_add_status;
  12634. union lpfc_sli4_cfg_shdr *shdr;
  12635. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12636. void __iomem *bar_memmap_p;
  12637. uint32_t db_offset;
  12638. uint16_t pci_barset;
  12639. /* sanity check on queue memory */
  12640. if (!hrq || !drq || !cq)
  12641. return -ENODEV;
  12642. if (!phba->sli4_hba.pc_sli4_params.supported)
  12643. hw_page_size = SLI4_PAGE_SIZE;
  12644. if (hrq->entry_count != drq->entry_count)
  12645. return -EINVAL;
  12646. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12647. if (!mbox)
  12648. return -ENOMEM;
  12649. length = (sizeof(struct lpfc_mbx_rq_create) -
  12650. sizeof(struct lpfc_sli4_cfg_mhdr));
  12651. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12652. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12653. length, LPFC_SLI4_MBX_EMBED);
  12654. rq_create = &mbox->u.mqe.un.rq_create;
  12655. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12656. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12657. phba->sli4_hba.pc_sli4_params.rqv);
  12658. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12659. bf_set(lpfc_rq_context_rqe_count_1,
  12660. &rq_create->u.request.context,
  12661. hrq->entry_count);
  12662. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  12663. bf_set(lpfc_rq_context_rqe_size,
  12664. &rq_create->u.request.context,
  12665. LPFC_RQE_SIZE_8);
  12666. bf_set(lpfc_rq_context_page_size,
  12667. &rq_create->u.request.context,
  12668. LPFC_RQ_PAGE_SIZE_4096);
  12669. } else {
  12670. switch (hrq->entry_count) {
  12671. default:
  12672. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12673. "2535 Unsupported RQ count. (%d)\n",
  12674. hrq->entry_count);
  12675. if (hrq->entry_count < 512) {
  12676. status = -EINVAL;
  12677. goto out;
  12678. }
  12679. /* otherwise default to smallest count (drop through) */
  12680. case 512:
  12681. bf_set(lpfc_rq_context_rqe_count,
  12682. &rq_create->u.request.context,
  12683. LPFC_RQ_RING_SIZE_512);
  12684. break;
  12685. case 1024:
  12686. bf_set(lpfc_rq_context_rqe_count,
  12687. &rq_create->u.request.context,
  12688. LPFC_RQ_RING_SIZE_1024);
  12689. break;
  12690. case 2048:
  12691. bf_set(lpfc_rq_context_rqe_count,
  12692. &rq_create->u.request.context,
  12693. LPFC_RQ_RING_SIZE_2048);
  12694. break;
  12695. case 4096:
  12696. bf_set(lpfc_rq_context_rqe_count,
  12697. &rq_create->u.request.context,
  12698. LPFC_RQ_RING_SIZE_4096);
  12699. break;
  12700. }
  12701. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12702. LPFC_HDR_BUF_SIZE);
  12703. }
  12704. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12705. cq->queue_id);
  12706. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12707. hrq->page_count);
  12708. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  12709. memset(dmabuf->virt, 0, hw_page_size);
  12710. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12711. putPaddrLow(dmabuf->phys);
  12712. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12713. putPaddrHigh(dmabuf->phys);
  12714. }
  12715. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12716. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12717. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12718. /* The IOCTL status is embedded in the mailbox subheader. */
  12719. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12720. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12721. if (shdr_status || shdr_add_status || rc) {
  12722. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12723. "2504 RQ_CREATE mailbox failed with "
  12724. "status x%x add_status x%x, mbx status x%x\n",
  12725. shdr_status, shdr_add_status, rc);
  12726. status = -ENXIO;
  12727. goto out;
  12728. }
  12729. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12730. if (hrq->queue_id == 0xFFFF) {
  12731. status = -ENXIO;
  12732. goto out;
  12733. }
  12734. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  12735. hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
  12736. &rq_create->u.response);
  12737. if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
  12738. (hrq->db_format != LPFC_DB_RING_FORMAT)) {
  12739. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12740. "3262 RQ [%d] doorbell format not "
  12741. "supported: x%x\n", hrq->queue_id,
  12742. hrq->db_format);
  12743. status = -EINVAL;
  12744. goto out;
  12745. }
  12746. pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
  12747. &rq_create->u.response);
  12748. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  12749. if (!bar_memmap_p) {
  12750. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12751. "3269 RQ[%d] failed to memmap pci "
  12752. "barset:x%x\n", hrq->queue_id,
  12753. pci_barset);
  12754. status = -ENOMEM;
  12755. goto out;
  12756. }
  12757. db_offset = rq_create->u.response.doorbell_offset;
  12758. if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
  12759. (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
  12760. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12761. "3270 RQ[%d] doorbell offset not "
  12762. "supported: x%x\n", hrq->queue_id,
  12763. db_offset);
  12764. status = -EINVAL;
  12765. goto out;
  12766. }
  12767. hrq->db_regaddr = bar_memmap_p + db_offset;
  12768. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12769. "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
  12770. "format:x%x\n", hrq->queue_id, pci_barset,
  12771. db_offset, hrq->db_format);
  12772. } else {
  12773. hrq->db_format = LPFC_DB_RING_FORMAT;
  12774. hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  12775. }
  12776. hrq->type = LPFC_HRQ;
  12777. hrq->assoc_qid = cq->queue_id;
  12778. hrq->subtype = subtype;
  12779. hrq->host_index = 0;
  12780. hrq->hba_index = 0;
  12781. /* now create the data queue */
  12782. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12783. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12784. length, LPFC_SLI4_MBX_EMBED);
  12785. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12786. phba->sli4_hba.pc_sli4_params.rqv);
  12787. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12788. bf_set(lpfc_rq_context_rqe_count_1,
  12789. &rq_create->u.request.context, hrq->entry_count);
  12790. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  12791. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  12792. LPFC_RQE_SIZE_8);
  12793. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  12794. (PAGE_SIZE/SLI4_PAGE_SIZE));
  12795. } else {
  12796. switch (drq->entry_count) {
  12797. default:
  12798. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12799. "2536 Unsupported RQ count. (%d)\n",
  12800. drq->entry_count);
  12801. if (drq->entry_count < 512) {
  12802. status = -EINVAL;
  12803. goto out;
  12804. }
  12805. /* otherwise default to smallest count (drop through) */
  12806. case 512:
  12807. bf_set(lpfc_rq_context_rqe_count,
  12808. &rq_create->u.request.context,
  12809. LPFC_RQ_RING_SIZE_512);
  12810. break;
  12811. case 1024:
  12812. bf_set(lpfc_rq_context_rqe_count,
  12813. &rq_create->u.request.context,
  12814. LPFC_RQ_RING_SIZE_1024);
  12815. break;
  12816. case 2048:
  12817. bf_set(lpfc_rq_context_rqe_count,
  12818. &rq_create->u.request.context,
  12819. LPFC_RQ_RING_SIZE_2048);
  12820. break;
  12821. case 4096:
  12822. bf_set(lpfc_rq_context_rqe_count,
  12823. &rq_create->u.request.context,
  12824. LPFC_RQ_RING_SIZE_4096);
  12825. break;
  12826. }
  12827. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12828. LPFC_DATA_BUF_SIZE);
  12829. }
  12830. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12831. cq->queue_id);
  12832. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12833. drq->page_count);
  12834. list_for_each_entry(dmabuf, &drq->page_list, list) {
  12835. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12836. putPaddrLow(dmabuf->phys);
  12837. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12838. putPaddrHigh(dmabuf->phys);
  12839. }
  12840. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12841. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12842. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12843. /* The IOCTL status is embedded in the mailbox subheader. */
  12844. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12845. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12846. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12847. if (shdr_status || shdr_add_status || rc) {
  12848. status = -ENXIO;
  12849. goto out;
  12850. }
  12851. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12852. if (drq->queue_id == 0xFFFF) {
  12853. status = -ENXIO;
  12854. goto out;
  12855. }
  12856. drq->type = LPFC_DRQ;
  12857. drq->assoc_qid = cq->queue_id;
  12858. drq->subtype = subtype;
  12859. drq->host_index = 0;
  12860. drq->hba_index = 0;
  12861. /* link the header and data RQs onto the parent cq child list */
  12862. list_add_tail(&hrq->list, &cq->child_list);
  12863. list_add_tail(&drq->list, &cq->child_list);
  12864. out:
  12865. mempool_free(mbox, phba->mbox_mem_pool);
  12866. return status;
  12867. }
  12868. /**
  12869. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  12870. * @eq: The queue structure associated with the queue to destroy.
  12871. *
  12872. * This function destroys a queue, as detailed in @eq by sending an mailbox
  12873. * command, specific to the type of queue, to the HBA.
  12874. *
  12875. * The @eq struct is used to get the queue ID of the queue to destroy.
  12876. *
  12877. * On success this function will return a zero. If the queue destroy mailbox
  12878. * command fails this function will return -ENXIO.
  12879. **/
  12880. int
  12881. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  12882. {
  12883. LPFC_MBOXQ_t *mbox;
  12884. int rc, length, status = 0;
  12885. uint32_t shdr_status, shdr_add_status;
  12886. union lpfc_sli4_cfg_shdr *shdr;
  12887. /* sanity check on queue memory */
  12888. if (!eq)
  12889. return -ENODEV;
  12890. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  12891. if (!mbox)
  12892. return -ENOMEM;
  12893. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  12894. sizeof(struct lpfc_sli4_cfg_mhdr));
  12895. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12896. LPFC_MBOX_OPCODE_EQ_DESTROY,
  12897. length, LPFC_SLI4_MBX_EMBED);
  12898. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  12899. eq->queue_id);
  12900. mbox->vport = eq->phba->pport;
  12901. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12902. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  12903. /* The IOCTL status is embedded in the mailbox subheader. */
  12904. shdr = (union lpfc_sli4_cfg_shdr *)
  12905. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  12906. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12907. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12908. if (shdr_status || shdr_add_status || rc) {
  12909. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12910. "2505 EQ_DESTROY mailbox failed with "
  12911. "status x%x add_status x%x, mbx status x%x\n",
  12912. shdr_status, shdr_add_status, rc);
  12913. status = -ENXIO;
  12914. }
  12915. /* Remove eq from any list */
  12916. list_del_init(&eq->list);
  12917. mempool_free(mbox, eq->phba->mbox_mem_pool);
  12918. return status;
  12919. }
  12920. /**
  12921. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  12922. * @cq: The queue structure associated with the queue to destroy.
  12923. *
  12924. * This function destroys a queue, as detailed in @cq by sending an mailbox
  12925. * command, specific to the type of queue, to the HBA.
  12926. *
  12927. * The @cq struct is used to get the queue ID of the queue to destroy.
  12928. *
  12929. * On success this function will return a zero. If the queue destroy mailbox
  12930. * command fails this function will return -ENXIO.
  12931. **/
  12932. int
  12933. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  12934. {
  12935. LPFC_MBOXQ_t *mbox;
  12936. int rc, length, status = 0;
  12937. uint32_t shdr_status, shdr_add_status;
  12938. union lpfc_sli4_cfg_shdr *shdr;
  12939. /* sanity check on queue memory */
  12940. if (!cq)
  12941. return -ENODEV;
  12942. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  12943. if (!mbox)
  12944. return -ENOMEM;
  12945. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  12946. sizeof(struct lpfc_sli4_cfg_mhdr));
  12947. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12948. LPFC_MBOX_OPCODE_CQ_DESTROY,
  12949. length, LPFC_SLI4_MBX_EMBED);
  12950. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  12951. cq->queue_id);
  12952. mbox->vport = cq->phba->pport;
  12953. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12954. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  12955. /* The IOCTL status is embedded in the mailbox subheader. */
  12956. shdr = (union lpfc_sli4_cfg_shdr *)
  12957. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  12958. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12959. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12960. if (shdr_status || shdr_add_status || rc) {
  12961. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12962. "2506 CQ_DESTROY mailbox failed with "
  12963. "status x%x add_status x%x, mbx status x%x\n",
  12964. shdr_status, shdr_add_status, rc);
  12965. status = -ENXIO;
  12966. }
  12967. /* Remove cq from any list */
  12968. list_del_init(&cq->list);
  12969. mempool_free(mbox, cq->phba->mbox_mem_pool);
  12970. return status;
  12971. }
  12972. /**
  12973. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  12974. * @qm: The queue structure associated with the queue to destroy.
  12975. *
  12976. * This function destroys a queue, as detailed in @mq by sending an mailbox
  12977. * command, specific to the type of queue, to the HBA.
  12978. *
  12979. * The @mq struct is used to get the queue ID of the queue to destroy.
  12980. *
  12981. * On success this function will return a zero. If the queue destroy mailbox
  12982. * command fails this function will return -ENXIO.
  12983. **/
  12984. int
  12985. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  12986. {
  12987. LPFC_MBOXQ_t *mbox;
  12988. int rc, length, status = 0;
  12989. uint32_t shdr_status, shdr_add_status;
  12990. union lpfc_sli4_cfg_shdr *shdr;
  12991. /* sanity check on queue memory */
  12992. if (!mq)
  12993. return -ENODEV;
  12994. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  12995. if (!mbox)
  12996. return -ENOMEM;
  12997. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  12998. sizeof(struct lpfc_sli4_cfg_mhdr));
  12999. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  13000. LPFC_MBOX_OPCODE_MQ_DESTROY,
  13001. length, LPFC_SLI4_MBX_EMBED);
  13002. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  13003. mq->queue_id);
  13004. mbox->vport = mq->phba->pport;
  13005. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13006. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  13007. /* The IOCTL status is embedded in the mailbox subheader. */
  13008. shdr = (union lpfc_sli4_cfg_shdr *)
  13009. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  13010. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13011. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13012. if (shdr_status || shdr_add_status || rc) {
  13013. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13014. "2507 MQ_DESTROY mailbox failed with "
  13015. "status x%x add_status x%x, mbx status x%x\n",
  13016. shdr_status, shdr_add_status, rc);
  13017. status = -ENXIO;
  13018. }
  13019. /* Remove mq from any list */
  13020. list_del_init(&mq->list);
  13021. mempool_free(mbox, mq->phba->mbox_mem_pool);
  13022. return status;
  13023. }
  13024. /**
  13025. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  13026. * @wq: The queue structure associated with the queue to destroy.
  13027. *
  13028. * This function destroys a queue, as detailed in @wq by sending an mailbox
  13029. * command, specific to the type of queue, to the HBA.
  13030. *
  13031. * The @wq struct is used to get the queue ID of the queue to destroy.
  13032. *
  13033. * On success this function will return a zero. If the queue destroy mailbox
  13034. * command fails this function will return -ENXIO.
  13035. **/
  13036. int
  13037. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  13038. {
  13039. LPFC_MBOXQ_t *mbox;
  13040. int rc, length, status = 0;
  13041. uint32_t shdr_status, shdr_add_status;
  13042. union lpfc_sli4_cfg_shdr *shdr;
  13043. /* sanity check on queue memory */
  13044. if (!wq)
  13045. return -ENODEV;
  13046. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  13047. if (!mbox)
  13048. return -ENOMEM;
  13049. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  13050. sizeof(struct lpfc_sli4_cfg_mhdr));
  13051. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13052. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  13053. length, LPFC_SLI4_MBX_EMBED);
  13054. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  13055. wq->queue_id);
  13056. mbox->vport = wq->phba->pport;
  13057. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13058. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  13059. shdr = (union lpfc_sli4_cfg_shdr *)
  13060. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  13061. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13062. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13063. if (shdr_status || shdr_add_status || rc) {
  13064. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13065. "2508 WQ_DESTROY mailbox failed with "
  13066. "status x%x add_status x%x, mbx status x%x\n",
  13067. shdr_status, shdr_add_status, rc);
  13068. status = -ENXIO;
  13069. }
  13070. /* Remove wq from any list */
  13071. list_del_init(&wq->list);
  13072. mempool_free(mbox, wq->phba->mbox_mem_pool);
  13073. return status;
  13074. }
  13075. /**
  13076. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  13077. * @rq: The queue structure associated with the queue to destroy.
  13078. *
  13079. * This function destroys a queue, as detailed in @rq by sending an mailbox
  13080. * command, specific to the type of queue, to the HBA.
  13081. *
  13082. * The @rq struct is used to get the queue ID of the queue to destroy.
  13083. *
  13084. * On success this function will return a zero. If the queue destroy mailbox
  13085. * command fails this function will return -ENXIO.
  13086. **/
  13087. int
  13088. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  13089. struct lpfc_queue *drq)
  13090. {
  13091. LPFC_MBOXQ_t *mbox;
  13092. int rc, length, status = 0;
  13093. uint32_t shdr_status, shdr_add_status;
  13094. union lpfc_sli4_cfg_shdr *shdr;
  13095. /* sanity check on queue memory */
  13096. if (!hrq || !drq)
  13097. return -ENODEV;
  13098. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  13099. if (!mbox)
  13100. return -ENOMEM;
  13101. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  13102. sizeof(struct lpfc_sli4_cfg_mhdr));
  13103. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13104. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  13105. length, LPFC_SLI4_MBX_EMBED);
  13106. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  13107. hrq->queue_id);
  13108. mbox->vport = hrq->phba->pport;
  13109. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13110. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  13111. /* The IOCTL status is embedded in the mailbox subheader. */
  13112. shdr = (union lpfc_sli4_cfg_shdr *)
  13113. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  13114. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13115. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13116. if (shdr_status || shdr_add_status || rc) {
  13117. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13118. "2509 RQ_DESTROY mailbox failed with "
  13119. "status x%x add_status x%x, mbx status x%x\n",
  13120. shdr_status, shdr_add_status, rc);
  13121. if (rc != MBX_TIMEOUT)
  13122. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  13123. return -ENXIO;
  13124. }
  13125. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  13126. drq->queue_id);
  13127. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  13128. shdr = (union lpfc_sli4_cfg_shdr *)
  13129. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  13130. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13131. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13132. if (shdr_status || shdr_add_status || rc) {
  13133. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13134. "2510 RQ_DESTROY mailbox failed with "
  13135. "status x%x add_status x%x, mbx status x%x\n",
  13136. shdr_status, shdr_add_status, rc);
  13137. status = -ENXIO;
  13138. }
  13139. list_del_init(&hrq->list);
  13140. list_del_init(&drq->list);
  13141. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  13142. return status;
  13143. }
  13144. /**
  13145. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  13146. * @phba: The virtual port for which this call being executed.
  13147. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  13148. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  13149. * @xritag: the xritag that ties this io to the SGL pages.
  13150. *
  13151. * This routine will post the sgl pages for the IO that has the xritag
  13152. * that is in the iocbq structure. The xritag is assigned during iocbq
  13153. * creation and persists for as long as the driver is loaded.
  13154. * if the caller has fewer than 256 scatter gather segments to map then
  13155. * pdma_phys_addr1 should be 0.
  13156. * If the caller needs to map more than 256 scatter gather segment then
  13157. * pdma_phys_addr1 should be a valid physical address.
  13158. * physical address for SGLs must be 64 byte aligned.
  13159. * If you are going to map 2 SGL's then the first one must have 256 entries
  13160. * the second sgl can have between 1 and 256 entries.
  13161. *
  13162. * Return codes:
  13163. * 0 - Success
  13164. * -ENXIO, -ENOMEM - Failure
  13165. **/
  13166. int
  13167. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  13168. dma_addr_t pdma_phys_addr0,
  13169. dma_addr_t pdma_phys_addr1,
  13170. uint16_t xritag)
  13171. {
  13172. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  13173. LPFC_MBOXQ_t *mbox;
  13174. int rc;
  13175. uint32_t shdr_status, shdr_add_status;
  13176. uint32_t mbox_tmo;
  13177. union lpfc_sli4_cfg_shdr *shdr;
  13178. if (xritag == NO_XRI) {
  13179. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13180. "0364 Invalid param:\n");
  13181. return -EINVAL;
  13182. }
  13183. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13184. if (!mbox)
  13185. return -ENOMEM;
  13186. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13187. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  13188. sizeof(struct lpfc_mbx_post_sgl_pages) -
  13189. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  13190. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  13191. &mbox->u.mqe.un.post_sgl_pages;
  13192. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  13193. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  13194. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  13195. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  13196. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  13197. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  13198. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  13199. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  13200. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  13201. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  13202. if (!phba->sli4_hba.intr_enable)
  13203. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13204. else {
  13205. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13206. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13207. }
  13208. /* The IOCTL status is embedded in the mailbox subheader. */
  13209. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  13210. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13211. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13212. if (rc != MBX_TIMEOUT)
  13213. mempool_free(mbox, phba->mbox_mem_pool);
  13214. if (shdr_status || shdr_add_status || rc) {
  13215. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13216. "2511 POST_SGL mailbox failed with "
  13217. "status x%x add_status x%x, mbx status x%x\n",
  13218. shdr_status, shdr_add_status, rc);
  13219. }
  13220. return 0;
  13221. }
  13222. /**
  13223. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  13224. * @phba: pointer to lpfc hba data structure.
  13225. *
  13226. * This routine is invoked to post rpi header templates to the
  13227. * HBA consistent with the SLI-4 interface spec. This routine
  13228. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13229. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13230. *
  13231. * Returns
  13232. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13233. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13234. **/
  13235. static uint16_t
  13236. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  13237. {
  13238. unsigned long xri;
  13239. /*
  13240. * Fetch the next logical xri. Because this index is logical,
  13241. * the driver starts at 0 each time.
  13242. */
  13243. spin_lock_irq(&phba->hbalock);
  13244. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  13245. phba->sli4_hba.max_cfg_param.max_xri, 0);
  13246. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  13247. spin_unlock_irq(&phba->hbalock);
  13248. return NO_XRI;
  13249. } else {
  13250. set_bit(xri, phba->sli4_hba.xri_bmask);
  13251. phba->sli4_hba.max_cfg_param.xri_used++;
  13252. }
  13253. spin_unlock_irq(&phba->hbalock);
  13254. return xri;
  13255. }
  13256. /**
  13257. * lpfc_sli4_free_xri - Release an xri for reuse.
  13258. * @phba: pointer to lpfc hba data structure.
  13259. *
  13260. * This routine is invoked to release an xri to the pool of
  13261. * available rpis maintained by the driver.
  13262. **/
  13263. static void
  13264. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  13265. {
  13266. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  13267. phba->sli4_hba.max_cfg_param.xri_used--;
  13268. }
  13269. }
  13270. /**
  13271. * lpfc_sli4_free_xri - Release an xri for reuse.
  13272. * @phba: pointer to lpfc hba data structure.
  13273. *
  13274. * This routine is invoked to release an xri to the pool of
  13275. * available rpis maintained by the driver.
  13276. **/
  13277. void
  13278. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  13279. {
  13280. spin_lock_irq(&phba->hbalock);
  13281. __lpfc_sli4_free_xri(phba, xri);
  13282. spin_unlock_irq(&phba->hbalock);
  13283. }
  13284. /**
  13285. * lpfc_sli4_next_xritag - Get an xritag for the io
  13286. * @phba: Pointer to HBA context object.
  13287. *
  13288. * This function gets an xritag for the iocb. If there is no unused xritag
  13289. * it will return 0xffff.
  13290. * The function returns the allocated xritag if successful, else returns zero.
  13291. * Zero is not a valid xritag.
  13292. * The caller is not required to hold any lock.
  13293. **/
  13294. uint16_t
  13295. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  13296. {
  13297. uint16_t xri_index;
  13298. xri_index = lpfc_sli4_alloc_xri(phba);
  13299. if (xri_index == NO_XRI)
  13300. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  13301. "2004 Failed to allocate XRI.last XRITAG is %d"
  13302. " Max XRI is %d, Used XRI is %d\n",
  13303. xri_index,
  13304. phba->sli4_hba.max_cfg_param.max_xri,
  13305. phba->sli4_hba.max_cfg_param.xri_used);
  13306. return xri_index;
  13307. }
  13308. /**
  13309. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  13310. * @phba: pointer to lpfc hba data structure.
  13311. * @post_sgl_list: pointer to els sgl entry list.
  13312. * @count: number of els sgl entries on the list.
  13313. *
  13314. * This routine is invoked to post a block of driver's sgl pages to the
  13315. * HBA using non-embedded mailbox command. No Lock is held. This routine
  13316. * is only called when the driver is loading and after all IO has been
  13317. * stopped.
  13318. **/
  13319. static int
  13320. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  13321. struct list_head *post_sgl_list,
  13322. int post_cnt)
  13323. {
  13324. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  13325. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  13326. struct sgl_page_pairs *sgl_pg_pairs;
  13327. void *viraddr;
  13328. LPFC_MBOXQ_t *mbox;
  13329. uint32_t reqlen, alloclen, pg_pairs;
  13330. uint32_t mbox_tmo;
  13331. uint16_t xritag_start = 0;
  13332. int rc = 0;
  13333. uint32_t shdr_status, shdr_add_status;
  13334. union lpfc_sli4_cfg_shdr *shdr;
  13335. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  13336. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  13337. if (reqlen > SLI4_PAGE_SIZE) {
  13338. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  13339. "2559 Block sgl registration required DMA "
  13340. "size (%d) great than a page\n", reqlen);
  13341. return -ENOMEM;
  13342. }
  13343. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13344. if (!mbox)
  13345. return -ENOMEM;
  13346. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13347. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13348. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  13349. LPFC_SLI4_MBX_NEMBED);
  13350. if (alloclen < reqlen) {
  13351. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13352. "0285 Allocated DMA memory size (%d) is "
  13353. "less than the requested DMA memory "
  13354. "size (%d)\n", alloclen, reqlen);
  13355. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13356. return -ENOMEM;
  13357. }
  13358. /* Set up the SGL pages in the non-embedded DMA pages */
  13359. viraddr = mbox->sge_array->addr[0];
  13360. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  13361. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  13362. pg_pairs = 0;
  13363. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  13364. /* Set up the sge entry */
  13365. sgl_pg_pairs->sgl_pg0_addr_lo =
  13366. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  13367. sgl_pg_pairs->sgl_pg0_addr_hi =
  13368. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  13369. sgl_pg_pairs->sgl_pg1_addr_lo =
  13370. cpu_to_le32(putPaddrLow(0));
  13371. sgl_pg_pairs->sgl_pg1_addr_hi =
  13372. cpu_to_le32(putPaddrHigh(0));
  13373. /* Keep the first xritag on the list */
  13374. if (pg_pairs == 0)
  13375. xritag_start = sglq_entry->sli4_xritag;
  13376. sgl_pg_pairs++;
  13377. pg_pairs++;
  13378. }
  13379. /* Complete initialization and perform endian conversion. */
  13380. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  13381. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  13382. sgl->word0 = cpu_to_le32(sgl->word0);
  13383. if (!phba->sli4_hba.intr_enable)
  13384. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13385. else {
  13386. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13387. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13388. }
  13389. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  13390. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13391. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13392. if (rc != MBX_TIMEOUT)
  13393. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13394. if (shdr_status || shdr_add_status || rc) {
  13395. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13396. "2513 POST_SGL_BLOCK mailbox command failed "
  13397. "status x%x add_status x%x mbx status x%x\n",
  13398. shdr_status, shdr_add_status, rc);
  13399. rc = -ENXIO;
  13400. }
  13401. return rc;
  13402. }
  13403. /**
  13404. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  13405. * @phba: pointer to lpfc hba data structure.
  13406. * @sblist: pointer to scsi buffer list.
  13407. * @count: number of scsi buffers on the list.
  13408. *
  13409. * This routine is invoked to post a block of @count scsi sgl pages from a
  13410. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  13411. * No Lock is held.
  13412. *
  13413. **/
  13414. int
  13415. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  13416. struct list_head *sblist,
  13417. int count)
  13418. {
  13419. struct lpfc_scsi_buf *psb;
  13420. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  13421. struct sgl_page_pairs *sgl_pg_pairs;
  13422. void *viraddr;
  13423. LPFC_MBOXQ_t *mbox;
  13424. uint32_t reqlen, alloclen, pg_pairs;
  13425. uint32_t mbox_tmo;
  13426. uint16_t xritag_start = 0;
  13427. int rc = 0;
  13428. uint32_t shdr_status, shdr_add_status;
  13429. dma_addr_t pdma_phys_bpl1;
  13430. union lpfc_sli4_cfg_shdr *shdr;
  13431. /* Calculate the requested length of the dma memory */
  13432. reqlen = count * sizeof(struct sgl_page_pairs) +
  13433. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  13434. if (reqlen > SLI4_PAGE_SIZE) {
  13435. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  13436. "0217 Block sgl registration required DMA "
  13437. "size (%d) great than a page\n", reqlen);
  13438. return -ENOMEM;
  13439. }
  13440. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13441. if (!mbox) {
  13442. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13443. "0283 Failed to allocate mbox cmd memory\n");
  13444. return -ENOMEM;
  13445. }
  13446. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13447. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13448. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  13449. LPFC_SLI4_MBX_NEMBED);
  13450. if (alloclen < reqlen) {
  13451. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13452. "2561 Allocated DMA memory size (%d) is "
  13453. "less than the requested DMA memory "
  13454. "size (%d)\n", alloclen, reqlen);
  13455. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13456. return -ENOMEM;
  13457. }
  13458. /* Get the first SGE entry from the non-embedded DMA memory */
  13459. viraddr = mbox->sge_array->addr[0];
  13460. /* Set up the SGL pages in the non-embedded DMA pages */
  13461. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  13462. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  13463. pg_pairs = 0;
  13464. list_for_each_entry(psb, sblist, list) {
  13465. /* Set up the sge entry */
  13466. sgl_pg_pairs->sgl_pg0_addr_lo =
  13467. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  13468. sgl_pg_pairs->sgl_pg0_addr_hi =
  13469. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  13470. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  13471. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  13472. else
  13473. pdma_phys_bpl1 = 0;
  13474. sgl_pg_pairs->sgl_pg1_addr_lo =
  13475. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  13476. sgl_pg_pairs->sgl_pg1_addr_hi =
  13477. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  13478. /* Keep the first xritag on the list */
  13479. if (pg_pairs == 0)
  13480. xritag_start = psb->cur_iocbq.sli4_xritag;
  13481. sgl_pg_pairs++;
  13482. pg_pairs++;
  13483. }
  13484. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  13485. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  13486. /* Perform endian conversion if necessary */
  13487. sgl->word0 = cpu_to_le32(sgl->word0);
  13488. if (!phba->sli4_hba.intr_enable)
  13489. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13490. else {
  13491. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13492. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13493. }
  13494. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  13495. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13496. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13497. if (rc != MBX_TIMEOUT)
  13498. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13499. if (shdr_status || shdr_add_status || rc) {
  13500. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13501. "2564 POST_SGL_BLOCK mailbox command failed "
  13502. "status x%x add_status x%x mbx status x%x\n",
  13503. shdr_status, shdr_add_status, rc);
  13504. rc = -ENXIO;
  13505. }
  13506. return rc;
  13507. }
  13508. /**
  13509. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  13510. * @phba: pointer to lpfc_hba struct that the frame was received on
  13511. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13512. *
  13513. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  13514. * valid type of frame that the LPFC driver will handle. This function will
  13515. * return a zero if the frame is a valid frame or a non zero value when the
  13516. * frame does not pass the check.
  13517. **/
  13518. static int
  13519. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  13520. {
  13521. /* make rctl_names static to save stack space */
  13522. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  13523. char *type_names[] = FC_TYPE_NAMES_INIT;
  13524. struct fc_vft_header *fc_vft_hdr;
  13525. uint32_t *header = (uint32_t *) fc_hdr;
  13526. switch (fc_hdr->fh_r_ctl) {
  13527. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  13528. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  13529. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  13530. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  13531. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  13532. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  13533. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  13534. case FC_RCTL_DD_CMD_STATUS: /* command status */
  13535. case FC_RCTL_ELS_REQ: /* extended link services request */
  13536. case FC_RCTL_ELS_REP: /* extended link services reply */
  13537. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  13538. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  13539. case FC_RCTL_BA_NOP: /* basic link service NOP */
  13540. case FC_RCTL_BA_ABTS: /* basic link service abort */
  13541. case FC_RCTL_BA_RMC: /* remove connection */
  13542. case FC_RCTL_BA_ACC: /* basic accept */
  13543. case FC_RCTL_BA_RJT: /* basic reject */
  13544. case FC_RCTL_BA_PRMT:
  13545. case FC_RCTL_ACK_1: /* acknowledge_1 */
  13546. case FC_RCTL_ACK_0: /* acknowledge_0 */
  13547. case FC_RCTL_P_RJT: /* port reject */
  13548. case FC_RCTL_F_RJT: /* fabric reject */
  13549. case FC_RCTL_P_BSY: /* port busy */
  13550. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  13551. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  13552. case FC_RCTL_LCR: /* link credit reset */
  13553. case FC_RCTL_END: /* end */
  13554. break;
  13555. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  13556. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  13557. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  13558. return lpfc_fc_frame_check(phba, fc_hdr);
  13559. default:
  13560. goto drop;
  13561. }
  13562. switch (fc_hdr->fh_type) {
  13563. case FC_TYPE_BLS:
  13564. case FC_TYPE_ELS:
  13565. case FC_TYPE_FCP:
  13566. case FC_TYPE_CT:
  13567. break;
  13568. case FC_TYPE_IP:
  13569. case FC_TYPE_ILS:
  13570. default:
  13571. goto drop;
  13572. }
  13573. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  13574. "2538 Received frame rctl:%s (x%x), type:%s (x%x), "
  13575. "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
  13576. rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl,
  13577. type_names[fc_hdr->fh_type], fc_hdr->fh_type,
  13578. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  13579. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  13580. be32_to_cpu(header[4]), be32_to_cpu(header[5]),
  13581. be32_to_cpu(header[6]));
  13582. return 0;
  13583. drop:
  13584. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  13585. "2539 Dropped frame rctl:%s type:%s\n",
  13586. rctl_names[fc_hdr->fh_r_ctl],
  13587. type_names[fc_hdr->fh_type]);
  13588. return 1;
  13589. }
  13590. /**
  13591. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  13592. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13593. *
  13594. * This function processes the FC header to retrieve the VFI from the VF
  13595. * header, if one exists. This function will return the VFI if one exists
  13596. * or 0 if no VSAN Header exists.
  13597. **/
  13598. static uint32_t
  13599. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  13600. {
  13601. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  13602. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  13603. return 0;
  13604. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  13605. }
  13606. /**
  13607. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  13608. * @phba: Pointer to the HBA structure to search for the vport on
  13609. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13610. * @fcfi: The FC Fabric ID that the frame came from
  13611. *
  13612. * This function searches the @phba for a vport that matches the content of the
  13613. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  13614. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  13615. * returns the matching vport pointer or NULL if unable to match frame to a
  13616. * vport.
  13617. **/
  13618. static struct lpfc_vport *
  13619. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  13620. uint16_t fcfi)
  13621. {
  13622. struct lpfc_vport **vports;
  13623. struct lpfc_vport *vport = NULL;
  13624. int i;
  13625. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  13626. fc_hdr->fh_d_id[1] << 8 |
  13627. fc_hdr->fh_d_id[2]);
  13628. if (did == Fabric_DID)
  13629. return phba->pport;
  13630. if ((phba->pport->fc_flag & FC_PT2PT) &&
  13631. !(phba->link_state == LPFC_HBA_READY))
  13632. return phba->pport;
  13633. vports = lpfc_create_vport_work_array(phba);
  13634. if (vports != NULL)
  13635. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  13636. if (phba->fcf.fcfi == fcfi &&
  13637. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  13638. vports[i]->fc_myDID == did) {
  13639. vport = vports[i];
  13640. break;
  13641. }
  13642. }
  13643. lpfc_destroy_vport_work_array(phba, vports);
  13644. return vport;
  13645. }
  13646. /**
  13647. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  13648. * @vport: The vport to work on.
  13649. *
  13650. * This function updates the receive sequence time stamp for this vport. The
  13651. * receive sequence time stamp indicates the time that the last frame of the
  13652. * the sequence that has been idle for the longest amount of time was received.
  13653. * the driver uses this time stamp to indicate if any received sequences have
  13654. * timed out.
  13655. **/
  13656. static void
  13657. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  13658. {
  13659. struct lpfc_dmabuf *h_buf;
  13660. struct hbq_dmabuf *dmabuf = NULL;
  13661. /* get the oldest sequence on the rcv list */
  13662. h_buf = list_get_first(&vport->rcv_buffer_list,
  13663. struct lpfc_dmabuf, list);
  13664. if (!h_buf)
  13665. return;
  13666. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13667. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  13668. }
  13669. /**
  13670. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  13671. * @vport: The vport that the received sequences were sent to.
  13672. *
  13673. * This function cleans up all outstanding received sequences. This is called
  13674. * by the driver when a link event or user action invalidates all the received
  13675. * sequences.
  13676. **/
  13677. void
  13678. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  13679. {
  13680. struct lpfc_dmabuf *h_buf, *hnext;
  13681. struct lpfc_dmabuf *d_buf, *dnext;
  13682. struct hbq_dmabuf *dmabuf = NULL;
  13683. /* start with the oldest sequence on the rcv list */
  13684. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  13685. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13686. list_del_init(&dmabuf->hbuf.list);
  13687. list_for_each_entry_safe(d_buf, dnext,
  13688. &dmabuf->dbuf.list, list) {
  13689. list_del_init(&d_buf->list);
  13690. lpfc_in_buf_free(vport->phba, d_buf);
  13691. }
  13692. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  13693. }
  13694. }
  13695. /**
  13696. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  13697. * @vport: The vport that the received sequences were sent to.
  13698. *
  13699. * This function determines whether any received sequences have timed out by
  13700. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  13701. * indicates that there is at least one timed out sequence this routine will
  13702. * go through the received sequences one at a time from most inactive to most
  13703. * active to determine which ones need to be cleaned up. Once it has determined
  13704. * that a sequence needs to be cleaned up it will simply free up the resources
  13705. * without sending an abort.
  13706. **/
  13707. void
  13708. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  13709. {
  13710. struct lpfc_dmabuf *h_buf, *hnext;
  13711. struct lpfc_dmabuf *d_buf, *dnext;
  13712. struct hbq_dmabuf *dmabuf = NULL;
  13713. unsigned long timeout;
  13714. int abort_count = 0;
  13715. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  13716. vport->rcv_buffer_time_stamp);
  13717. if (list_empty(&vport->rcv_buffer_list) ||
  13718. time_before(jiffies, timeout))
  13719. return;
  13720. /* start with the oldest sequence on the rcv list */
  13721. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  13722. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13723. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  13724. dmabuf->time_stamp);
  13725. if (time_before(jiffies, timeout))
  13726. break;
  13727. abort_count++;
  13728. list_del_init(&dmabuf->hbuf.list);
  13729. list_for_each_entry_safe(d_buf, dnext,
  13730. &dmabuf->dbuf.list, list) {
  13731. list_del_init(&d_buf->list);
  13732. lpfc_in_buf_free(vport->phba, d_buf);
  13733. }
  13734. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  13735. }
  13736. if (abort_count)
  13737. lpfc_update_rcv_time_stamp(vport);
  13738. }
  13739. /**
  13740. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  13741. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  13742. *
  13743. * This function searches through the existing incomplete sequences that have
  13744. * been sent to this @vport. If the frame matches one of the incomplete
  13745. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  13746. * make up that sequence. If no sequence is found that matches this frame then
  13747. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  13748. * This function returns a pointer to the first dmabuf in the sequence list that
  13749. * the frame was linked to.
  13750. **/
  13751. static struct hbq_dmabuf *
  13752. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13753. {
  13754. struct fc_frame_header *new_hdr;
  13755. struct fc_frame_header *temp_hdr;
  13756. struct lpfc_dmabuf *d_buf;
  13757. struct lpfc_dmabuf *h_buf;
  13758. struct hbq_dmabuf *seq_dmabuf = NULL;
  13759. struct hbq_dmabuf *temp_dmabuf = NULL;
  13760. uint8_t found = 0;
  13761. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13762. dmabuf->time_stamp = jiffies;
  13763. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13764. /* Use the hdr_buf to find the sequence that this frame belongs to */
  13765. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13766. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13767. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13768. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13769. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13770. continue;
  13771. /* found a pending sequence that matches this frame */
  13772. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13773. break;
  13774. }
  13775. if (!seq_dmabuf) {
  13776. /*
  13777. * This indicates first frame received for this sequence.
  13778. * Queue the buffer on the vport's rcv_buffer_list.
  13779. */
  13780. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13781. lpfc_update_rcv_time_stamp(vport);
  13782. return dmabuf;
  13783. }
  13784. temp_hdr = seq_dmabuf->hbuf.virt;
  13785. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  13786. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13787. list_del_init(&seq_dmabuf->hbuf.list);
  13788. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13789. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13790. lpfc_update_rcv_time_stamp(vport);
  13791. return dmabuf;
  13792. }
  13793. /* move this sequence to the tail to indicate a young sequence */
  13794. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13795. seq_dmabuf->time_stamp = jiffies;
  13796. lpfc_update_rcv_time_stamp(vport);
  13797. if (list_empty(&seq_dmabuf->dbuf.list)) {
  13798. temp_hdr = dmabuf->hbuf.virt;
  13799. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13800. return seq_dmabuf;
  13801. }
  13802. /* find the correct place in the sequence to insert this frame */
  13803. d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
  13804. while (!found) {
  13805. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13806. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  13807. /*
  13808. * If the frame's sequence count is greater than the frame on
  13809. * the list then insert the frame right after this frame
  13810. */
  13811. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  13812. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13813. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  13814. found = 1;
  13815. break;
  13816. }
  13817. if (&d_buf->list == &seq_dmabuf->dbuf.list)
  13818. break;
  13819. d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
  13820. }
  13821. if (found)
  13822. return seq_dmabuf;
  13823. return NULL;
  13824. }
  13825. /**
  13826. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  13827. * @vport: pointer to a vitural port
  13828. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13829. *
  13830. * This function tries to abort from the partially assembed sequence, described
  13831. * by the information from basic abbort @dmabuf. It checks to see whether such
  13832. * partially assembled sequence held by the driver. If so, it shall free up all
  13833. * the frames from the partially assembled sequence.
  13834. *
  13835. * Return
  13836. * true -- if there is matching partially assembled sequence present and all
  13837. * the frames freed with the sequence;
  13838. * false -- if there is no matching partially assembled sequence present so
  13839. * nothing got aborted in the lower layer driver
  13840. **/
  13841. static bool
  13842. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  13843. struct hbq_dmabuf *dmabuf)
  13844. {
  13845. struct fc_frame_header *new_hdr;
  13846. struct fc_frame_header *temp_hdr;
  13847. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  13848. struct hbq_dmabuf *seq_dmabuf = NULL;
  13849. /* Use the hdr_buf to find the sequence that matches this frame */
  13850. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13851. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  13852. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13853. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13854. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13855. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13856. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13857. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13858. continue;
  13859. /* found a pending sequence that matches this frame */
  13860. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13861. break;
  13862. }
  13863. /* Free up all the frames from the partially assembled sequence */
  13864. if (seq_dmabuf) {
  13865. list_for_each_entry_safe(d_buf, n_buf,
  13866. &seq_dmabuf->dbuf.list, list) {
  13867. list_del_init(&d_buf->list);
  13868. lpfc_in_buf_free(vport->phba, d_buf);
  13869. }
  13870. return true;
  13871. }
  13872. return false;
  13873. }
  13874. /**
  13875. * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
  13876. * @vport: pointer to a vitural port
  13877. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13878. *
  13879. * This function tries to abort from the assembed sequence from upper level
  13880. * protocol, described by the information from basic abbort @dmabuf. It
  13881. * checks to see whether such pending context exists at upper level protocol.
  13882. * If so, it shall clean up the pending context.
  13883. *
  13884. * Return
  13885. * true -- if there is matching pending context of the sequence cleaned
  13886. * at ulp;
  13887. * false -- if there is no matching pending context of the sequence present
  13888. * at ulp.
  13889. **/
  13890. static bool
  13891. lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13892. {
  13893. struct lpfc_hba *phba = vport->phba;
  13894. int handled;
  13895. /* Accepting abort at ulp with SLI4 only */
  13896. if (phba->sli_rev < LPFC_SLI_REV4)
  13897. return false;
  13898. /* Register all caring upper level protocols to attend abort */
  13899. handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
  13900. if (handled)
  13901. return true;
  13902. return false;
  13903. }
  13904. /**
  13905. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  13906. * @phba: Pointer to HBA context object.
  13907. * @cmd_iocbq: pointer to the command iocbq structure.
  13908. * @rsp_iocbq: pointer to the response iocbq structure.
  13909. *
  13910. * This function handles the sequence abort response iocb command complete
  13911. * event. It properly releases the memory allocated to the sequence abort
  13912. * accept iocb.
  13913. **/
  13914. static void
  13915. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  13916. struct lpfc_iocbq *cmd_iocbq,
  13917. struct lpfc_iocbq *rsp_iocbq)
  13918. {
  13919. struct lpfc_nodelist *ndlp;
  13920. if (cmd_iocbq) {
  13921. ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
  13922. lpfc_nlp_put(ndlp);
  13923. lpfc_nlp_not_used(ndlp);
  13924. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  13925. }
  13926. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  13927. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  13928. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13929. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  13930. rsp_iocbq->iocb.ulpStatus,
  13931. rsp_iocbq->iocb.un.ulpWord[4]);
  13932. }
  13933. /**
  13934. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  13935. * @phba: Pointer to HBA context object.
  13936. * @xri: xri id in transaction.
  13937. *
  13938. * This function validates the xri maps to the known range of XRIs allocated an
  13939. * used by the driver.
  13940. **/
  13941. uint16_t
  13942. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  13943. uint16_t xri)
  13944. {
  13945. uint16_t i;
  13946. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  13947. if (xri == phba->sli4_hba.xri_ids[i])
  13948. return i;
  13949. }
  13950. return NO_XRI;
  13951. }
  13952. /**
  13953. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  13954. * @phba: Pointer to HBA context object.
  13955. * @fc_hdr: pointer to a FC frame header.
  13956. *
  13957. * This function sends a basic response to a previous unsol sequence abort
  13958. * event after aborting the sequence handling.
  13959. **/
  13960. static void
  13961. lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
  13962. struct fc_frame_header *fc_hdr, bool aborted)
  13963. {
  13964. struct lpfc_hba *phba = vport->phba;
  13965. struct lpfc_iocbq *ctiocb = NULL;
  13966. struct lpfc_nodelist *ndlp;
  13967. uint16_t oxid, rxid, xri, lxri;
  13968. uint32_t sid, fctl;
  13969. IOCB_t *icmd;
  13970. int rc;
  13971. if (!lpfc_is_link_up(phba))
  13972. return;
  13973. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13974. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  13975. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  13976. ndlp = lpfc_findnode_did(vport, sid);
  13977. if (!ndlp) {
  13978. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  13979. if (!ndlp) {
  13980. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13981. "1268 Failed to allocate ndlp for "
  13982. "oxid:x%x SID:x%x\n", oxid, sid);
  13983. return;
  13984. }
  13985. lpfc_nlp_init(vport, ndlp, sid);
  13986. /* Put ndlp onto pport node list */
  13987. lpfc_enqueue_node(vport, ndlp);
  13988. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  13989. /* re-setup ndlp without removing from node list */
  13990. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  13991. if (!ndlp) {
  13992. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13993. "3275 Failed to active ndlp found "
  13994. "for oxid:x%x SID:x%x\n", oxid, sid);
  13995. return;
  13996. }
  13997. }
  13998. /* Allocate buffer for rsp iocb */
  13999. ctiocb = lpfc_sli_get_iocbq(phba);
  14000. if (!ctiocb)
  14001. return;
  14002. /* Extract the F_CTL field from FC_HDR */
  14003. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  14004. icmd = &ctiocb->iocb;
  14005. icmd->un.xseq64.bdl.bdeSize = 0;
  14006. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  14007. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  14008. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  14009. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  14010. /* Fill in the rest of iocb fields */
  14011. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  14012. icmd->ulpBdeCount = 0;
  14013. icmd->ulpLe = 1;
  14014. icmd->ulpClass = CLASS3;
  14015. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  14016. ctiocb->context1 = lpfc_nlp_get(ndlp);
  14017. ctiocb->iocb_cmpl = NULL;
  14018. ctiocb->vport = phba->pport;
  14019. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  14020. ctiocb->sli4_lxritag = NO_XRI;
  14021. ctiocb->sli4_xritag = NO_XRI;
  14022. if (fctl & FC_FC_EX_CTX)
  14023. /* Exchange responder sent the abort so we
  14024. * own the oxid.
  14025. */
  14026. xri = oxid;
  14027. else
  14028. xri = rxid;
  14029. lxri = lpfc_sli4_xri_inrange(phba, xri);
  14030. if (lxri != NO_XRI)
  14031. lpfc_set_rrq_active(phba, ndlp, lxri,
  14032. (xri == oxid) ? rxid : oxid, 0);
  14033. /* For BA_ABTS from exchange responder, if the logical xri with
  14034. * the oxid maps to the FCP XRI range, the port no longer has
  14035. * that exchange context, send a BLS_RJT. Override the IOCB for
  14036. * a BA_RJT.
  14037. */
  14038. if ((fctl & FC_FC_EX_CTX) &&
  14039. (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) {
  14040. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  14041. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  14042. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  14043. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  14044. }
  14045. /* If BA_ABTS failed to abort a partially assembled receive sequence,
  14046. * the driver no longer has that exchange, send a BLS_RJT. Override
  14047. * the IOCB for a BA_RJT.
  14048. */
  14049. if (aborted == false) {
  14050. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  14051. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  14052. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  14053. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  14054. }
  14055. if (fctl & FC_FC_EX_CTX) {
  14056. /* ABTS sent by responder to CT exchange, construction
  14057. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  14058. * field and RX_ID from ABTS for RX_ID field.
  14059. */
  14060. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  14061. } else {
  14062. /* ABTS sent by initiator to CT exchange, construction
  14063. * of BA_ACC will need to allocate a new XRI as for the
  14064. * XRI_TAG field.
  14065. */
  14066. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  14067. }
  14068. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  14069. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  14070. /* Xmit CT abts response on exchange <xid> */
  14071. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  14072. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  14073. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  14074. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  14075. if (rc == IOCB_ERROR) {
  14076. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  14077. "2925 Failed to issue CT ABTS RSP x%x on "
  14078. "xri x%x, Data x%x\n",
  14079. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  14080. phba->link_state);
  14081. lpfc_nlp_put(ndlp);
  14082. ctiocb->context1 = NULL;
  14083. lpfc_sli_release_iocbq(phba, ctiocb);
  14084. }
  14085. }
  14086. /**
  14087. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  14088. * @vport: Pointer to the vport on which this sequence was received
  14089. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  14090. *
  14091. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  14092. * receive sequence is only partially assembed by the driver, it shall abort
  14093. * the partially assembled frames for the sequence. Otherwise, if the
  14094. * unsolicited receive sequence has been completely assembled and passed to
  14095. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  14096. * unsolicited sequence has been aborted. After that, it will issue a basic
  14097. * accept to accept the abort.
  14098. **/
  14099. static void
  14100. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  14101. struct hbq_dmabuf *dmabuf)
  14102. {
  14103. struct lpfc_hba *phba = vport->phba;
  14104. struct fc_frame_header fc_hdr;
  14105. uint32_t fctl;
  14106. bool aborted;
  14107. /* Make a copy of fc_hdr before the dmabuf being released */
  14108. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  14109. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  14110. if (fctl & FC_FC_EX_CTX) {
  14111. /* ABTS by responder to exchange, no cleanup needed */
  14112. aborted = true;
  14113. } else {
  14114. /* ABTS by initiator to exchange, need to do cleanup */
  14115. aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  14116. if (aborted == false)
  14117. aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
  14118. }
  14119. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14120. /* Respond with BA_ACC or BA_RJT accordingly */
  14121. lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
  14122. }
  14123. /**
  14124. * lpfc_seq_complete - Indicates if a sequence is complete
  14125. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  14126. *
  14127. * This function checks the sequence, starting with the frame described by
  14128. * @dmabuf, to see if all the frames associated with this sequence are present.
  14129. * the frames associated with this sequence are linked to the @dmabuf using the
  14130. * dbuf list. This function looks for two major things. 1) That the first frame
  14131. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  14132. * set. 3) That there are no holes in the sequence count. The function will
  14133. * return 1 when the sequence is complete, otherwise it will return 0.
  14134. **/
  14135. static int
  14136. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  14137. {
  14138. struct fc_frame_header *hdr;
  14139. struct lpfc_dmabuf *d_buf;
  14140. struct hbq_dmabuf *seq_dmabuf;
  14141. uint32_t fctl;
  14142. int seq_count = 0;
  14143. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  14144. /* make sure first fame of sequence has a sequence count of zero */
  14145. if (hdr->fh_seq_cnt != seq_count)
  14146. return 0;
  14147. fctl = (hdr->fh_f_ctl[0] << 16 |
  14148. hdr->fh_f_ctl[1] << 8 |
  14149. hdr->fh_f_ctl[2]);
  14150. /* If last frame of sequence we can return success. */
  14151. if (fctl & FC_FC_END_SEQ)
  14152. return 1;
  14153. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  14154. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  14155. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14156. /* If there is a hole in the sequence count then fail. */
  14157. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  14158. return 0;
  14159. fctl = (hdr->fh_f_ctl[0] << 16 |
  14160. hdr->fh_f_ctl[1] << 8 |
  14161. hdr->fh_f_ctl[2]);
  14162. /* If last frame of sequence we can return success. */
  14163. if (fctl & FC_FC_END_SEQ)
  14164. return 1;
  14165. }
  14166. return 0;
  14167. }
  14168. /**
  14169. * lpfc_prep_seq - Prep sequence for ULP processing
  14170. * @vport: Pointer to the vport on which this sequence was received
  14171. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  14172. *
  14173. * This function takes a sequence, described by a list of frames, and creates
  14174. * a list of iocbq structures to describe the sequence. This iocbq list will be
  14175. * used to issue to the generic unsolicited sequence handler. This routine
  14176. * returns a pointer to the first iocbq in the list. If the function is unable
  14177. * to allocate an iocbq then it throw out the received frames that were not
  14178. * able to be described and return a pointer to the first iocbq. If unable to
  14179. * allocate any iocbqs (including the first) this function will return NULL.
  14180. **/
  14181. static struct lpfc_iocbq *
  14182. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  14183. {
  14184. struct hbq_dmabuf *hbq_buf;
  14185. struct lpfc_dmabuf *d_buf, *n_buf;
  14186. struct lpfc_iocbq *first_iocbq, *iocbq;
  14187. struct fc_frame_header *fc_hdr;
  14188. uint32_t sid;
  14189. uint32_t len, tot_len;
  14190. struct ulp_bde64 *pbde;
  14191. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14192. /* remove from receive buffer list */
  14193. list_del_init(&seq_dmabuf->hbuf.list);
  14194. lpfc_update_rcv_time_stamp(vport);
  14195. /* get the Remote Port's SID */
  14196. sid = sli4_sid_from_fc_hdr(fc_hdr);
  14197. tot_len = 0;
  14198. /* Get an iocbq struct to fill in. */
  14199. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  14200. if (first_iocbq) {
  14201. /* Initialize the first IOCB. */
  14202. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  14203. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  14204. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  14205. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  14206. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  14207. first_iocbq->iocb.un.rcvels.parmRo =
  14208. sli4_did_from_fc_hdr(fc_hdr);
  14209. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  14210. } else
  14211. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  14212. first_iocbq->iocb.ulpContext = NO_XRI;
  14213. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  14214. be16_to_cpu(fc_hdr->fh_ox_id);
  14215. /* iocbq is prepped for internal consumption. Physical vpi. */
  14216. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  14217. vport->phba->vpi_ids[vport->vpi];
  14218. /* put the first buffer into the first IOCBq */
  14219. tot_len = bf_get(lpfc_rcqe_length,
  14220. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  14221. first_iocbq->context2 = &seq_dmabuf->dbuf;
  14222. first_iocbq->context3 = NULL;
  14223. first_iocbq->iocb.ulpBdeCount = 1;
  14224. if (tot_len > LPFC_DATA_BUF_SIZE)
  14225. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  14226. LPFC_DATA_BUF_SIZE;
  14227. else
  14228. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
  14229. first_iocbq->iocb.un.rcvels.remoteID = sid;
  14230. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  14231. }
  14232. iocbq = first_iocbq;
  14233. /*
  14234. * Each IOCBq can have two Buffers assigned, so go through the list
  14235. * of buffers for this sequence and save two buffers in each IOCBq
  14236. */
  14237. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  14238. if (!iocbq) {
  14239. lpfc_in_buf_free(vport->phba, d_buf);
  14240. continue;
  14241. }
  14242. if (!iocbq->context3) {
  14243. iocbq->context3 = d_buf;
  14244. iocbq->iocb.ulpBdeCount++;
  14245. /* We need to get the size out of the right CQE */
  14246. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  14247. len = bf_get(lpfc_rcqe_length,
  14248. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  14249. pbde = (struct ulp_bde64 *)
  14250. &iocbq->iocb.unsli3.sli3Words[4];
  14251. if (len > LPFC_DATA_BUF_SIZE)
  14252. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  14253. else
  14254. pbde->tus.f.bdeSize = len;
  14255. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  14256. tot_len += len;
  14257. } else {
  14258. iocbq = lpfc_sli_get_iocbq(vport->phba);
  14259. if (!iocbq) {
  14260. if (first_iocbq) {
  14261. first_iocbq->iocb.ulpStatus =
  14262. IOSTAT_FCP_RSP_ERROR;
  14263. first_iocbq->iocb.un.ulpWord[4] =
  14264. IOERR_NO_RESOURCES;
  14265. }
  14266. lpfc_in_buf_free(vport->phba, d_buf);
  14267. continue;
  14268. }
  14269. /* We need to get the size out of the right CQE */
  14270. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  14271. len = bf_get(lpfc_rcqe_length,
  14272. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  14273. iocbq->context2 = d_buf;
  14274. iocbq->context3 = NULL;
  14275. iocbq->iocb.ulpBdeCount = 1;
  14276. if (len > LPFC_DATA_BUF_SIZE)
  14277. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  14278. LPFC_DATA_BUF_SIZE;
  14279. else
  14280. iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
  14281. tot_len += len;
  14282. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  14283. iocbq->iocb.un.rcvels.remoteID = sid;
  14284. list_add_tail(&iocbq->list, &first_iocbq->list);
  14285. }
  14286. }
  14287. return first_iocbq;
  14288. }
  14289. static void
  14290. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  14291. struct hbq_dmabuf *seq_dmabuf)
  14292. {
  14293. struct fc_frame_header *fc_hdr;
  14294. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  14295. struct lpfc_hba *phba = vport->phba;
  14296. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14297. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  14298. if (!iocbq) {
  14299. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14300. "2707 Ring %d handler: Failed to allocate "
  14301. "iocb Rctl x%x Type x%x received\n",
  14302. LPFC_ELS_RING,
  14303. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  14304. return;
  14305. }
  14306. if (!lpfc_complete_unsol_iocb(phba,
  14307. &phba->sli.ring[LPFC_ELS_RING],
  14308. iocbq, fc_hdr->fh_r_ctl,
  14309. fc_hdr->fh_type))
  14310. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14311. "2540 Ring %d handler: unexpected Rctl "
  14312. "x%x Type x%x received\n",
  14313. LPFC_ELS_RING,
  14314. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  14315. /* Free iocb created in lpfc_prep_seq */
  14316. list_for_each_entry_safe(curr_iocb, next_iocb,
  14317. &iocbq->list, list) {
  14318. list_del_init(&curr_iocb->list);
  14319. lpfc_sli_release_iocbq(phba, curr_iocb);
  14320. }
  14321. lpfc_sli_release_iocbq(phba, iocbq);
  14322. }
  14323. /**
  14324. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  14325. * @phba: Pointer to HBA context object.
  14326. *
  14327. * This function is called with no lock held. This function processes all
  14328. * the received buffers and gives it to upper layers when a received buffer
  14329. * indicates that it is the final frame in the sequence. The interrupt
  14330. * service routine processes received buffers at interrupt contexts and adds
  14331. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  14332. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  14333. * appropriate receive function when the final frame in a sequence is received.
  14334. **/
  14335. void
  14336. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  14337. struct hbq_dmabuf *dmabuf)
  14338. {
  14339. struct hbq_dmabuf *seq_dmabuf;
  14340. struct fc_frame_header *fc_hdr;
  14341. struct lpfc_vport *vport;
  14342. uint32_t fcfi;
  14343. uint32_t did;
  14344. /* Process each received buffer */
  14345. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  14346. /* check to see if this a valid type of frame */
  14347. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  14348. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14349. return;
  14350. }
  14351. if ((bf_get(lpfc_cqe_code,
  14352. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  14353. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  14354. &dmabuf->cq_event.cqe.rcqe_cmpl);
  14355. else
  14356. fcfi = bf_get(lpfc_rcqe_fcf_id,
  14357. &dmabuf->cq_event.cqe.rcqe_cmpl);
  14358. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  14359. if (!vport) {
  14360. /* throw out the frame */
  14361. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14362. return;
  14363. }
  14364. /* d_id this frame is directed to */
  14365. did = sli4_did_from_fc_hdr(fc_hdr);
  14366. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  14367. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  14368. (did != Fabric_DID)) {
  14369. /*
  14370. * Throw out the frame if we are not pt2pt.
  14371. * The pt2pt protocol allows for discovery frames
  14372. * to be received without a registered VPI.
  14373. */
  14374. if (!(vport->fc_flag & FC_PT2PT) ||
  14375. (phba->link_state == LPFC_HBA_READY)) {
  14376. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14377. return;
  14378. }
  14379. }
  14380. /* Handle the basic abort sequence (BA_ABTS) event */
  14381. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  14382. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  14383. return;
  14384. }
  14385. /* Link this frame */
  14386. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  14387. if (!seq_dmabuf) {
  14388. /* unable to add frame to vport - throw it out */
  14389. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14390. return;
  14391. }
  14392. /* If not last frame in sequence continue processing frames. */
  14393. if (!lpfc_seq_complete(seq_dmabuf))
  14394. return;
  14395. /* Send the complete sequence to the upper layer protocol */
  14396. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  14397. }
  14398. /**
  14399. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  14400. * @phba: pointer to lpfc hba data structure.
  14401. *
  14402. * This routine is invoked to post rpi header templates to the
  14403. * HBA consistent with the SLI-4 interface spec. This routine
  14404. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  14405. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  14406. *
  14407. * This routine does not require any locks. It's usage is expected
  14408. * to be driver load or reset recovery when the driver is
  14409. * sequential.
  14410. *
  14411. * Return codes
  14412. * 0 - successful
  14413. * -EIO - The mailbox failed to complete successfully.
  14414. * When this error occurs, the driver is not guaranteed
  14415. * to have any rpi regions posted to the device and
  14416. * must either attempt to repost the regions or take a
  14417. * fatal error.
  14418. **/
  14419. int
  14420. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  14421. {
  14422. struct lpfc_rpi_hdr *rpi_page;
  14423. uint32_t rc = 0;
  14424. uint16_t lrpi = 0;
  14425. /* SLI4 ports that support extents do not require RPI headers. */
  14426. if (!phba->sli4_hba.rpi_hdrs_in_use)
  14427. goto exit;
  14428. if (phba->sli4_hba.extents_in_use)
  14429. return -EIO;
  14430. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  14431. /*
  14432. * Assign the rpi headers a physical rpi only if the driver
  14433. * has not initialized those resources. A port reset only
  14434. * needs the headers posted.
  14435. */
  14436. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  14437. LPFC_RPI_RSRC_RDY)
  14438. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  14439. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  14440. if (rc != MBX_SUCCESS) {
  14441. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14442. "2008 Error %d posting all rpi "
  14443. "headers\n", rc);
  14444. rc = -EIO;
  14445. break;
  14446. }
  14447. }
  14448. exit:
  14449. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  14450. LPFC_RPI_RSRC_RDY);
  14451. return rc;
  14452. }
  14453. /**
  14454. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  14455. * @phba: pointer to lpfc hba data structure.
  14456. * @rpi_page: pointer to the rpi memory region.
  14457. *
  14458. * This routine is invoked to post a single rpi header to the
  14459. * HBA consistent with the SLI-4 interface spec. This memory region
  14460. * maps up to 64 rpi context regions.
  14461. *
  14462. * Return codes
  14463. * 0 - successful
  14464. * -ENOMEM - No available memory
  14465. * -EIO - The mailbox failed to complete successfully.
  14466. **/
  14467. int
  14468. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  14469. {
  14470. LPFC_MBOXQ_t *mboxq;
  14471. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  14472. uint32_t rc = 0;
  14473. uint32_t shdr_status, shdr_add_status;
  14474. union lpfc_sli4_cfg_shdr *shdr;
  14475. /* SLI4 ports that support extents do not require RPI headers. */
  14476. if (!phba->sli4_hba.rpi_hdrs_in_use)
  14477. return rc;
  14478. if (phba->sli4_hba.extents_in_use)
  14479. return -EIO;
  14480. /* The port is notified of the header region via a mailbox command. */
  14481. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14482. if (!mboxq) {
  14483. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14484. "2001 Unable to allocate memory for issuing "
  14485. "SLI_CONFIG_SPECIAL mailbox command\n");
  14486. return -ENOMEM;
  14487. }
  14488. /* Post all rpi memory regions to the port. */
  14489. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  14490. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  14491. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  14492. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  14493. sizeof(struct lpfc_sli4_cfg_mhdr),
  14494. LPFC_SLI4_MBX_EMBED);
  14495. /* Post the physical rpi to the port for this rpi header. */
  14496. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  14497. rpi_page->start_rpi);
  14498. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  14499. hdr_tmpl, rpi_page->page_count);
  14500. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  14501. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  14502. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14503. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  14504. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14505. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14506. if (rc != MBX_TIMEOUT)
  14507. mempool_free(mboxq, phba->mbox_mem_pool);
  14508. if (shdr_status || shdr_add_status || rc) {
  14509. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14510. "2514 POST_RPI_HDR mailbox failed with "
  14511. "status x%x add_status x%x, mbx status x%x\n",
  14512. shdr_status, shdr_add_status, rc);
  14513. rc = -ENXIO;
  14514. }
  14515. return rc;
  14516. }
  14517. /**
  14518. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  14519. * @phba: pointer to lpfc hba data structure.
  14520. *
  14521. * This routine is invoked to post rpi header templates to the
  14522. * HBA consistent with the SLI-4 interface spec. This routine
  14523. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  14524. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  14525. *
  14526. * Returns
  14527. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  14528. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  14529. **/
  14530. int
  14531. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  14532. {
  14533. unsigned long rpi;
  14534. uint16_t max_rpi, rpi_limit;
  14535. uint16_t rpi_remaining, lrpi = 0;
  14536. struct lpfc_rpi_hdr *rpi_hdr;
  14537. unsigned long iflag;
  14538. /*
  14539. * Fetch the next logical rpi. Because this index is logical,
  14540. * the driver starts at 0 each time.
  14541. */
  14542. spin_lock_irqsave(&phba->hbalock, iflag);
  14543. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  14544. rpi_limit = phba->sli4_hba.next_rpi;
  14545. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  14546. if (rpi >= rpi_limit)
  14547. rpi = LPFC_RPI_ALLOC_ERROR;
  14548. else {
  14549. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  14550. phba->sli4_hba.max_cfg_param.rpi_used++;
  14551. phba->sli4_hba.rpi_count++;
  14552. }
  14553. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  14554. "0001 rpi:%x max:%x lim:%x\n",
  14555. (int) rpi, max_rpi, rpi_limit);
  14556. /*
  14557. * Don't try to allocate more rpi header regions if the device limit
  14558. * has been exhausted.
  14559. */
  14560. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  14561. (phba->sli4_hba.rpi_count >= max_rpi)) {
  14562. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14563. return rpi;
  14564. }
  14565. /*
  14566. * RPI header postings are not required for SLI4 ports capable of
  14567. * extents.
  14568. */
  14569. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  14570. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14571. return rpi;
  14572. }
  14573. /*
  14574. * If the driver is running low on rpi resources, allocate another
  14575. * page now. Note that the next_rpi value is used because
  14576. * it represents how many are actually in use whereas max_rpi notes
  14577. * how many are supported max by the device.
  14578. */
  14579. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  14580. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14581. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  14582. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  14583. if (!rpi_hdr) {
  14584. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14585. "2002 Error Could not grow rpi "
  14586. "count\n");
  14587. } else {
  14588. lrpi = rpi_hdr->start_rpi;
  14589. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  14590. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  14591. }
  14592. }
  14593. return rpi;
  14594. }
  14595. /**
  14596. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  14597. * @phba: pointer to lpfc hba data structure.
  14598. *
  14599. * This routine is invoked to release an rpi to the pool of
  14600. * available rpis maintained by the driver.
  14601. **/
  14602. static void
  14603. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  14604. {
  14605. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  14606. phba->sli4_hba.rpi_count--;
  14607. phba->sli4_hba.max_cfg_param.rpi_used--;
  14608. }
  14609. }
  14610. /**
  14611. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  14612. * @phba: pointer to lpfc hba data structure.
  14613. *
  14614. * This routine is invoked to release an rpi to the pool of
  14615. * available rpis maintained by the driver.
  14616. **/
  14617. void
  14618. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  14619. {
  14620. spin_lock_irq(&phba->hbalock);
  14621. __lpfc_sli4_free_rpi(phba, rpi);
  14622. spin_unlock_irq(&phba->hbalock);
  14623. }
  14624. /**
  14625. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  14626. * @phba: pointer to lpfc hba data structure.
  14627. *
  14628. * This routine is invoked to remove the memory region that
  14629. * provided rpi via a bitmask.
  14630. **/
  14631. void
  14632. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  14633. {
  14634. kfree(phba->sli4_hba.rpi_bmask);
  14635. kfree(phba->sli4_hba.rpi_ids);
  14636. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  14637. }
  14638. /**
  14639. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  14640. * @phba: pointer to lpfc hba data structure.
  14641. *
  14642. * This routine is invoked to remove the memory region that
  14643. * provided rpi via a bitmask.
  14644. **/
  14645. int
  14646. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  14647. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  14648. {
  14649. LPFC_MBOXQ_t *mboxq;
  14650. struct lpfc_hba *phba = ndlp->phba;
  14651. int rc;
  14652. /* The port is notified of the header region via a mailbox command. */
  14653. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14654. if (!mboxq)
  14655. return -ENOMEM;
  14656. /* Post all rpi memory regions to the port. */
  14657. lpfc_resume_rpi(mboxq, ndlp);
  14658. if (cmpl) {
  14659. mboxq->mbox_cmpl = cmpl;
  14660. mboxq->context1 = arg;
  14661. mboxq->context2 = ndlp;
  14662. } else
  14663. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14664. mboxq->vport = ndlp->vport;
  14665. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14666. if (rc == MBX_NOT_FINISHED) {
  14667. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14668. "2010 Resume RPI Mailbox failed "
  14669. "status %d, mbxStatus x%x\n", rc,
  14670. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  14671. mempool_free(mboxq, phba->mbox_mem_pool);
  14672. return -EIO;
  14673. }
  14674. return 0;
  14675. }
  14676. /**
  14677. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  14678. * @vport: Pointer to the vport for which the vpi is being initialized
  14679. *
  14680. * This routine is invoked to activate a vpi with the port.
  14681. *
  14682. * Returns:
  14683. * 0 success
  14684. * -Evalue otherwise
  14685. **/
  14686. int
  14687. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  14688. {
  14689. LPFC_MBOXQ_t *mboxq;
  14690. int rc = 0;
  14691. int retval = MBX_SUCCESS;
  14692. uint32_t mbox_tmo;
  14693. struct lpfc_hba *phba = vport->phba;
  14694. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14695. if (!mboxq)
  14696. return -ENOMEM;
  14697. lpfc_init_vpi(phba, mboxq, vport->vpi);
  14698. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  14699. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  14700. if (rc != MBX_SUCCESS) {
  14701. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  14702. "2022 INIT VPI Mailbox failed "
  14703. "status %d, mbxStatus x%x\n", rc,
  14704. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  14705. retval = -EIO;
  14706. }
  14707. if (rc != MBX_TIMEOUT)
  14708. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  14709. return retval;
  14710. }
  14711. /**
  14712. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  14713. * @phba: pointer to lpfc hba data structure.
  14714. * @mboxq: Pointer to mailbox object.
  14715. *
  14716. * This routine is invoked to manually add a single FCF record. The caller
  14717. * must pass a completely initialized FCF_Record. This routine takes
  14718. * care of the nonembedded mailbox operations.
  14719. **/
  14720. static void
  14721. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  14722. {
  14723. void *virt_addr;
  14724. union lpfc_sli4_cfg_shdr *shdr;
  14725. uint32_t shdr_status, shdr_add_status;
  14726. virt_addr = mboxq->sge_array->addr[0];
  14727. /* The IOCTL status is embedded in the mailbox subheader. */
  14728. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  14729. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14730. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14731. if ((shdr_status || shdr_add_status) &&
  14732. (shdr_status != STATUS_FCF_IN_USE))
  14733. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14734. "2558 ADD_FCF_RECORD mailbox failed with "
  14735. "status x%x add_status x%x\n",
  14736. shdr_status, shdr_add_status);
  14737. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14738. }
  14739. /**
  14740. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  14741. * @phba: pointer to lpfc hba data structure.
  14742. * @fcf_record: pointer to the initialized fcf record to add.
  14743. *
  14744. * This routine is invoked to manually add a single FCF record. The caller
  14745. * must pass a completely initialized FCF_Record. This routine takes
  14746. * care of the nonembedded mailbox operations.
  14747. **/
  14748. int
  14749. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  14750. {
  14751. int rc = 0;
  14752. LPFC_MBOXQ_t *mboxq;
  14753. uint8_t *bytep;
  14754. void *virt_addr;
  14755. struct lpfc_mbx_sge sge;
  14756. uint32_t alloc_len, req_len;
  14757. uint32_t fcfindex;
  14758. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14759. if (!mboxq) {
  14760. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14761. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  14762. return -ENOMEM;
  14763. }
  14764. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  14765. sizeof(uint32_t);
  14766. /* Allocate DMA memory and set up the non-embedded mailbox command */
  14767. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  14768. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  14769. req_len, LPFC_SLI4_MBX_NEMBED);
  14770. if (alloc_len < req_len) {
  14771. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14772. "2523 Allocated DMA memory size (x%x) is "
  14773. "less than the requested DMA memory "
  14774. "size (x%x)\n", alloc_len, req_len);
  14775. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14776. return -ENOMEM;
  14777. }
  14778. /*
  14779. * Get the first SGE entry from the non-embedded DMA memory. This
  14780. * routine only uses a single SGE.
  14781. */
  14782. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  14783. virt_addr = mboxq->sge_array->addr[0];
  14784. /*
  14785. * Configure the FCF record for FCFI 0. This is the driver's
  14786. * hardcoded default and gets used in nonFIP mode.
  14787. */
  14788. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  14789. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  14790. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  14791. /*
  14792. * Copy the fcf_index and the FCF Record Data. The data starts after
  14793. * the FCoE header plus word10. The data copy needs to be endian
  14794. * correct.
  14795. */
  14796. bytep += sizeof(uint32_t);
  14797. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  14798. mboxq->vport = phba->pport;
  14799. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  14800. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14801. if (rc == MBX_NOT_FINISHED) {
  14802. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14803. "2515 ADD_FCF_RECORD mailbox failed with "
  14804. "status 0x%x\n", rc);
  14805. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14806. rc = -EIO;
  14807. } else
  14808. rc = 0;
  14809. return rc;
  14810. }
  14811. /**
  14812. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  14813. * @phba: pointer to lpfc hba data structure.
  14814. * @fcf_record: pointer to the fcf record to write the default data.
  14815. * @fcf_index: FCF table entry index.
  14816. *
  14817. * This routine is invoked to build the driver's default FCF record. The
  14818. * values used are hardcoded. This routine handles memory initialization.
  14819. *
  14820. **/
  14821. void
  14822. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  14823. struct fcf_record *fcf_record,
  14824. uint16_t fcf_index)
  14825. {
  14826. memset(fcf_record, 0, sizeof(struct fcf_record));
  14827. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  14828. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  14829. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  14830. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  14831. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  14832. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  14833. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  14834. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  14835. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  14836. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  14837. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  14838. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  14839. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  14840. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  14841. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  14842. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  14843. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  14844. /* Set the VLAN bit map */
  14845. if (phba->valid_vlan) {
  14846. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  14847. = 1 << (phba->vlan_id % 8);
  14848. }
  14849. }
  14850. /**
  14851. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  14852. * @phba: pointer to lpfc hba data structure.
  14853. * @fcf_index: FCF table entry offset.
  14854. *
  14855. * This routine is invoked to scan the entire FCF table by reading FCF
  14856. * record and processing it one at a time starting from the @fcf_index
  14857. * for initial FCF discovery or fast FCF failover rediscovery.
  14858. *
  14859. * Return 0 if the mailbox command is submitted successfully, none 0
  14860. * otherwise.
  14861. **/
  14862. int
  14863. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14864. {
  14865. int rc = 0, error;
  14866. LPFC_MBOXQ_t *mboxq;
  14867. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  14868. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  14869. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14870. if (!mboxq) {
  14871. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14872. "2000 Failed to allocate mbox for "
  14873. "READ_FCF cmd\n");
  14874. error = -ENOMEM;
  14875. goto fail_fcf_scan;
  14876. }
  14877. /* Construct the read FCF record mailbox command */
  14878. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14879. if (rc) {
  14880. error = -EINVAL;
  14881. goto fail_fcf_scan;
  14882. }
  14883. /* Issue the mailbox command asynchronously */
  14884. mboxq->vport = phba->pport;
  14885. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  14886. spin_lock_irq(&phba->hbalock);
  14887. phba->hba_flag |= FCF_TS_INPROG;
  14888. spin_unlock_irq(&phba->hbalock);
  14889. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14890. if (rc == MBX_NOT_FINISHED)
  14891. error = -EIO;
  14892. else {
  14893. /* Reset eligible FCF count for new scan */
  14894. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  14895. phba->fcf.eligible_fcf_cnt = 0;
  14896. error = 0;
  14897. }
  14898. fail_fcf_scan:
  14899. if (error) {
  14900. if (mboxq)
  14901. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14902. /* FCF scan failed, clear FCF_TS_INPROG flag */
  14903. spin_lock_irq(&phba->hbalock);
  14904. phba->hba_flag &= ~FCF_TS_INPROG;
  14905. spin_unlock_irq(&phba->hbalock);
  14906. }
  14907. return error;
  14908. }
  14909. /**
  14910. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  14911. * @phba: pointer to lpfc hba data structure.
  14912. * @fcf_index: FCF table entry offset.
  14913. *
  14914. * This routine is invoked to read an FCF record indicated by @fcf_index
  14915. * and to use it for FLOGI roundrobin FCF failover.
  14916. *
  14917. * Return 0 if the mailbox command is submitted successfully, none 0
  14918. * otherwise.
  14919. **/
  14920. int
  14921. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14922. {
  14923. int rc = 0, error;
  14924. LPFC_MBOXQ_t *mboxq;
  14925. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14926. if (!mboxq) {
  14927. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14928. "2763 Failed to allocate mbox for "
  14929. "READ_FCF cmd\n");
  14930. error = -ENOMEM;
  14931. goto fail_fcf_read;
  14932. }
  14933. /* Construct the read FCF record mailbox command */
  14934. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14935. if (rc) {
  14936. error = -EINVAL;
  14937. goto fail_fcf_read;
  14938. }
  14939. /* Issue the mailbox command asynchronously */
  14940. mboxq->vport = phba->pport;
  14941. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  14942. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14943. if (rc == MBX_NOT_FINISHED)
  14944. error = -EIO;
  14945. else
  14946. error = 0;
  14947. fail_fcf_read:
  14948. if (error && mboxq)
  14949. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14950. return error;
  14951. }
  14952. /**
  14953. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  14954. * @phba: pointer to lpfc hba data structure.
  14955. * @fcf_index: FCF table entry offset.
  14956. *
  14957. * This routine is invoked to read an FCF record indicated by @fcf_index to
  14958. * determine whether it's eligible for FLOGI roundrobin failover list.
  14959. *
  14960. * Return 0 if the mailbox command is submitted successfully, none 0
  14961. * otherwise.
  14962. **/
  14963. int
  14964. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14965. {
  14966. int rc = 0, error;
  14967. LPFC_MBOXQ_t *mboxq;
  14968. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14969. if (!mboxq) {
  14970. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14971. "2758 Failed to allocate mbox for "
  14972. "READ_FCF cmd\n");
  14973. error = -ENOMEM;
  14974. goto fail_fcf_read;
  14975. }
  14976. /* Construct the read FCF record mailbox command */
  14977. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14978. if (rc) {
  14979. error = -EINVAL;
  14980. goto fail_fcf_read;
  14981. }
  14982. /* Issue the mailbox command asynchronously */
  14983. mboxq->vport = phba->pport;
  14984. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  14985. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14986. if (rc == MBX_NOT_FINISHED)
  14987. error = -EIO;
  14988. else
  14989. error = 0;
  14990. fail_fcf_read:
  14991. if (error && mboxq)
  14992. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14993. return error;
  14994. }
  14995. /**
  14996. * lpfc_check_next_fcf_pri_level
  14997. * phba pointer to the lpfc_hba struct for this port.
  14998. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  14999. * routine when the rr_bmask is empty. The FCF indecies are put into the
  15000. * rr_bmask based on their priority level. Starting from the highest priority
  15001. * to the lowest. The most likely FCF candidate will be in the highest
  15002. * priority group. When this routine is called it searches the fcf_pri list for
  15003. * next lowest priority group and repopulates the rr_bmask with only those
  15004. * fcf_indexes.
  15005. * returns:
  15006. * 1=success 0=failure
  15007. **/
  15008. static int
  15009. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  15010. {
  15011. uint16_t next_fcf_pri;
  15012. uint16_t last_index;
  15013. struct lpfc_fcf_pri *fcf_pri;
  15014. int rc;
  15015. int ret = 0;
  15016. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  15017. LPFC_SLI4_FCF_TBL_INDX_MAX);
  15018. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15019. "3060 Last IDX %d\n", last_index);
  15020. /* Verify the priority list has 2 or more entries */
  15021. spin_lock_irq(&phba->hbalock);
  15022. if (list_empty(&phba->fcf.fcf_pri_list) ||
  15023. list_is_singular(&phba->fcf.fcf_pri_list)) {
  15024. spin_unlock_irq(&phba->hbalock);
  15025. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15026. "3061 Last IDX %d\n", last_index);
  15027. return 0; /* Empty rr list */
  15028. }
  15029. spin_unlock_irq(&phba->hbalock);
  15030. next_fcf_pri = 0;
  15031. /*
  15032. * Clear the rr_bmask and set all of the bits that are at this
  15033. * priority.
  15034. */
  15035. memset(phba->fcf.fcf_rr_bmask, 0,
  15036. sizeof(*phba->fcf.fcf_rr_bmask));
  15037. spin_lock_irq(&phba->hbalock);
  15038. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  15039. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  15040. continue;
  15041. /*
  15042. * the 1st priority that has not FLOGI failed
  15043. * will be the highest.
  15044. */
  15045. if (!next_fcf_pri)
  15046. next_fcf_pri = fcf_pri->fcf_rec.priority;
  15047. spin_unlock_irq(&phba->hbalock);
  15048. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  15049. rc = lpfc_sli4_fcf_rr_index_set(phba,
  15050. fcf_pri->fcf_rec.fcf_index);
  15051. if (rc)
  15052. return 0;
  15053. }
  15054. spin_lock_irq(&phba->hbalock);
  15055. }
  15056. /*
  15057. * if next_fcf_pri was not set above and the list is not empty then
  15058. * we have failed flogis on all of them. So reset flogi failed
  15059. * and start at the beginning.
  15060. */
  15061. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  15062. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  15063. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  15064. /*
  15065. * the 1st priority that has not FLOGI failed
  15066. * will be the highest.
  15067. */
  15068. if (!next_fcf_pri)
  15069. next_fcf_pri = fcf_pri->fcf_rec.priority;
  15070. spin_unlock_irq(&phba->hbalock);
  15071. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  15072. rc = lpfc_sli4_fcf_rr_index_set(phba,
  15073. fcf_pri->fcf_rec.fcf_index);
  15074. if (rc)
  15075. return 0;
  15076. }
  15077. spin_lock_irq(&phba->hbalock);
  15078. }
  15079. } else
  15080. ret = 1;
  15081. spin_unlock_irq(&phba->hbalock);
  15082. return ret;
  15083. }
  15084. /**
  15085. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  15086. * @phba: pointer to lpfc hba data structure.
  15087. *
  15088. * This routine is to get the next eligible FCF record index in a round
  15089. * robin fashion. If the next eligible FCF record index equals to the
  15090. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  15091. * shall be returned, otherwise, the next eligible FCF record's index
  15092. * shall be returned.
  15093. **/
  15094. uint16_t
  15095. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  15096. {
  15097. uint16_t next_fcf_index;
  15098. initial_priority:
  15099. /* Search start from next bit of currently registered FCF index */
  15100. next_fcf_index = phba->fcf.current_rec.fcf_indx;
  15101. next_priority:
  15102. /* Determine the next fcf index to check */
  15103. next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
  15104. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  15105. LPFC_SLI4_FCF_TBL_INDX_MAX,
  15106. next_fcf_index);
  15107. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  15108. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  15109. /*
  15110. * If we have wrapped then we need to clear the bits that
  15111. * have been tested so that we can detect when we should
  15112. * change the priority level.
  15113. */
  15114. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  15115. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  15116. }
  15117. /* Check roundrobin failover list empty condition */
  15118. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  15119. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  15120. /*
  15121. * If next fcf index is not found check if there are lower
  15122. * Priority level fcf's in the fcf_priority list.
  15123. * Set up the rr_bmask with all of the avaiable fcf bits
  15124. * at that level and continue the selection process.
  15125. */
  15126. if (lpfc_check_next_fcf_pri_level(phba))
  15127. goto initial_priority;
  15128. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  15129. "2844 No roundrobin failover FCF available\n");
  15130. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  15131. return LPFC_FCOE_FCF_NEXT_NONE;
  15132. else {
  15133. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  15134. "3063 Only FCF available idx %d, flag %x\n",
  15135. next_fcf_index,
  15136. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  15137. return next_fcf_index;
  15138. }
  15139. }
  15140. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  15141. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  15142. LPFC_FCF_FLOGI_FAILED) {
  15143. if (list_is_singular(&phba->fcf.fcf_pri_list))
  15144. return LPFC_FCOE_FCF_NEXT_NONE;
  15145. goto next_priority;
  15146. }
  15147. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15148. "2845 Get next roundrobin failover FCF (x%x)\n",
  15149. next_fcf_index);
  15150. return next_fcf_index;
  15151. }
  15152. /**
  15153. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  15154. * @phba: pointer to lpfc hba data structure.
  15155. *
  15156. * This routine sets the FCF record index in to the eligible bmask for
  15157. * roundrobin failover search. It checks to make sure that the index
  15158. * does not go beyond the range of the driver allocated bmask dimension
  15159. * before setting the bit.
  15160. *
  15161. * Returns 0 if the index bit successfully set, otherwise, it returns
  15162. * -EINVAL.
  15163. **/
  15164. int
  15165. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  15166. {
  15167. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  15168. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15169. "2610 FCF (x%x) reached driver's book "
  15170. "keeping dimension:x%x\n",
  15171. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  15172. return -EINVAL;
  15173. }
  15174. /* Set the eligible FCF record index bmask */
  15175. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  15176. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15177. "2790 Set FCF (x%x) to roundrobin FCF failover "
  15178. "bmask\n", fcf_index);
  15179. return 0;
  15180. }
  15181. /**
  15182. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  15183. * @phba: pointer to lpfc hba data structure.
  15184. *
  15185. * This routine clears the FCF record index from the eligible bmask for
  15186. * roundrobin failover search. It checks to make sure that the index
  15187. * does not go beyond the range of the driver allocated bmask dimension
  15188. * before clearing the bit.
  15189. **/
  15190. void
  15191. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  15192. {
  15193. struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
  15194. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  15195. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15196. "2762 FCF (x%x) reached driver's book "
  15197. "keeping dimension:x%x\n",
  15198. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  15199. return;
  15200. }
  15201. /* Clear the eligible FCF record index bmask */
  15202. spin_lock_irq(&phba->hbalock);
  15203. list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
  15204. list) {
  15205. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  15206. list_del_init(&fcf_pri->list);
  15207. break;
  15208. }
  15209. }
  15210. spin_unlock_irq(&phba->hbalock);
  15211. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  15212. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15213. "2791 Clear FCF (x%x) from roundrobin failover "
  15214. "bmask\n", fcf_index);
  15215. }
  15216. /**
  15217. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  15218. * @phba: pointer to lpfc hba data structure.
  15219. *
  15220. * This routine is the completion routine for the rediscover FCF table mailbox
  15221. * command. If the mailbox command returned failure, it will try to stop the
  15222. * FCF rediscover wait timer.
  15223. **/
  15224. static void
  15225. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  15226. {
  15227. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  15228. uint32_t shdr_status, shdr_add_status;
  15229. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  15230. shdr_status = bf_get(lpfc_mbox_hdr_status,
  15231. &redisc_fcf->header.cfg_shdr.response);
  15232. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  15233. &redisc_fcf->header.cfg_shdr.response);
  15234. if (shdr_status || shdr_add_status) {
  15235. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15236. "2746 Requesting for FCF rediscovery failed "
  15237. "status x%x add_status x%x\n",
  15238. shdr_status, shdr_add_status);
  15239. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  15240. spin_lock_irq(&phba->hbalock);
  15241. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  15242. spin_unlock_irq(&phba->hbalock);
  15243. /*
  15244. * CVL event triggered FCF rediscover request failed,
  15245. * last resort to re-try current registered FCF entry.
  15246. */
  15247. lpfc_retry_pport_discovery(phba);
  15248. } else {
  15249. spin_lock_irq(&phba->hbalock);
  15250. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  15251. spin_unlock_irq(&phba->hbalock);
  15252. /*
  15253. * DEAD FCF event triggered FCF rediscover request
  15254. * failed, last resort to fail over as a link down
  15255. * to FCF registration.
  15256. */
  15257. lpfc_sli4_fcf_dead_failthrough(phba);
  15258. }
  15259. } else {
  15260. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15261. "2775 Start FCF rediscover quiescent timer\n");
  15262. /*
  15263. * Start FCF rediscovery wait timer for pending FCF
  15264. * before rescan FCF record table.
  15265. */
  15266. lpfc_fcf_redisc_wait_start_timer(phba);
  15267. }
  15268. mempool_free(mbox, phba->mbox_mem_pool);
  15269. }
  15270. /**
  15271. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  15272. * @phba: pointer to lpfc hba data structure.
  15273. *
  15274. * This routine is invoked to request for rediscovery of the entire FCF table
  15275. * by the port.
  15276. **/
  15277. int
  15278. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  15279. {
  15280. LPFC_MBOXQ_t *mbox;
  15281. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  15282. int rc, length;
  15283. /* Cancel retry delay timers to all vports before FCF rediscover */
  15284. lpfc_cancel_all_vport_retry_delay_timer(phba);
  15285. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15286. if (!mbox) {
  15287. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15288. "2745 Failed to allocate mbox for "
  15289. "requesting FCF rediscover.\n");
  15290. return -ENOMEM;
  15291. }
  15292. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  15293. sizeof(struct lpfc_sli4_cfg_mhdr));
  15294. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  15295. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  15296. length, LPFC_SLI4_MBX_EMBED);
  15297. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  15298. /* Set count to 0 for invalidating the entire FCF database */
  15299. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  15300. /* Issue the mailbox command asynchronously */
  15301. mbox->vport = phba->pport;
  15302. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  15303. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  15304. if (rc == MBX_NOT_FINISHED) {
  15305. mempool_free(mbox, phba->mbox_mem_pool);
  15306. return -EIO;
  15307. }
  15308. return 0;
  15309. }
  15310. /**
  15311. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  15312. * @phba: pointer to lpfc hba data structure.
  15313. *
  15314. * This function is the failover routine as a last resort to the FCF DEAD
  15315. * event when driver failed to perform fast FCF failover.
  15316. **/
  15317. void
  15318. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  15319. {
  15320. uint32_t link_state;
  15321. /*
  15322. * Last resort as FCF DEAD event failover will treat this as
  15323. * a link down, but save the link state because we don't want
  15324. * it to be changed to Link Down unless it is already down.
  15325. */
  15326. link_state = phba->link_state;
  15327. lpfc_linkdown(phba);
  15328. phba->link_state = link_state;
  15329. /* Unregister FCF if no devices connected to it */
  15330. lpfc_unregister_unused_fcf(phba);
  15331. }
  15332. /**
  15333. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  15334. * @phba: pointer to lpfc hba data structure.
  15335. * @rgn23_data: pointer to configure region 23 data.
  15336. *
  15337. * This function gets SLI3 port configure region 23 data through memory dump
  15338. * mailbox command. When it successfully retrieves data, the size of the data
  15339. * will be returned, otherwise, 0 will be returned.
  15340. **/
  15341. static uint32_t
  15342. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  15343. {
  15344. LPFC_MBOXQ_t *pmb = NULL;
  15345. MAILBOX_t *mb;
  15346. uint32_t offset = 0;
  15347. int rc;
  15348. if (!rgn23_data)
  15349. return 0;
  15350. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15351. if (!pmb) {
  15352. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15353. "2600 failed to allocate mailbox memory\n");
  15354. return 0;
  15355. }
  15356. mb = &pmb->u.mb;
  15357. do {
  15358. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  15359. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  15360. if (rc != MBX_SUCCESS) {
  15361. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  15362. "2601 failed to read config "
  15363. "region 23, rc 0x%x Status 0x%x\n",
  15364. rc, mb->mbxStatus);
  15365. mb->un.varDmp.word_cnt = 0;
  15366. }
  15367. /*
  15368. * dump mem may return a zero when finished or we got a
  15369. * mailbox error, either way we are done.
  15370. */
  15371. if (mb->un.varDmp.word_cnt == 0)
  15372. break;
  15373. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  15374. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  15375. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  15376. rgn23_data + offset,
  15377. mb->un.varDmp.word_cnt);
  15378. offset += mb->un.varDmp.word_cnt;
  15379. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  15380. mempool_free(pmb, phba->mbox_mem_pool);
  15381. return offset;
  15382. }
  15383. /**
  15384. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  15385. * @phba: pointer to lpfc hba data structure.
  15386. * @rgn23_data: pointer to configure region 23 data.
  15387. *
  15388. * This function gets SLI4 port configure region 23 data through memory dump
  15389. * mailbox command. When it successfully retrieves data, the size of the data
  15390. * will be returned, otherwise, 0 will be returned.
  15391. **/
  15392. static uint32_t
  15393. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  15394. {
  15395. LPFC_MBOXQ_t *mboxq = NULL;
  15396. struct lpfc_dmabuf *mp = NULL;
  15397. struct lpfc_mqe *mqe;
  15398. uint32_t data_length = 0;
  15399. int rc;
  15400. if (!rgn23_data)
  15401. return 0;
  15402. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15403. if (!mboxq) {
  15404. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15405. "3105 failed to allocate mailbox memory\n");
  15406. return 0;
  15407. }
  15408. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  15409. goto out;
  15410. mqe = &mboxq->u.mqe;
  15411. mp = (struct lpfc_dmabuf *) mboxq->context1;
  15412. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  15413. if (rc)
  15414. goto out;
  15415. data_length = mqe->un.mb_words[5];
  15416. if (data_length == 0)
  15417. goto out;
  15418. if (data_length > DMP_RGN23_SIZE) {
  15419. data_length = 0;
  15420. goto out;
  15421. }
  15422. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  15423. out:
  15424. mempool_free(mboxq, phba->mbox_mem_pool);
  15425. if (mp) {
  15426. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  15427. kfree(mp);
  15428. }
  15429. return data_length;
  15430. }
  15431. /**
  15432. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  15433. * @phba: pointer to lpfc hba data structure.
  15434. *
  15435. * This function read region 23 and parse TLV for port status to
  15436. * decide if the user disaled the port. If the TLV indicates the
  15437. * port is disabled, the hba_flag is set accordingly.
  15438. **/
  15439. void
  15440. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  15441. {
  15442. uint8_t *rgn23_data = NULL;
  15443. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  15444. uint32_t offset = 0;
  15445. /* Get adapter Region 23 data */
  15446. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  15447. if (!rgn23_data)
  15448. goto out;
  15449. if (phba->sli_rev < LPFC_SLI_REV4)
  15450. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  15451. else {
  15452. if_type = bf_get(lpfc_sli_intf_if_type,
  15453. &phba->sli4_hba.sli_intf);
  15454. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  15455. goto out;
  15456. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  15457. }
  15458. if (!data_size)
  15459. goto out;
  15460. /* Check the region signature first */
  15461. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  15462. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15463. "2619 Config region 23 has bad signature\n");
  15464. goto out;
  15465. }
  15466. offset += 4;
  15467. /* Check the data structure version */
  15468. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  15469. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15470. "2620 Config region 23 has bad version\n");
  15471. goto out;
  15472. }
  15473. offset += 4;
  15474. /* Parse TLV entries in the region */
  15475. while (offset < data_size) {
  15476. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  15477. break;
  15478. /*
  15479. * If the TLV is not driver specific TLV or driver id is
  15480. * not linux driver id, skip the record.
  15481. */
  15482. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  15483. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  15484. (rgn23_data[offset + 3] != 0)) {
  15485. offset += rgn23_data[offset + 1] * 4 + 4;
  15486. continue;
  15487. }
  15488. /* Driver found a driver specific TLV in the config region */
  15489. sub_tlv_len = rgn23_data[offset + 1] * 4;
  15490. offset += 4;
  15491. tlv_offset = 0;
  15492. /*
  15493. * Search for configured port state sub-TLV.
  15494. */
  15495. while ((offset < data_size) &&
  15496. (tlv_offset < sub_tlv_len)) {
  15497. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  15498. offset += 4;
  15499. tlv_offset += 4;
  15500. break;
  15501. }
  15502. if (rgn23_data[offset] != PORT_STE_TYPE) {
  15503. offset += rgn23_data[offset + 1] * 4 + 4;
  15504. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  15505. continue;
  15506. }
  15507. /* This HBA contains PORT_STE configured */
  15508. if (!rgn23_data[offset + 2])
  15509. phba->hba_flag |= LINK_DISABLED;
  15510. goto out;
  15511. }
  15512. }
  15513. out:
  15514. kfree(rgn23_data);
  15515. return;
  15516. }
  15517. /**
  15518. * lpfc_wr_object - write an object to the firmware
  15519. * @phba: HBA structure that indicates port to create a queue on.
  15520. * @dmabuf_list: list of dmabufs to write to the port.
  15521. * @size: the total byte value of the objects to write to the port.
  15522. * @offset: the current offset to be used to start the transfer.
  15523. *
  15524. * This routine will create a wr_object mailbox command to send to the port.
  15525. * the mailbox command will be constructed using the dma buffers described in
  15526. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  15527. * BDEs that the imbedded mailbox can support. The @offset variable will be
  15528. * used to indicate the starting offset of the transfer and will also return
  15529. * the offset after the write object mailbox has completed. @size is used to
  15530. * determine the end of the object and whether the eof bit should be set.
  15531. *
  15532. * Return 0 is successful and offset will contain the the new offset to use
  15533. * for the next write.
  15534. * Return negative value for error cases.
  15535. **/
  15536. int
  15537. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  15538. uint32_t size, uint32_t *offset)
  15539. {
  15540. struct lpfc_mbx_wr_object *wr_object;
  15541. LPFC_MBOXQ_t *mbox;
  15542. int rc = 0, i = 0;
  15543. uint32_t shdr_status, shdr_add_status;
  15544. uint32_t mbox_tmo;
  15545. union lpfc_sli4_cfg_shdr *shdr;
  15546. struct lpfc_dmabuf *dmabuf;
  15547. uint32_t written = 0;
  15548. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15549. if (!mbox)
  15550. return -ENOMEM;
  15551. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  15552. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  15553. sizeof(struct lpfc_mbx_wr_object) -
  15554. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  15555. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  15556. wr_object->u.request.write_offset = *offset;
  15557. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  15558. wr_object->u.request.object_name[0] =
  15559. cpu_to_le32(wr_object->u.request.object_name[0]);
  15560. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  15561. list_for_each_entry(dmabuf, dmabuf_list, list) {
  15562. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  15563. break;
  15564. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  15565. wr_object->u.request.bde[i].addrHigh =
  15566. putPaddrHigh(dmabuf->phys);
  15567. if (written + SLI4_PAGE_SIZE >= size) {
  15568. wr_object->u.request.bde[i].tus.f.bdeSize =
  15569. (size - written);
  15570. written += (size - written);
  15571. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  15572. } else {
  15573. wr_object->u.request.bde[i].tus.f.bdeSize =
  15574. SLI4_PAGE_SIZE;
  15575. written += SLI4_PAGE_SIZE;
  15576. }
  15577. i++;
  15578. }
  15579. wr_object->u.request.bde_count = i;
  15580. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  15581. if (!phba->sli4_hba.intr_enable)
  15582. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15583. else {
  15584. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  15585. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  15586. }
  15587. /* The IOCTL status is embedded in the mailbox subheader. */
  15588. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  15589. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15590. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15591. if (rc != MBX_TIMEOUT)
  15592. mempool_free(mbox, phba->mbox_mem_pool);
  15593. if (shdr_status || shdr_add_status || rc) {
  15594. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15595. "3025 Write Object mailbox failed with "
  15596. "status x%x add_status x%x, mbx status x%x\n",
  15597. shdr_status, shdr_add_status, rc);
  15598. rc = -ENXIO;
  15599. } else
  15600. *offset += wr_object->u.response.actual_write_length;
  15601. return rc;
  15602. }
  15603. /**
  15604. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  15605. * @vport: pointer to vport data structure.
  15606. *
  15607. * This function iterate through the mailboxq and clean up all REG_LOGIN
  15608. * and REG_VPI mailbox commands associated with the vport. This function
  15609. * is called when driver want to restart discovery of the vport due to
  15610. * a Clear Virtual Link event.
  15611. **/
  15612. void
  15613. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  15614. {
  15615. struct lpfc_hba *phba = vport->phba;
  15616. LPFC_MBOXQ_t *mb, *nextmb;
  15617. struct lpfc_dmabuf *mp;
  15618. struct lpfc_nodelist *ndlp;
  15619. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  15620. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  15621. LIST_HEAD(mbox_cmd_list);
  15622. uint8_t restart_loop;
  15623. /* Clean up internally queued mailbox commands with the vport */
  15624. spin_lock_irq(&phba->hbalock);
  15625. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  15626. if (mb->vport != vport)
  15627. continue;
  15628. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  15629. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  15630. continue;
  15631. list_del(&mb->list);
  15632. list_add_tail(&mb->list, &mbox_cmd_list);
  15633. }
  15634. /* Clean up active mailbox command with the vport */
  15635. mb = phba->sli.mbox_active;
  15636. if (mb && (mb->vport == vport)) {
  15637. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  15638. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  15639. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15640. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15641. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  15642. /* Put reference count for delayed processing */
  15643. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  15644. /* Unregister the RPI when mailbox complete */
  15645. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  15646. }
  15647. }
  15648. /* Cleanup any mailbox completions which are not yet processed */
  15649. do {
  15650. restart_loop = 0;
  15651. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  15652. /*
  15653. * If this mailox is already processed or it is
  15654. * for another vport ignore it.
  15655. */
  15656. if ((mb->vport != vport) ||
  15657. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  15658. continue;
  15659. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  15660. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  15661. continue;
  15662. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15663. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15664. ndlp = (struct lpfc_nodelist *)mb->context2;
  15665. /* Unregister the RPI when mailbox complete */
  15666. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  15667. restart_loop = 1;
  15668. spin_unlock_irq(&phba->hbalock);
  15669. spin_lock(shost->host_lock);
  15670. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15671. spin_unlock(shost->host_lock);
  15672. spin_lock_irq(&phba->hbalock);
  15673. break;
  15674. }
  15675. }
  15676. } while (restart_loop);
  15677. spin_unlock_irq(&phba->hbalock);
  15678. /* Release the cleaned-up mailbox commands */
  15679. while (!list_empty(&mbox_cmd_list)) {
  15680. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  15681. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15682. mp = (struct lpfc_dmabuf *) (mb->context1);
  15683. if (mp) {
  15684. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  15685. kfree(mp);
  15686. }
  15687. ndlp = (struct lpfc_nodelist *) mb->context2;
  15688. mb->context2 = NULL;
  15689. if (ndlp) {
  15690. spin_lock(shost->host_lock);
  15691. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15692. spin_unlock(shost->host_lock);
  15693. lpfc_nlp_put(ndlp);
  15694. }
  15695. }
  15696. mempool_free(mb, phba->mbox_mem_pool);
  15697. }
  15698. /* Release the ndlp with the cleaned-up active mailbox command */
  15699. if (act_mbx_ndlp) {
  15700. spin_lock(shost->host_lock);
  15701. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15702. spin_unlock(shost->host_lock);
  15703. lpfc_nlp_put(act_mbx_ndlp);
  15704. }
  15705. }
  15706. /**
  15707. * lpfc_drain_txq - Drain the txq
  15708. * @phba: Pointer to HBA context object.
  15709. *
  15710. * This function attempt to submit IOCBs on the txq
  15711. * to the adapter. For SLI4 adapters, the txq contains
  15712. * ELS IOCBs that have been deferred because the there
  15713. * are no SGLs. This congestion can occur with large
  15714. * vport counts during node discovery.
  15715. **/
  15716. uint32_t
  15717. lpfc_drain_txq(struct lpfc_hba *phba)
  15718. {
  15719. LIST_HEAD(completions);
  15720. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  15721. struct lpfc_iocbq *piocbq = NULL;
  15722. unsigned long iflags = 0;
  15723. char *fail_msg = NULL;
  15724. struct lpfc_sglq *sglq;
  15725. union lpfc_wqe wqe;
  15726. uint32_t txq_cnt = 0;
  15727. spin_lock_irqsave(&pring->ring_lock, iflags);
  15728. list_for_each_entry(piocbq, &pring->txq, list) {
  15729. txq_cnt++;
  15730. }
  15731. if (txq_cnt > pring->txq_max)
  15732. pring->txq_max = txq_cnt;
  15733. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15734. while (!list_empty(&pring->txq)) {
  15735. spin_lock_irqsave(&pring->ring_lock, iflags);
  15736. piocbq = lpfc_sli_ringtx_get(phba, pring);
  15737. if (!piocbq) {
  15738. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15739. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15740. "2823 txq empty and txq_cnt is %d\n ",
  15741. txq_cnt);
  15742. break;
  15743. }
  15744. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  15745. if (!sglq) {
  15746. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  15747. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15748. break;
  15749. }
  15750. txq_cnt--;
  15751. /* The xri and iocb resources secured,
  15752. * attempt to issue request
  15753. */
  15754. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  15755. piocbq->sli4_xritag = sglq->sli4_xritag;
  15756. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  15757. fail_msg = "to convert bpl to sgl";
  15758. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  15759. fail_msg = "to convert iocb to wqe";
  15760. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  15761. fail_msg = " - Wq is full";
  15762. else
  15763. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  15764. if (fail_msg) {
  15765. /* Failed means we can't issue and need to cancel */
  15766. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15767. "2822 IOCB failed %s iotag 0x%x "
  15768. "xri 0x%x\n",
  15769. fail_msg,
  15770. piocbq->iotag, piocbq->sli4_xritag);
  15771. list_add_tail(&piocbq->list, &completions);
  15772. }
  15773. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15774. }
  15775. /* Cancel all the IOCBs that cannot be issued */
  15776. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  15777. IOERR_SLI_ABORTED);
  15778. return txq_cnt;
  15779. }