lpfc_sli.c 521 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2015 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 <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include <scsi/fc/fc_fs.h>
  32. #include <linux/aer.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_crtn.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_compat.h"
  44. #include "lpfc_debugfs.h"
  45. #include "lpfc_vport.h"
  46. /* There are only four IOCB completion types. */
  47. typedef enum _lpfc_iocb_type {
  48. LPFC_UNKNOWN_IOCB,
  49. LPFC_UNSOL_IOCB,
  50. LPFC_SOL_IOCB,
  51. LPFC_ABORT_IOCB
  52. } lpfc_iocb_type;
  53. /* Provide function prototypes local to this module. */
  54. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  55. uint32_t);
  56. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  57. uint8_t *, uint32_t *);
  58. static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
  59. struct lpfc_iocbq *);
  60. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  61. struct hbq_dmabuf *);
  62. static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *,
  63. struct lpfc_cqe *);
  64. static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *,
  65. int);
  66. static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *,
  67. uint32_t);
  68. static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
  69. static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
  70. static IOCB_t *
  71. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  72. {
  73. return &iocbq->iocb;
  74. }
  75. /**
  76. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  77. * @q: The Work Queue to operate on.
  78. * @wqe: The work Queue Entry to put on the Work queue.
  79. *
  80. * This routine will copy the contents of @wqe to the next available entry on
  81. * the @q. This function will then ring the Work Queue Doorbell to signal the
  82. * HBA to start processing the Work Queue Entry. This function returns 0 if
  83. * successful. If no entries are available on @q then this function will return
  84. * -ENOMEM.
  85. * The caller is expected to hold the hbalock when calling this routine.
  86. **/
  87. static uint32_t
  88. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  89. {
  90. union lpfc_wqe *temp_wqe;
  91. struct lpfc_register doorbell;
  92. uint32_t host_index;
  93. uint32_t idx;
  94. /* sanity check on queue memory */
  95. if (unlikely(!q))
  96. return -ENOMEM;
  97. temp_wqe = q->qe[q->host_index].wqe;
  98. /* If the host has not yet processed the next entry then we are done */
  99. idx = ((q->host_index + 1) % q->entry_count);
  100. if (idx == q->hba_index) {
  101. q->WQ_overflow++;
  102. return -ENOMEM;
  103. }
  104. q->WQ_posted++;
  105. /* set consumption flag every once in a while */
  106. if (!((q->host_index + 1) % q->entry_repost))
  107. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  108. else
  109. bf_set(wqe_wqec, &wqe->generic.wqe_com, 0);
  110. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  111. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  112. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  113. /* ensure WQE bcopy flushed before doorbell write */
  114. wmb();
  115. /* Update the host index before invoking device */
  116. host_index = q->host_index;
  117. q->host_index = idx;
  118. /* Ring Doorbell */
  119. doorbell.word0 = 0;
  120. if (q->db_format == LPFC_DB_LIST_FORMAT) {
  121. bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
  122. bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index);
  123. bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
  124. } else if (q->db_format == LPFC_DB_RING_FORMAT) {
  125. bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
  126. bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
  127. } else {
  128. return -EINVAL;
  129. }
  130. writel(doorbell.word0, q->db_regaddr);
  131. return 0;
  132. }
  133. /**
  134. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  135. * @q: The Work Queue to operate on.
  136. * @index: The index to advance the hba index to.
  137. *
  138. * This routine will update the HBA index of a queue to reflect consumption of
  139. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  140. * an entry the host calls this function to update the queue's internal
  141. * pointers. This routine returns the number of entries that were consumed by
  142. * the HBA.
  143. **/
  144. static uint32_t
  145. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  146. {
  147. uint32_t released = 0;
  148. /* sanity check on queue memory */
  149. if (unlikely(!q))
  150. return 0;
  151. if (q->hba_index == index)
  152. return 0;
  153. do {
  154. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  155. released++;
  156. } while (q->hba_index != index);
  157. return released;
  158. }
  159. /**
  160. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  161. * @q: The Mailbox Queue to operate on.
  162. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  163. *
  164. * This routine will copy the contents of @mqe to the next available entry on
  165. * the @q. This function will then ring the Work Queue Doorbell to signal the
  166. * HBA to start processing the Work Queue Entry. This function returns 0 if
  167. * successful. If no entries are available on @q then this function will return
  168. * -ENOMEM.
  169. * The caller is expected to hold the hbalock when calling this routine.
  170. **/
  171. static uint32_t
  172. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  173. {
  174. struct lpfc_mqe *temp_mqe;
  175. struct lpfc_register doorbell;
  176. /* sanity check on queue memory */
  177. if (unlikely(!q))
  178. return -ENOMEM;
  179. temp_mqe = q->qe[q->host_index].mqe;
  180. /* If the host has not yet processed the next entry then we are done */
  181. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  182. return -ENOMEM;
  183. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  184. /* Save off the mailbox pointer for completion */
  185. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  186. /* Update the host index before invoking device */
  187. q->host_index = ((q->host_index + 1) % q->entry_count);
  188. /* Ring Doorbell */
  189. doorbell.word0 = 0;
  190. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  191. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  192. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  193. return 0;
  194. }
  195. /**
  196. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  197. * @q: The Mailbox Queue to operate on.
  198. *
  199. * This routine will update the HBA index of a queue to reflect consumption of
  200. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  201. * an entry the host calls this function to update the queue's internal
  202. * pointers. This routine returns the number of entries that were consumed by
  203. * the HBA.
  204. **/
  205. static uint32_t
  206. lpfc_sli4_mq_release(struct lpfc_queue *q)
  207. {
  208. /* sanity check on queue memory */
  209. if (unlikely(!q))
  210. return 0;
  211. /* Clear the mailbox pointer for completion */
  212. q->phba->mbox = NULL;
  213. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  214. return 1;
  215. }
  216. /**
  217. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  218. * @q: The Event Queue to get the first valid EQE from
  219. *
  220. * This routine will get the first valid Event Queue Entry from @q, update
  221. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  222. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  223. * processed, but not popped back to the HBA then this routine will return NULL.
  224. **/
  225. static struct lpfc_eqe *
  226. lpfc_sli4_eq_get(struct lpfc_queue *q)
  227. {
  228. struct lpfc_eqe *eqe;
  229. uint32_t idx;
  230. /* sanity check on queue memory */
  231. if (unlikely(!q))
  232. return NULL;
  233. eqe = q->qe[q->hba_index].eqe;
  234. /* If the next EQE is not valid then we are done */
  235. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  236. return NULL;
  237. /* If the host has not yet processed the next entry then we are done */
  238. idx = ((q->hba_index + 1) % q->entry_count);
  239. if (idx == q->host_index)
  240. return NULL;
  241. q->hba_index = idx;
  242. /*
  243. * insert barrier for instruction interlock : data from the hardware
  244. * must have the valid bit checked before it can be copied and acted
  245. * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
  246. * instructions allowing action on content before valid bit checked,
  247. * add barrier here as well. May not be needed as "content" is a
  248. * single 32-bit entity here (vs multi word structure for cq's).
  249. */
  250. mb();
  251. return eqe;
  252. }
  253. /**
  254. * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
  255. * @q: The Event Queue to disable interrupts
  256. *
  257. **/
  258. static inline void
  259. lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
  260. {
  261. struct lpfc_register doorbell;
  262. doorbell.word0 = 0;
  263. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  264. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  265. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  266. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  267. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  268. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  269. }
  270. /**
  271. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  272. * @q: The Event Queue that the host has completed processing for.
  273. * @arm: Indicates whether the host wants to arms this CQ.
  274. *
  275. * This routine will mark all Event Queue Entries on @q, from the last
  276. * known completed entry to the last entry that was processed, as completed
  277. * by clearing the valid bit for each completion queue entry. Then it will
  278. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  279. * The internal host index in the @q will be updated by this routine to indicate
  280. * that the host has finished processing the entries. The @arm parameter
  281. * indicates that the queue should be rearmed when ringing the doorbell.
  282. *
  283. * This function will return the number of EQEs that were popped.
  284. **/
  285. uint32_t
  286. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  287. {
  288. uint32_t released = 0;
  289. struct lpfc_eqe *temp_eqe;
  290. struct lpfc_register doorbell;
  291. /* sanity check on queue memory */
  292. if (unlikely(!q))
  293. return 0;
  294. /* while there are valid entries */
  295. while (q->hba_index != q->host_index) {
  296. temp_eqe = q->qe[q->host_index].eqe;
  297. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  298. released++;
  299. q->host_index = ((q->host_index + 1) % q->entry_count);
  300. }
  301. if (unlikely(released == 0 && !arm))
  302. return 0;
  303. /* ring doorbell for number popped */
  304. doorbell.word0 = 0;
  305. if (arm) {
  306. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  307. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  308. }
  309. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  310. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  311. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  312. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  313. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  314. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  315. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  316. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  317. readl(q->phba->sli4_hba.EQCQDBregaddr);
  318. return released;
  319. }
  320. /**
  321. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  322. * @q: The Completion Queue to get the first valid CQE from
  323. *
  324. * This routine will get the first valid Completion Queue Entry from @q, update
  325. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  326. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  327. * processed, but not popped back to the HBA then this routine will return NULL.
  328. **/
  329. static struct lpfc_cqe *
  330. lpfc_sli4_cq_get(struct lpfc_queue *q)
  331. {
  332. struct lpfc_cqe *cqe;
  333. uint32_t idx;
  334. /* sanity check on queue memory */
  335. if (unlikely(!q))
  336. return NULL;
  337. /* If the next CQE is not valid then we are done */
  338. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  339. return NULL;
  340. /* If the host has not yet processed the next entry then we are done */
  341. idx = ((q->hba_index + 1) % q->entry_count);
  342. if (idx == q->host_index)
  343. return NULL;
  344. cqe = q->qe[q->hba_index].cqe;
  345. q->hba_index = idx;
  346. /*
  347. * insert barrier for instruction interlock : data from the hardware
  348. * must have the valid bit checked before it can be copied and acted
  349. * upon. Speculative instructions were allowing a bcopy at the start
  350. * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
  351. * after our return, to copy data before the valid bit check above
  352. * was done. As such, some of the copied data was stale. The barrier
  353. * ensures the check is before any data is copied.
  354. */
  355. mb();
  356. return cqe;
  357. }
  358. /**
  359. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  360. * @q: The Completion Queue that the host has completed processing for.
  361. * @arm: Indicates whether the host wants to arms this CQ.
  362. *
  363. * This routine will mark all Completion queue entries on @q, from the last
  364. * known completed entry to the last entry that was processed, as completed
  365. * by clearing the valid bit for each completion queue entry. Then it will
  366. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  367. * The internal host index in the @q will be updated by this routine to indicate
  368. * that the host has finished processing the entries. The @arm parameter
  369. * indicates that the queue should be rearmed when ringing the doorbell.
  370. *
  371. * This function will return the number of CQEs that were released.
  372. **/
  373. uint32_t
  374. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  375. {
  376. uint32_t released = 0;
  377. struct lpfc_cqe *temp_qe;
  378. struct lpfc_register doorbell;
  379. /* sanity check on queue memory */
  380. if (unlikely(!q))
  381. return 0;
  382. /* while there are valid entries */
  383. while (q->hba_index != q->host_index) {
  384. temp_qe = q->qe[q->host_index].cqe;
  385. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  386. released++;
  387. q->host_index = ((q->host_index + 1) % q->entry_count);
  388. }
  389. if (unlikely(released == 0 && !arm))
  390. return 0;
  391. /* ring doorbell for number popped */
  392. doorbell.word0 = 0;
  393. if (arm)
  394. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  395. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  396. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  397. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  398. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  399. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  400. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  401. return released;
  402. }
  403. /**
  404. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  405. * @q: The Header Receive Queue to operate on.
  406. * @wqe: The Receive Queue Entry to put on the Receive queue.
  407. *
  408. * This routine will copy the contents of @wqe to the next available entry on
  409. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  410. * HBA to start processing the Receive Queue Entry. This function returns the
  411. * index that the rqe was copied to if successful. If no entries are available
  412. * on @q then this function will return -ENOMEM.
  413. * The caller is expected to hold the hbalock when calling this routine.
  414. **/
  415. static int
  416. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  417. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  418. {
  419. struct lpfc_rqe *temp_hrqe;
  420. struct lpfc_rqe *temp_drqe;
  421. struct lpfc_register doorbell;
  422. int put_index;
  423. /* sanity check on queue memory */
  424. if (unlikely(!hq) || unlikely(!dq))
  425. return -ENOMEM;
  426. put_index = hq->host_index;
  427. temp_hrqe = hq->qe[hq->host_index].rqe;
  428. temp_drqe = dq->qe[dq->host_index].rqe;
  429. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  430. return -EINVAL;
  431. if (hq->host_index != dq->host_index)
  432. return -EINVAL;
  433. /* If the host has not yet processed the next entry then we are done */
  434. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  435. return -EBUSY;
  436. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  437. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  438. /* Update the host index to point to the next slot */
  439. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  440. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  441. /* Ring The Header Receive Queue Doorbell */
  442. if (!(hq->host_index % hq->entry_repost)) {
  443. doorbell.word0 = 0;
  444. if (hq->db_format == LPFC_DB_RING_FORMAT) {
  445. bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
  446. hq->entry_repost);
  447. bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
  448. } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
  449. bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
  450. hq->entry_repost);
  451. bf_set(lpfc_rq_db_list_fm_index, &doorbell,
  452. hq->host_index);
  453. bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
  454. } else {
  455. return -EINVAL;
  456. }
  457. writel(doorbell.word0, hq->db_regaddr);
  458. }
  459. return put_index;
  460. }
  461. /**
  462. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  463. * @q: The Header Receive Queue to operate on.
  464. *
  465. * This routine will update the HBA index of a queue to reflect consumption of
  466. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  467. * consumed an entry the host calls this function to update the queue's
  468. * internal pointers. This routine returns the number of entries that were
  469. * consumed by the HBA.
  470. **/
  471. static uint32_t
  472. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  473. {
  474. /* sanity check on queue memory */
  475. if (unlikely(!hq) || unlikely(!dq))
  476. return 0;
  477. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  478. return 0;
  479. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  480. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  481. return 1;
  482. }
  483. /**
  484. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  485. * @phba: Pointer to HBA context object.
  486. * @pring: Pointer to driver SLI ring object.
  487. *
  488. * This function returns pointer to next command iocb entry
  489. * in the command ring. The caller must hold hbalock to prevent
  490. * other threads consume the next command iocb.
  491. * SLI-2/SLI-3 provide different sized iocbs.
  492. **/
  493. static inline IOCB_t *
  494. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  495. {
  496. return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
  497. pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
  498. }
  499. /**
  500. * lpfc_resp_iocb - Get next response iocb entry in the ring
  501. * @phba: Pointer to HBA context object.
  502. * @pring: Pointer to driver SLI ring object.
  503. *
  504. * This function returns pointer to next response iocb entry
  505. * in the response ring. The caller must hold hbalock to make sure
  506. * that no other thread consume the next response iocb.
  507. * SLI-2/SLI-3 provide different sized iocbs.
  508. **/
  509. static inline IOCB_t *
  510. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  511. {
  512. return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
  513. pring->sli.sli3.rspidx * phba->iocb_rsp_size);
  514. }
  515. /**
  516. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  517. * @phba: Pointer to HBA context object.
  518. *
  519. * This function is called with hbalock held. This function
  520. * allocates a new driver iocb object from the iocb pool. If the
  521. * allocation is successful, it returns pointer to the newly
  522. * allocated iocb object else it returns NULL.
  523. **/
  524. struct lpfc_iocbq *
  525. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  526. {
  527. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  528. struct lpfc_iocbq * iocbq = NULL;
  529. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  530. if (iocbq)
  531. phba->iocb_cnt++;
  532. if (phba->iocb_cnt > phba->iocb_max)
  533. phba->iocb_max = phba->iocb_cnt;
  534. return iocbq;
  535. }
  536. /**
  537. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  538. * @phba: Pointer to HBA context object.
  539. * @xritag: XRI value.
  540. *
  541. * This function clears the sglq pointer from the array of acive
  542. * sglq's. The xritag that is passed in is used to index into the
  543. * array. Before the xritag can be used it needs to be adjusted
  544. * by subtracting the xribase.
  545. *
  546. * Returns sglq ponter = success, NULL = Failure.
  547. **/
  548. static struct lpfc_sglq *
  549. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  550. {
  551. struct lpfc_sglq *sglq;
  552. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  553. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  554. return sglq;
  555. }
  556. /**
  557. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  558. * @phba: Pointer to HBA context object.
  559. * @xritag: XRI value.
  560. *
  561. * This function returns the sglq pointer from the array of acive
  562. * sglq's. The xritag that is passed in is used to index into the
  563. * array. Before the xritag can be used it needs to be adjusted
  564. * by subtracting the xribase.
  565. *
  566. * Returns sglq ponter = success, NULL = Failure.
  567. **/
  568. struct lpfc_sglq *
  569. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  570. {
  571. struct lpfc_sglq *sglq;
  572. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  573. return sglq;
  574. }
  575. /**
  576. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  577. * @phba: Pointer to HBA context object.
  578. * @xritag: xri used in this exchange.
  579. * @rrq: The RRQ to be cleared.
  580. *
  581. **/
  582. void
  583. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  584. uint16_t xritag,
  585. struct lpfc_node_rrq *rrq)
  586. {
  587. struct lpfc_nodelist *ndlp = NULL;
  588. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  589. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  590. /* The target DID could have been swapped (cable swap)
  591. * we should use the ndlp from the findnode if it is
  592. * available.
  593. */
  594. if ((!ndlp) && rrq->ndlp)
  595. ndlp = rrq->ndlp;
  596. if (!ndlp)
  597. goto out;
  598. if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
  599. rrq->send_rrq = 0;
  600. rrq->xritag = 0;
  601. rrq->rrq_stop_time = 0;
  602. }
  603. out:
  604. mempool_free(rrq, phba->rrq_pool);
  605. }
  606. /**
  607. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  608. * @phba: Pointer to HBA context object.
  609. *
  610. * This function is called with hbalock held. This function
  611. * Checks if stop_time (ratov from setting rrq active) has
  612. * been reached, if it has and the send_rrq flag is set then
  613. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  614. * then it will just call the routine to clear the rrq and
  615. * free the rrq resource.
  616. * The timer is set to the next rrq that is going to expire before
  617. * leaving the routine.
  618. *
  619. **/
  620. void
  621. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  622. {
  623. struct lpfc_node_rrq *rrq;
  624. struct lpfc_node_rrq *nextrrq;
  625. unsigned long next_time;
  626. unsigned long iflags;
  627. LIST_HEAD(send_rrq);
  628. spin_lock_irqsave(&phba->hbalock, iflags);
  629. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  630. next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  631. list_for_each_entry_safe(rrq, nextrrq,
  632. &phba->active_rrq_list, list) {
  633. if (time_after(jiffies, rrq->rrq_stop_time))
  634. list_move(&rrq->list, &send_rrq);
  635. else if (time_before(rrq->rrq_stop_time, next_time))
  636. next_time = rrq->rrq_stop_time;
  637. }
  638. spin_unlock_irqrestore(&phba->hbalock, iflags);
  639. if ((!list_empty(&phba->active_rrq_list)) &&
  640. (!(phba->pport->load_flag & FC_UNLOADING)))
  641. mod_timer(&phba->rrq_tmr, next_time);
  642. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  643. list_del(&rrq->list);
  644. if (!rrq->send_rrq)
  645. /* this call will free the rrq */
  646. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  647. else if (lpfc_send_rrq(phba, rrq)) {
  648. /* if we send the rrq then the completion handler
  649. * will clear the bit in the xribitmap.
  650. */
  651. lpfc_clr_rrq_active(phba, rrq->xritag,
  652. rrq);
  653. }
  654. }
  655. }
  656. /**
  657. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  658. * @vport: Pointer to vport context object.
  659. * @xri: The xri used in the exchange.
  660. * @did: The targets DID for this exchange.
  661. *
  662. * returns NULL = rrq not found in the phba->active_rrq_list.
  663. * rrq = rrq for this xri and target.
  664. **/
  665. struct lpfc_node_rrq *
  666. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  667. {
  668. struct lpfc_hba *phba = vport->phba;
  669. struct lpfc_node_rrq *rrq;
  670. struct lpfc_node_rrq *nextrrq;
  671. unsigned long iflags;
  672. if (phba->sli_rev != LPFC_SLI_REV4)
  673. return NULL;
  674. spin_lock_irqsave(&phba->hbalock, iflags);
  675. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  676. if (rrq->vport == vport && rrq->xritag == xri &&
  677. rrq->nlp_DID == did){
  678. list_del(&rrq->list);
  679. spin_unlock_irqrestore(&phba->hbalock, iflags);
  680. return rrq;
  681. }
  682. }
  683. spin_unlock_irqrestore(&phba->hbalock, iflags);
  684. return NULL;
  685. }
  686. /**
  687. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  688. * @vport: Pointer to vport context object.
  689. * @ndlp: Pointer to the lpfc_node_list structure.
  690. * If ndlp is NULL Remove all active RRQs for this vport from the
  691. * phba->active_rrq_list and clear the rrq.
  692. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  693. **/
  694. void
  695. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  696. {
  697. struct lpfc_hba *phba = vport->phba;
  698. struct lpfc_node_rrq *rrq;
  699. struct lpfc_node_rrq *nextrrq;
  700. unsigned long iflags;
  701. LIST_HEAD(rrq_list);
  702. if (phba->sli_rev != LPFC_SLI_REV4)
  703. return;
  704. if (!ndlp) {
  705. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  706. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  707. }
  708. spin_lock_irqsave(&phba->hbalock, iflags);
  709. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  710. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  711. list_move(&rrq->list, &rrq_list);
  712. spin_unlock_irqrestore(&phba->hbalock, iflags);
  713. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  714. list_del(&rrq->list);
  715. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  716. }
  717. }
  718. /**
  719. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  720. * @phba: Pointer to HBA context object.
  721. * @ndlp: Targets nodelist pointer for this exchange.
  722. * @xritag the xri in the bitmap to test.
  723. *
  724. * This function is called with hbalock held. This function
  725. * returns 0 = rrq not active for this xri
  726. * 1 = rrq is valid for this xri.
  727. **/
  728. int
  729. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  730. uint16_t xritag)
  731. {
  732. if (!ndlp)
  733. return 0;
  734. if (!ndlp->active_rrqs_xri_bitmap)
  735. return 0;
  736. if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
  737. return 1;
  738. else
  739. return 0;
  740. }
  741. /**
  742. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  743. * @phba: Pointer to HBA context object.
  744. * @ndlp: nodelist pointer for this target.
  745. * @xritag: xri used in this exchange.
  746. * @rxid: Remote Exchange ID.
  747. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  748. *
  749. * This function takes the hbalock.
  750. * The active bit is always set in the active rrq xri_bitmap even
  751. * if there is no slot avaiable for the other rrq information.
  752. *
  753. * returns 0 rrq actived for this xri
  754. * < 0 No memory or invalid ndlp.
  755. **/
  756. int
  757. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  758. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  759. {
  760. unsigned long iflags;
  761. struct lpfc_node_rrq *rrq;
  762. int empty;
  763. if (!ndlp)
  764. return -EINVAL;
  765. if (!phba->cfg_enable_rrq)
  766. return -EINVAL;
  767. spin_lock_irqsave(&phba->hbalock, iflags);
  768. if (phba->pport->load_flag & FC_UNLOADING) {
  769. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  770. goto out;
  771. }
  772. /*
  773. * set the active bit even if there is no mem available.
  774. */
  775. if (NLP_CHK_FREE_REQ(ndlp))
  776. goto out;
  777. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  778. goto out;
  779. if (!ndlp->active_rrqs_xri_bitmap)
  780. goto out;
  781. if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
  782. goto out;
  783. spin_unlock_irqrestore(&phba->hbalock, iflags);
  784. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  785. if (!rrq) {
  786. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  787. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  788. " DID:0x%x Send:%d\n",
  789. xritag, rxid, ndlp->nlp_DID, send_rrq);
  790. return -EINVAL;
  791. }
  792. if (phba->cfg_enable_rrq == 1)
  793. rrq->send_rrq = send_rrq;
  794. else
  795. rrq->send_rrq = 0;
  796. rrq->xritag = xritag;
  797. rrq->rrq_stop_time = jiffies +
  798. msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  799. rrq->ndlp = ndlp;
  800. rrq->nlp_DID = ndlp->nlp_DID;
  801. rrq->vport = ndlp->vport;
  802. rrq->rxid = rxid;
  803. spin_lock_irqsave(&phba->hbalock, iflags);
  804. empty = list_empty(&phba->active_rrq_list);
  805. list_add_tail(&rrq->list, &phba->active_rrq_list);
  806. phba->hba_flag |= HBA_RRQ_ACTIVE;
  807. if (empty)
  808. lpfc_worker_wake_up(phba);
  809. spin_unlock_irqrestore(&phba->hbalock, iflags);
  810. return 0;
  811. out:
  812. spin_unlock_irqrestore(&phba->hbalock, iflags);
  813. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  814. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  815. " DID:0x%x Send:%d\n",
  816. xritag, rxid, ndlp->nlp_DID, send_rrq);
  817. return -EINVAL;
  818. }
  819. /**
  820. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  821. * @phba: Pointer to HBA context object.
  822. * @piocb: Pointer to the iocbq.
  823. *
  824. * This function is called with the ring lock held. This function
  825. * gets a new driver sglq object from the sglq list. If the
  826. * list is not empty then it is successful, it returns pointer to the newly
  827. * allocated sglq object else it returns NULL.
  828. **/
  829. static struct lpfc_sglq *
  830. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  831. {
  832. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  833. struct lpfc_sglq *sglq = NULL;
  834. struct lpfc_sglq *start_sglq = NULL;
  835. struct lpfc_scsi_buf *lpfc_cmd;
  836. struct lpfc_nodelist *ndlp;
  837. int found = 0;
  838. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  839. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  840. ndlp = lpfc_cmd->rdata->pnode;
  841. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  842. !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  843. ndlp = piocbq->context_un.ndlp;
  844. } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) {
  845. if (piocbq->iocb_flag & LPFC_IO_LOOPBACK)
  846. ndlp = NULL;
  847. else
  848. ndlp = piocbq->context_un.ndlp;
  849. } else {
  850. ndlp = piocbq->context1;
  851. }
  852. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  853. start_sglq = sglq;
  854. while (!found) {
  855. if (!sglq)
  856. return NULL;
  857. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
  858. /* This xri has an rrq outstanding for this DID.
  859. * put it back in the list and get another xri.
  860. */
  861. list_add_tail(&sglq->list, lpfc_sgl_list);
  862. sglq = NULL;
  863. list_remove_head(lpfc_sgl_list, sglq,
  864. struct lpfc_sglq, list);
  865. if (sglq == start_sglq) {
  866. sglq = NULL;
  867. break;
  868. } else
  869. continue;
  870. }
  871. sglq->ndlp = ndlp;
  872. found = 1;
  873. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  874. sglq->state = SGL_ALLOCATED;
  875. }
  876. return sglq;
  877. }
  878. /**
  879. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  880. * @phba: Pointer to HBA context object.
  881. *
  882. * This function is called with no lock held. This function
  883. * allocates a new driver iocb object from the iocb pool. If the
  884. * allocation is successful, it returns pointer to the newly
  885. * allocated iocb object else it returns NULL.
  886. **/
  887. struct lpfc_iocbq *
  888. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  889. {
  890. struct lpfc_iocbq * iocbq = NULL;
  891. unsigned long iflags;
  892. spin_lock_irqsave(&phba->hbalock, iflags);
  893. iocbq = __lpfc_sli_get_iocbq(phba);
  894. spin_unlock_irqrestore(&phba->hbalock, iflags);
  895. return iocbq;
  896. }
  897. /**
  898. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  899. * @phba: Pointer to HBA context object.
  900. * @iocbq: Pointer to driver iocb object.
  901. *
  902. * This function is called with hbalock held to release driver
  903. * iocb object to the iocb pool. The iotag in the iocb object
  904. * does not change for each use of the iocb object. This function
  905. * clears all other fields of the iocb object when it is freed.
  906. * The sqlq structure that holds the xritag and phys and virtual
  907. * mappings for the scatter gather list is retrieved from the
  908. * active array of sglq. The get of the sglq pointer also clears
  909. * the entry in the array. If the status of the IO indiactes that
  910. * this IO was aborted then the sglq entry it put on the
  911. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  912. * IO has good status or fails for any other reason then the sglq
  913. * entry is added to the free list (lpfc_sgl_list).
  914. **/
  915. static void
  916. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  917. {
  918. struct lpfc_sglq *sglq;
  919. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  920. unsigned long iflag = 0;
  921. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  922. if (iocbq->sli4_xritag == NO_XRI)
  923. sglq = NULL;
  924. else
  925. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  926. if (sglq) {
  927. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  928. (sglq->state != SGL_XRI_ABORTED)) {
  929. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  930. iflag);
  931. list_add(&sglq->list,
  932. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  933. spin_unlock_irqrestore(
  934. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  935. } else {
  936. spin_lock_irqsave(&pring->ring_lock, iflag);
  937. sglq->state = SGL_FREED;
  938. sglq->ndlp = NULL;
  939. list_add_tail(&sglq->list,
  940. &phba->sli4_hba.lpfc_sgl_list);
  941. spin_unlock_irqrestore(&pring->ring_lock, iflag);
  942. /* Check if TXQ queue needs to be serviced */
  943. if (!list_empty(&pring->txq))
  944. lpfc_worker_wake_up(phba);
  945. }
  946. }
  947. /*
  948. * Clean all volatile data fields, preserve iotag and node struct.
  949. */
  950. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  951. iocbq->sli4_lxritag = NO_XRI;
  952. iocbq->sli4_xritag = NO_XRI;
  953. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  954. }
  955. /**
  956. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  957. * @phba: Pointer to HBA context object.
  958. * @iocbq: Pointer to driver iocb object.
  959. *
  960. * This function is called with hbalock held to release driver
  961. * iocb object to the iocb pool. The iotag in the iocb object
  962. * does not change for each use of the iocb object. This function
  963. * clears all other fields of the iocb object when it is freed.
  964. **/
  965. static void
  966. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  967. {
  968. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  969. /*
  970. * Clean all volatile data fields, preserve iotag and node struct.
  971. */
  972. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  973. iocbq->sli4_xritag = NO_XRI;
  974. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  975. }
  976. /**
  977. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  978. * @phba: Pointer to HBA context object.
  979. * @iocbq: Pointer to driver iocb object.
  980. *
  981. * This function is called with hbalock held to release driver
  982. * iocb object to the iocb pool. The iotag in the iocb object
  983. * does not change for each use of the iocb object. This function
  984. * clears all other fields of the iocb object when it is freed.
  985. **/
  986. static void
  987. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  988. {
  989. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  990. phba->iocb_cnt--;
  991. }
  992. /**
  993. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  994. * @phba: Pointer to HBA context object.
  995. * @iocbq: Pointer to driver iocb object.
  996. *
  997. * This function is called with no lock held to release the iocb to
  998. * iocb pool.
  999. **/
  1000. void
  1001. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1002. {
  1003. unsigned long iflags;
  1004. /*
  1005. * Clean all volatile data fields, preserve iotag and node struct.
  1006. */
  1007. spin_lock_irqsave(&phba->hbalock, iflags);
  1008. __lpfc_sli_release_iocbq(phba, iocbq);
  1009. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1010. }
  1011. /**
  1012. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  1013. * @phba: Pointer to HBA context object.
  1014. * @iocblist: List of IOCBs.
  1015. * @ulpstatus: ULP status in IOCB command field.
  1016. * @ulpWord4: ULP word-4 in IOCB command field.
  1017. *
  1018. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  1019. * on the list by invoking the complete callback function associated with the
  1020. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  1021. * fields.
  1022. **/
  1023. void
  1024. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  1025. uint32_t ulpstatus, uint32_t ulpWord4)
  1026. {
  1027. struct lpfc_iocbq *piocb;
  1028. while (!list_empty(iocblist)) {
  1029. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  1030. if (!piocb->iocb_cmpl)
  1031. lpfc_sli_release_iocbq(phba, piocb);
  1032. else {
  1033. piocb->iocb.ulpStatus = ulpstatus;
  1034. piocb->iocb.un.ulpWord[4] = ulpWord4;
  1035. (piocb->iocb_cmpl) (phba, piocb, piocb);
  1036. }
  1037. }
  1038. return;
  1039. }
  1040. /**
  1041. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1042. * @iocb_cmnd: iocb command code.
  1043. *
  1044. * This function is called by ring event handler function to get the iocb type.
  1045. * This function translates the iocb command to an iocb command type used to
  1046. * decide the final disposition of each completed IOCB.
  1047. * The function returns
  1048. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1049. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1050. * LPFC_ABORT_IOCB if it is an abort iocb
  1051. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1052. *
  1053. * The caller is not required to hold any lock.
  1054. **/
  1055. static lpfc_iocb_type
  1056. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1057. {
  1058. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1059. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1060. return 0;
  1061. switch (iocb_cmnd) {
  1062. case CMD_XMIT_SEQUENCE_CR:
  1063. case CMD_XMIT_SEQUENCE_CX:
  1064. case CMD_XMIT_BCAST_CN:
  1065. case CMD_XMIT_BCAST_CX:
  1066. case CMD_ELS_REQUEST_CR:
  1067. case CMD_ELS_REQUEST_CX:
  1068. case CMD_CREATE_XRI_CR:
  1069. case CMD_CREATE_XRI_CX:
  1070. case CMD_GET_RPI_CN:
  1071. case CMD_XMIT_ELS_RSP_CX:
  1072. case CMD_GET_RPI_CR:
  1073. case CMD_FCP_IWRITE_CR:
  1074. case CMD_FCP_IWRITE_CX:
  1075. case CMD_FCP_IREAD_CR:
  1076. case CMD_FCP_IREAD_CX:
  1077. case CMD_FCP_ICMND_CR:
  1078. case CMD_FCP_ICMND_CX:
  1079. case CMD_FCP_TSEND_CX:
  1080. case CMD_FCP_TRSP_CX:
  1081. case CMD_FCP_TRECEIVE_CX:
  1082. case CMD_FCP_AUTO_TRSP_CX:
  1083. case CMD_ADAPTER_MSG:
  1084. case CMD_ADAPTER_DUMP:
  1085. case CMD_XMIT_SEQUENCE64_CR:
  1086. case CMD_XMIT_SEQUENCE64_CX:
  1087. case CMD_XMIT_BCAST64_CN:
  1088. case CMD_XMIT_BCAST64_CX:
  1089. case CMD_ELS_REQUEST64_CR:
  1090. case CMD_ELS_REQUEST64_CX:
  1091. case CMD_FCP_IWRITE64_CR:
  1092. case CMD_FCP_IWRITE64_CX:
  1093. case CMD_FCP_IREAD64_CR:
  1094. case CMD_FCP_IREAD64_CX:
  1095. case CMD_FCP_ICMND64_CR:
  1096. case CMD_FCP_ICMND64_CX:
  1097. case CMD_FCP_TSEND64_CX:
  1098. case CMD_FCP_TRSP64_CX:
  1099. case CMD_FCP_TRECEIVE64_CX:
  1100. case CMD_GEN_REQUEST64_CR:
  1101. case CMD_GEN_REQUEST64_CX:
  1102. case CMD_XMIT_ELS_RSP64_CX:
  1103. case DSSCMD_IWRITE64_CR:
  1104. case DSSCMD_IWRITE64_CX:
  1105. case DSSCMD_IREAD64_CR:
  1106. case DSSCMD_IREAD64_CX:
  1107. type = LPFC_SOL_IOCB;
  1108. break;
  1109. case CMD_ABORT_XRI_CN:
  1110. case CMD_ABORT_XRI_CX:
  1111. case CMD_CLOSE_XRI_CN:
  1112. case CMD_CLOSE_XRI_CX:
  1113. case CMD_XRI_ABORTED_CX:
  1114. case CMD_ABORT_MXRI64_CN:
  1115. case CMD_XMIT_BLS_RSP64_CX:
  1116. type = LPFC_ABORT_IOCB;
  1117. break;
  1118. case CMD_RCV_SEQUENCE_CX:
  1119. case CMD_RCV_ELS_REQ_CX:
  1120. case CMD_RCV_SEQUENCE64_CX:
  1121. case CMD_RCV_ELS_REQ64_CX:
  1122. case CMD_ASYNC_STATUS:
  1123. case CMD_IOCB_RCV_SEQ64_CX:
  1124. case CMD_IOCB_RCV_ELS64_CX:
  1125. case CMD_IOCB_RCV_CONT64_CX:
  1126. case CMD_IOCB_RET_XRI64_CX:
  1127. type = LPFC_UNSOL_IOCB;
  1128. break;
  1129. case CMD_IOCB_XMIT_MSEQ64_CR:
  1130. case CMD_IOCB_XMIT_MSEQ64_CX:
  1131. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1132. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1133. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1134. case CMD_IOCB_ABORT_EXTENDED_CN:
  1135. case CMD_IOCB_RET_HBQE64_CN:
  1136. case CMD_IOCB_FCP_IBIDIR64_CR:
  1137. case CMD_IOCB_FCP_IBIDIR64_CX:
  1138. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1139. case CMD_IOCB_LOGENTRY_CN:
  1140. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1141. printk("%s - Unhandled SLI-3 Command x%x\n",
  1142. __func__, iocb_cmnd);
  1143. type = LPFC_UNKNOWN_IOCB;
  1144. break;
  1145. default:
  1146. type = LPFC_UNKNOWN_IOCB;
  1147. break;
  1148. }
  1149. return type;
  1150. }
  1151. /**
  1152. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1153. * @phba: Pointer to HBA context object.
  1154. *
  1155. * This function is called from SLI initialization code
  1156. * to configure every ring of the HBA's SLI interface. The
  1157. * caller is not required to hold any lock. This function issues
  1158. * a config_ring mailbox command for each ring.
  1159. * This function returns zero if successful else returns a negative
  1160. * error code.
  1161. **/
  1162. static int
  1163. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1164. {
  1165. struct lpfc_sli *psli = &phba->sli;
  1166. LPFC_MBOXQ_t *pmb;
  1167. MAILBOX_t *pmbox;
  1168. int i, rc, ret = 0;
  1169. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1170. if (!pmb)
  1171. return -ENOMEM;
  1172. pmbox = &pmb->u.mb;
  1173. phba->link_state = LPFC_INIT_MBX_CMDS;
  1174. for (i = 0; i < psli->num_rings; i++) {
  1175. lpfc_config_ring(phba, i, pmb);
  1176. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1177. if (rc != MBX_SUCCESS) {
  1178. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1179. "0446 Adapter failed to init (%d), "
  1180. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1181. "ring %d\n",
  1182. rc, pmbox->mbxCommand,
  1183. pmbox->mbxStatus, i);
  1184. phba->link_state = LPFC_HBA_ERROR;
  1185. ret = -ENXIO;
  1186. break;
  1187. }
  1188. }
  1189. mempool_free(pmb, phba->mbox_mem_pool);
  1190. return ret;
  1191. }
  1192. /**
  1193. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1194. * @phba: Pointer to HBA context object.
  1195. * @pring: Pointer to driver SLI ring object.
  1196. * @piocb: Pointer to the driver iocb object.
  1197. *
  1198. * This function is called with hbalock held. The function adds the
  1199. * new iocb to txcmplq of the given ring. This function always returns
  1200. * 0. If this function is called for ELS ring, this function checks if
  1201. * there is a vport associated with the ELS command. This function also
  1202. * starts els_tmofunc timer if this is an ELS command.
  1203. **/
  1204. static int
  1205. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1206. struct lpfc_iocbq *piocb)
  1207. {
  1208. list_add_tail(&piocb->list, &pring->txcmplq);
  1209. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1210. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1211. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1212. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN) &&
  1213. (!(piocb->vport->load_flag & FC_UNLOADING))) {
  1214. if (!piocb->vport)
  1215. BUG();
  1216. else
  1217. mod_timer(&piocb->vport->els_tmofunc,
  1218. jiffies +
  1219. msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
  1220. }
  1221. return 0;
  1222. }
  1223. /**
  1224. * lpfc_sli_ringtx_get - Get first element of the txq
  1225. * @phba: Pointer to HBA context object.
  1226. * @pring: Pointer to driver SLI ring object.
  1227. *
  1228. * This function is called with hbalock held to get next
  1229. * iocb in txq of the given ring. If there is any iocb in
  1230. * the txq, the function returns first iocb in the list after
  1231. * removing the iocb from the list, else it returns NULL.
  1232. **/
  1233. struct lpfc_iocbq *
  1234. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1235. {
  1236. struct lpfc_iocbq *cmd_iocb;
  1237. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1238. return cmd_iocb;
  1239. }
  1240. /**
  1241. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1242. * @phba: Pointer to HBA context object.
  1243. * @pring: Pointer to driver SLI ring object.
  1244. *
  1245. * This function is called with hbalock held and the caller must post the
  1246. * iocb without releasing the lock. If the caller releases the lock,
  1247. * iocb slot returned by the function is not guaranteed to be available.
  1248. * The function returns pointer to the next available iocb slot if there
  1249. * is available slot in the ring, else it returns NULL.
  1250. * If the get index of the ring is ahead of the put index, the function
  1251. * will post an error attention event to the worker thread to take the
  1252. * HBA to offline state.
  1253. **/
  1254. static IOCB_t *
  1255. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1256. {
  1257. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1258. uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
  1259. if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
  1260. (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
  1261. pring->sli.sli3.next_cmdidx = 0;
  1262. if (unlikely(pring->sli.sli3.local_getidx ==
  1263. pring->sli.sli3.next_cmdidx)) {
  1264. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1265. if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
  1266. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1267. "0315 Ring %d issue: portCmdGet %d "
  1268. "is bigger than cmd ring %d\n",
  1269. pring->ringno,
  1270. pring->sli.sli3.local_getidx,
  1271. max_cmd_idx);
  1272. phba->link_state = LPFC_HBA_ERROR;
  1273. /*
  1274. * All error attention handlers are posted to
  1275. * worker thread
  1276. */
  1277. phba->work_ha |= HA_ERATT;
  1278. phba->work_hs = HS_FFER3;
  1279. lpfc_worker_wake_up(phba);
  1280. return NULL;
  1281. }
  1282. if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
  1283. return NULL;
  1284. }
  1285. return lpfc_cmd_iocb(phba, pring);
  1286. }
  1287. /**
  1288. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1289. * @phba: Pointer to HBA context object.
  1290. * @iocbq: Pointer to driver iocb object.
  1291. *
  1292. * This function gets an iotag for the iocb. If there is no unused iotag and
  1293. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1294. * array and assigns a new iotag.
  1295. * The function returns the allocated iotag if successful, else returns zero.
  1296. * Zero is not a valid iotag.
  1297. * The caller is not required to hold any lock.
  1298. **/
  1299. uint16_t
  1300. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1301. {
  1302. struct lpfc_iocbq **new_arr;
  1303. struct lpfc_iocbq **old_arr;
  1304. size_t new_len;
  1305. struct lpfc_sli *psli = &phba->sli;
  1306. uint16_t iotag;
  1307. spin_lock_irq(&phba->hbalock);
  1308. iotag = psli->last_iotag;
  1309. if(++iotag < psli->iocbq_lookup_len) {
  1310. psli->last_iotag = iotag;
  1311. psli->iocbq_lookup[iotag] = iocbq;
  1312. spin_unlock_irq(&phba->hbalock);
  1313. iocbq->iotag = iotag;
  1314. return iotag;
  1315. } else if (psli->iocbq_lookup_len < (0xffff
  1316. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1317. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1318. spin_unlock_irq(&phba->hbalock);
  1319. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1320. GFP_KERNEL);
  1321. if (new_arr) {
  1322. spin_lock_irq(&phba->hbalock);
  1323. old_arr = psli->iocbq_lookup;
  1324. if (new_len <= psli->iocbq_lookup_len) {
  1325. /* highly unprobable case */
  1326. kfree(new_arr);
  1327. iotag = psli->last_iotag;
  1328. if(++iotag < psli->iocbq_lookup_len) {
  1329. psli->last_iotag = iotag;
  1330. psli->iocbq_lookup[iotag] = iocbq;
  1331. spin_unlock_irq(&phba->hbalock);
  1332. iocbq->iotag = iotag;
  1333. return iotag;
  1334. }
  1335. spin_unlock_irq(&phba->hbalock);
  1336. return 0;
  1337. }
  1338. if (psli->iocbq_lookup)
  1339. memcpy(new_arr, old_arr,
  1340. ((psli->last_iotag + 1) *
  1341. sizeof (struct lpfc_iocbq *)));
  1342. psli->iocbq_lookup = new_arr;
  1343. psli->iocbq_lookup_len = new_len;
  1344. psli->last_iotag = iotag;
  1345. psli->iocbq_lookup[iotag] = iocbq;
  1346. spin_unlock_irq(&phba->hbalock);
  1347. iocbq->iotag = iotag;
  1348. kfree(old_arr);
  1349. return iotag;
  1350. }
  1351. } else
  1352. spin_unlock_irq(&phba->hbalock);
  1353. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1354. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1355. psli->last_iotag);
  1356. return 0;
  1357. }
  1358. /**
  1359. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1360. * @phba: Pointer to HBA context object.
  1361. * @pring: Pointer to driver SLI ring object.
  1362. * @iocb: Pointer to iocb slot in the ring.
  1363. * @nextiocb: Pointer to driver iocb object which need to be
  1364. * posted to firmware.
  1365. *
  1366. * This function is called with hbalock held to post a new iocb to
  1367. * the firmware. This function copies the new iocb to ring iocb slot and
  1368. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1369. * a completion call back for this iocb else the function will free the
  1370. * iocb object.
  1371. **/
  1372. static void
  1373. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1374. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1375. {
  1376. /*
  1377. * Set up an iotag
  1378. */
  1379. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1380. if (pring->ringno == LPFC_ELS_RING) {
  1381. lpfc_debugfs_slow_ring_trc(phba,
  1382. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1383. *(((uint32_t *) &nextiocb->iocb) + 4),
  1384. *(((uint32_t *) &nextiocb->iocb) + 6),
  1385. *(((uint32_t *) &nextiocb->iocb) + 7));
  1386. }
  1387. /*
  1388. * Issue iocb command to adapter
  1389. */
  1390. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1391. wmb();
  1392. pring->stats.iocb_cmd++;
  1393. /*
  1394. * If there is no completion routine to call, we can release the
  1395. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1396. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1397. */
  1398. if (nextiocb->iocb_cmpl)
  1399. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1400. else
  1401. __lpfc_sli_release_iocbq(phba, nextiocb);
  1402. /*
  1403. * Let the HBA know what IOCB slot will be the next one the
  1404. * driver will put a command into.
  1405. */
  1406. pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
  1407. writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1408. }
  1409. /**
  1410. * lpfc_sli_update_full_ring - Update the chip attention register
  1411. * @phba: Pointer to HBA context object.
  1412. * @pring: Pointer to driver SLI ring object.
  1413. *
  1414. * The caller is not required to hold any lock for calling this function.
  1415. * This function updates the chip attention bits for the ring to inform firmware
  1416. * that there are pending work to be done for this ring and requests an
  1417. * interrupt when there is space available in the ring. This function is
  1418. * called when the driver is unable to post more iocbs to the ring due
  1419. * to unavailability of space in the ring.
  1420. **/
  1421. static void
  1422. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1423. {
  1424. int ringno = pring->ringno;
  1425. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1426. wmb();
  1427. /*
  1428. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1429. * The HBA will tell us when an IOCB entry is available.
  1430. */
  1431. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1432. readl(phba->CAregaddr); /* flush */
  1433. pring->stats.iocb_cmd_full++;
  1434. }
  1435. /**
  1436. * lpfc_sli_update_ring - Update chip attention register
  1437. * @phba: Pointer to HBA context object.
  1438. * @pring: Pointer to driver SLI ring object.
  1439. *
  1440. * This function updates the chip attention register bit for the
  1441. * given ring to inform HBA that there is more work to be done
  1442. * in this ring. The caller is not required to hold any lock.
  1443. **/
  1444. static void
  1445. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1446. {
  1447. int ringno = pring->ringno;
  1448. /*
  1449. * Tell the HBA that there is work to do in this ring.
  1450. */
  1451. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1452. wmb();
  1453. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1454. readl(phba->CAregaddr); /* flush */
  1455. }
  1456. }
  1457. /**
  1458. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1459. * @phba: Pointer to HBA context object.
  1460. * @pring: Pointer to driver SLI ring object.
  1461. *
  1462. * This function is called with hbalock held to post pending iocbs
  1463. * in the txq to the firmware. This function is called when driver
  1464. * detects space available in the ring.
  1465. **/
  1466. static void
  1467. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1468. {
  1469. IOCB_t *iocb;
  1470. struct lpfc_iocbq *nextiocb;
  1471. /*
  1472. * Check to see if:
  1473. * (a) there is anything on the txq to send
  1474. * (b) link is up
  1475. * (c) link attention events can be processed (fcp ring only)
  1476. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1477. */
  1478. if (lpfc_is_link_up(phba) &&
  1479. (!list_empty(&pring->txq)) &&
  1480. (pring->ringno != phba->sli.fcp_ring ||
  1481. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1482. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1483. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1484. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1485. if (iocb)
  1486. lpfc_sli_update_ring(phba, pring);
  1487. else
  1488. lpfc_sli_update_full_ring(phba, pring);
  1489. }
  1490. return;
  1491. }
  1492. /**
  1493. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1494. * @phba: Pointer to HBA context object.
  1495. * @hbqno: HBQ number.
  1496. *
  1497. * This function is called with hbalock held to get the next
  1498. * available slot for the given HBQ. If there is free slot
  1499. * available for the HBQ it will return pointer to the next available
  1500. * HBQ entry else it will return NULL.
  1501. **/
  1502. static struct lpfc_hbq_entry *
  1503. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1504. {
  1505. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1506. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1507. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1508. hbqp->next_hbqPutIdx = 0;
  1509. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1510. uint32_t raw_index = phba->hbq_get[hbqno];
  1511. uint32_t getidx = le32_to_cpu(raw_index);
  1512. hbqp->local_hbqGetIdx = getidx;
  1513. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1514. lpfc_printf_log(phba, KERN_ERR,
  1515. LOG_SLI | LOG_VPORT,
  1516. "1802 HBQ %d: local_hbqGetIdx "
  1517. "%u is > than hbqp->entry_count %u\n",
  1518. hbqno, hbqp->local_hbqGetIdx,
  1519. hbqp->entry_count);
  1520. phba->link_state = LPFC_HBA_ERROR;
  1521. return NULL;
  1522. }
  1523. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1524. return NULL;
  1525. }
  1526. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1527. hbqp->hbqPutIdx;
  1528. }
  1529. /**
  1530. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1531. * @phba: Pointer to HBA context object.
  1532. *
  1533. * This function is called with no lock held to free all the
  1534. * hbq buffers while uninitializing the SLI interface. It also
  1535. * frees the HBQ buffers returned by the firmware but not yet
  1536. * processed by the upper layers.
  1537. **/
  1538. void
  1539. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1540. {
  1541. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1542. struct hbq_dmabuf *hbq_buf;
  1543. unsigned long flags;
  1544. int i, hbq_count;
  1545. uint32_t hbqno;
  1546. hbq_count = lpfc_sli_hbq_count();
  1547. /* Return all memory used by all HBQs */
  1548. spin_lock_irqsave(&phba->hbalock, flags);
  1549. for (i = 0; i < hbq_count; ++i) {
  1550. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1551. &phba->hbqs[i].hbq_buffer_list, list) {
  1552. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1553. list_del(&hbq_buf->dbuf.list);
  1554. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1555. }
  1556. phba->hbqs[i].buffer_count = 0;
  1557. }
  1558. /* Return all HBQ buffer that are in-fly */
  1559. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1560. list) {
  1561. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1562. list_del(&hbq_buf->dbuf.list);
  1563. if (hbq_buf->tag == -1) {
  1564. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1565. (phba, hbq_buf);
  1566. } else {
  1567. hbqno = hbq_buf->tag >> 16;
  1568. if (hbqno >= LPFC_MAX_HBQS)
  1569. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1570. (phba, hbq_buf);
  1571. else
  1572. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1573. hbq_buf);
  1574. }
  1575. }
  1576. /* Mark the HBQs not in use */
  1577. phba->hbq_in_use = 0;
  1578. spin_unlock_irqrestore(&phba->hbalock, flags);
  1579. }
  1580. /**
  1581. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1582. * @phba: Pointer to HBA context object.
  1583. * @hbqno: HBQ number.
  1584. * @hbq_buf: Pointer to HBQ buffer.
  1585. *
  1586. * This function is called with the hbalock held to post a
  1587. * hbq buffer to the firmware. If the function finds an empty
  1588. * slot in the HBQ, it will post the buffer. The function will return
  1589. * pointer to the hbq entry if it successfully post the buffer
  1590. * else it will return NULL.
  1591. **/
  1592. static int
  1593. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1594. struct hbq_dmabuf *hbq_buf)
  1595. {
  1596. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1597. }
  1598. /**
  1599. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1600. * @phba: Pointer to HBA context object.
  1601. * @hbqno: HBQ number.
  1602. * @hbq_buf: Pointer to HBQ buffer.
  1603. *
  1604. * This function is called with the hbalock held to post a hbq buffer to the
  1605. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1606. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1607. * it successfully post the buffer else it will return an error.
  1608. **/
  1609. static int
  1610. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1611. struct hbq_dmabuf *hbq_buf)
  1612. {
  1613. struct lpfc_hbq_entry *hbqe;
  1614. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1615. /* Get next HBQ entry slot to use */
  1616. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1617. if (hbqe) {
  1618. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1619. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1620. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1621. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1622. hbqe->bde.tus.f.bdeFlags = 0;
  1623. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1624. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1625. /* Sync SLIM */
  1626. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1627. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1628. /* flush */
  1629. readl(phba->hbq_put + hbqno);
  1630. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1631. return 0;
  1632. } else
  1633. return -ENOMEM;
  1634. }
  1635. /**
  1636. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1637. * @phba: Pointer to HBA context object.
  1638. * @hbqno: HBQ number.
  1639. * @hbq_buf: Pointer to HBQ buffer.
  1640. *
  1641. * This function is called with the hbalock held to post an RQE to the SLI4
  1642. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1643. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1644. **/
  1645. static int
  1646. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1647. struct hbq_dmabuf *hbq_buf)
  1648. {
  1649. int rc;
  1650. struct lpfc_rqe hrqe;
  1651. struct lpfc_rqe drqe;
  1652. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1653. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1654. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1655. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1656. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1657. &hrqe, &drqe);
  1658. if (rc < 0)
  1659. return rc;
  1660. hbq_buf->tag = rc;
  1661. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1662. return 0;
  1663. }
  1664. /* HBQ for ELS and CT traffic. */
  1665. static struct lpfc_hbq_init lpfc_els_hbq = {
  1666. .rn = 1,
  1667. .entry_count = 256,
  1668. .mask_count = 0,
  1669. .profile = 0,
  1670. .ring_mask = (1 << LPFC_ELS_RING),
  1671. .buffer_count = 0,
  1672. .init_count = 40,
  1673. .add_count = 40,
  1674. };
  1675. /* HBQ for the extra ring if needed */
  1676. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1677. .rn = 1,
  1678. .entry_count = 200,
  1679. .mask_count = 0,
  1680. .profile = 0,
  1681. .ring_mask = (1 << LPFC_EXTRA_RING),
  1682. .buffer_count = 0,
  1683. .init_count = 0,
  1684. .add_count = 5,
  1685. };
  1686. /* Array of HBQs */
  1687. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1688. &lpfc_els_hbq,
  1689. &lpfc_extra_hbq,
  1690. };
  1691. /**
  1692. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1693. * @phba: Pointer to HBA context object.
  1694. * @hbqno: HBQ number.
  1695. * @count: Number of HBQ buffers to be posted.
  1696. *
  1697. * This function is called with no lock held to post more hbq buffers to the
  1698. * given HBQ. The function returns the number of HBQ buffers successfully
  1699. * posted.
  1700. **/
  1701. static int
  1702. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1703. {
  1704. uint32_t i, posted = 0;
  1705. unsigned long flags;
  1706. struct hbq_dmabuf *hbq_buffer;
  1707. LIST_HEAD(hbq_buf_list);
  1708. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1709. return 0;
  1710. if ((phba->hbqs[hbqno].buffer_count + count) >
  1711. lpfc_hbq_defs[hbqno]->entry_count)
  1712. count = lpfc_hbq_defs[hbqno]->entry_count -
  1713. phba->hbqs[hbqno].buffer_count;
  1714. if (!count)
  1715. return 0;
  1716. /* Allocate HBQ entries */
  1717. for (i = 0; i < count; i++) {
  1718. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1719. if (!hbq_buffer)
  1720. break;
  1721. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1722. }
  1723. /* Check whether HBQ is still in use */
  1724. spin_lock_irqsave(&phba->hbalock, flags);
  1725. if (!phba->hbq_in_use)
  1726. goto err;
  1727. while (!list_empty(&hbq_buf_list)) {
  1728. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1729. dbuf.list);
  1730. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1731. (hbqno << 16));
  1732. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1733. phba->hbqs[hbqno].buffer_count++;
  1734. posted++;
  1735. } else
  1736. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1737. }
  1738. spin_unlock_irqrestore(&phba->hbalock, flags);
  1739. return posted;
  1740. err:
  1741. spin_unlock_irqrestore(&phba->hbalock, flags);
  1742. while (!list_empty(&hbq_buf_list)) {
  1743. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1744. dbuf.list);
  1745. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1746. }
  1747. return 0;
  1748. }
  1749. /**
  1750. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1751. * @phba: Pointer to HBA context object.
  1752. * @qno: HBQ number.
  1753. *
  1754. * This function posts more buffers to the HBQ. This function
  1755. * is called with no lock held. The function returns the number of HBQ entries
  1756. * successfully allocated.
  1757. **/
  1758. int
  1759. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1760. {
  1761. if (phba->sli_rev == LPFC_SLI_REV4)
  1762. return 0;
  1763. else
  1764. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1765. lpfc_hbq_defs[qno]->add_count);
  1766. }
  1767. /**
  1768. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1769. * @phba: Pointer to HBA context object.
  1770. * @qno: HBQ queue number.
  1771. *
  1772. * This function is called from SLI initialization code path with
  1773. * no lock held to post initial HBQ buffers to firmware. The
  1774. * function returns the number of HBQ entries successfully allocated.
  1775. **/
  1776. static int
  1777. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1778. {
  1779. if (phba->sli_rev == LPFC_SLI_REV4)
  1780. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1781. lpfc_hbq_defs[qno]->entry_count);
  1782. else
  1783. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1784. lpfc_hbq_defs[qno]->init_count);
  1785. }
  1786. /**
  1787. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1788. * @phba: Pointer to HBA context object.
  1789. * @hbqno: HBQ number.
  1790. *
  1791. * This function removes the first hbq buffer on an hbq list and returns a
  1792. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1793. **/
  1794. static struct hbq_dmabuf *
  1795. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1796. {
  1797. struct lpfc_dmabuf *d_buf;
  1798. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1799. if (!d_buf)
  1800. return NULL;
  1801. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1802. }
  1803. /**
  1804. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1805. * @phba: Pointer to HBA context object.
  1806. * @tag: Tag of the hbq buffer.
  1807. *
  1808. * This function is called with hbalock held. This function searches
  1809. * for the hbq buffer associated with the given tag in the hbq buffer
  1810. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1811. * it returns NULL.
  1812. **/
  1813. static struct hbq_dmabuf *
  1814. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1815. {
  1816. struct lpfc_dmabuf *d_buf;
  1817. struct hbq_dmabuf *hbq_buf;
  1818. uint32_t hbqno;
  1819. hbqno = tag >> 16;
  1820. if (hbqno >= LPFC_MAX_HBQS)
  1821. return NULL;
  1822. spin_lock_irq(&phba->hbalock);
  1823. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1824. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1825. if (hbq_buf->tag == tag) {
  1826. spin_unlock_irq(&phba->hbalock);
  1827. return hbq_buf;
  1828. }
  1829. }
  1830. spin_unlock_irq(&phba->hbalock);
  1831. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1832. "1803 Bad hbq tag. Data: x%x x%x\n",
  1833. tag, phba->hbqs[tag >> 16].buffer_count);
  1834. return NULL;
  1835. }
  1836. /**
  1837. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1838. * @phba: Pointer to HBA context object.
  1839. * @hbq_buffer: Pointer to HBQ buffer.
  1840. *
  1841. * This function is called with hbalock. This function gives back
  1842. * the hbq buffer to firmware. If the HBQ does not have space to
  1843. * post the buffer, it will free the buffer.
  1844. **/
  1845. void
  1846. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1847. {
  1848. uint32_t hbqno;
  1849. if (hbq_buffer) {
  1850. hbqno = hbq_buffer->tag >> 16;
  1851. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1852. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1853. }
  1854. }
  1855. /**
  1856. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1857. * @mbxCommand: mailbox command code.
  1858. *
  1859. * This function is called by the mailbox event handler function to verify
  1860. * that the completed mailbox command is a legitimate mailbox command. If the
  1861. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1862. * and the mailbox event handler will take the HBA offline.
  1863. **/
  1864. static int
  1865. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1866. {
  1867. uint8_t ret;
  1868. switch (mbxCommand) {
  1869. case MBX_LOAD_SM:
  1870. case MBX_READ_NV:
  1871. case MBX_WRITE_NV:
  1872. case MBX_WRITE_VPARMS:
  1873. case MBX_RUN_BIU_DIAG:
  1874. case MBX_INIT_LINK:
  1875. case MBX_DOWN_LINK:
  1876. case MBX_CONFIG_LINK:
  1877. case MBX_CONFIG_RING:
  1878. case MBX_RESET_RING:
  1879. case MBX_READ_CONFIG:
  1880. case MBX_READ_RCONFIG:
  1881. case MBX_READ_SPARM:
  1882. case MBX_READ_STATUS:
  1883. case MBX_READ_RPI:
  1884. case MBX_READ_XRI:
  1885. case MBX_READ_REV:
  1886. case MBX_READ_LNK_STAT:
  1887. case MBX_REG_LOGIN:
  1888. case MBX_UNREG_LOGIN:
  1889. case MBX_CLEAR_LA:
  1890. case MBX_DUMP_MEMORY:
  1891. case MBX_DUMP_CONTEXT:
  1892. case MBX_RUN_DIAGS:
  1893. case MBX_RESTART:
  1894. case MBX_UPDATE_CFG:
  1895. case MBX_DOWN_LOAD:
  1896. case MBX_DEL_LD_ENTRY:
  1897. case MBX_RUN_PROGRAM:
  1898. case MBX_SET_MASK:
  1899. case MBX_SET_VARIABLE:
  1900. case MBX_UNREG_D_ID:
  1901. case MBX_KILL_BOARD:
  1902. case MBX_CONFIG_FARP:
  1903. case MBX_BEACON:
  1904. case MBX_LOAD_AREA:
  1905. case MBX_RUN_BIU_DIAG64:
  1906. case MBX_CONFIG_PORT:
  1907. case MBX_READ_SPARM64:
  1908. case MBX_READ_RPI64:
  1909. case MBX_REG_LOGIN64:
  1910. case MBX_READ_TOPOLOGY:
  1911. case MBX_WRITE_WWN:
  1912. case MBX_SET_DEBUG:
  1913. case MBX_LOAD_EXP_ROM:
  1914. case MBX_ASYNCEVT_ENABLE:
  1915. case MBX_REG_VPI:
  1916. case MBX_UNREG_VPI:
  1917. case MBX_HEARTBEAT:
  1918. case MBX_PORT_CAPABILITIES:
  1919. case MBX_PORT_IOV_CONTROL:
  1920. case MBX_SLI4_CONFIG:
  1921. case MBX_SLI4_REQ_FTRS:
  1922. case MBX_REG_FCFI:
  1923. case MBX_UNREG_FCFI:
  1924. case MBX_REG_VFI:
  1925. case MBX_UNREG_VFI:
  1926. case MBX_INIT_VPI:
  1927. case MBX_INIT_VFI:
  1928. case MBX_RESUME_RPI:
  1929. case MBX_READ_EVENT_LOG_STATUS:
  1930. case MBX_READ_EVENT_LOG:
  1931. case MBX_SECURITY_MGMT:
  1932. case MBX_AUTH_PORT:
  1933. case MBX_ACCESS_VDATA:
  1934. ret = mbxCommand;
  1935. break;
  1936. default:
  1937. ret = MBX_SHUTDOWN;
  1938. break;
  1939. }
  1940. return ret;
  1941. }
  1942. /**
  1943. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1944. * @phba: Pointer to HBA context object.
  1945. * @pmboxq: Pointer to mailbox command.
  1946. *
  1947. * This is completion handler function for mailbox commands issued from
  1948. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1949. * mailbox event handler function with no lock held. This function
  1950. * will wake up thread waiting on the wait queue pointed by context1
  1951. * of the mailbox.
  1952. **/
  1953. void
  1954. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1955. {
  1956. wait_queue_head_t *pdone_q;
  1957. unsigned long drvr_flag;
  1958. /*
  1959. * If pdone_q is empty, the driver thread gave up waiting and
  1960. * continued running.
  1961. */
  1962. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1963. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1964. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1965. if (pdone_q)
  1966. wake_up_interruptible(pdone_q);
  1967. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1968. return;
  1969. }
  1970. /**
  1971. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1972. * @phba: Pointer to HBA context object.
  1973. * @pmb: Pointer to mailbox object.
  1974. *
  1975. * This function is the default mailbox completion handler. It
  1976. * frees the memory resources associated with the completed mailbox
  1977. * command. If the completed command is a REG_LOGIN mailbox command,
  1978. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1979. **/
  1980. void
  1981. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1982. {
  1983. struct lpfc_vport *vport = pmb->vport;
  1984. struct lpfc_dmabuf *mp;
  1985. struct lpfc_nodelist *ndlp;
  1986. struct Scsi_Host *shost;
  1987. uint16_t rpi, vpi;
  1988. int rc;
  1989. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1990. if (mp) {
  1991. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1992. kfree(mp);
  1993. }
  1994. /*
  1995. * If a REG_LOGIN succeeded after node is destroyed or node
  1996. * is in re-discovery driver need to cleanup the RPI.
  1997. */
  1998. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1999. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  2000. !pmb->u.mb.mbxStatus) {
  2001. rpi = pmb->u.mb.un.varWords[0];
  2002. vpi = pmb->u.mb.un.varRegLogin.vpi;
  2003. lpfc_unreg_login(phba, vpi, rpi, pmb);
  2004. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2005. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2006. if (rc != MBX_NOT_FINISHED)
  2007. return;
  2008. }
  2009. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  2010. !(phba->pport->load_flag & FC_UNLOADING) &&
  2011. !pmb->u.mb.mbxStatus) {
  2012. shost = lpfc_shost_from_vport(vport);
  2013. spin_lock_irq(shost->host_lock);
  2014. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2015. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2016. spin_unlock_irq(shost->host_lock);
  2017. }
  2018. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  2019. ndlp = (struct lpfc_nodelist *)pmb->context2;
  2020. lpfc_nlp_put(ndlp);
  2021. pmb->context2 = NULL;
  2022. }
  2023. /* Check security permission status on INIT_LINK mailbox command */
  2024. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  2025. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  2026. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2027. "2860 SLI authentication is required "
  2028. "for INIT_LINK but has not done yet\n");
  2029. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  2030. lpfc_sli4_mbox_cmd_free(phba, pmb);
  2031. else
  2032. mempool_free(pmb, phba->mbox_mem_pool);
  2033. }
  2034. /**
  2035. * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
  2036. * @phba: Pointer to HBA context object.
  2037. * @pmb: Pointer to mailbox object.
  2038. *
  2039. * This function is the unreg rpi mailbox completion handler. It
  2040. * frees the memory resources associated with the completed mailbox
  2041. * command. An additional refrenece is put on the ndlp to prevent
  2042. * lpfc_nlp_release from freeing the rpi bit in the bitmask before
  2043. * the unreg mailbox command completes, this routine puts the
  2044. * reference back.
  2045. *
  2046. **/
  2047. void
  2048. lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2049. {
  2050. struct lpfc_vport *vport = pmb->vport;
  2051. struct lpfc_nodelist *ndlp;
  2052. ndlp = pmb->context1;
  2053. if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
  2054. if (phba->sli_rev == LPFC_SLI_REV4 &&
  2055. (bf_get(lpfc_sli_intf_if_type,
  2056. &phba->sli4_hba.sli_intf) ==
  2057. LPFC_SLI_INTF_IF_TYPE_2)) {
  2058. if (ndlp) {
  2059. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  2060. "0010 UNREG_LOGIN vpi:%x "
  2061. "rpi:%x DID:%x map:%x %p\n",
  2062. vport->vpi, ndlp->nlp_rpi,
  2063. ndlp->nlp_DID,
  2064. ndlp->nlp_usg_map, ndlp);
  2065. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2066. lpfc_nlp_put(ndlp);
  2067. }
  2068. }
  2069. }
  2070. mempool_free(pmb, phba->mbox_mem_pool);
  2071. }
  2072. /**
  2073. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2074. * @phba: Pointer to HBA context object.
  2075. *
  2076. * This function is called with no lock held. This function processes all
  2077. * the completed mailbox commands and gives it to upper layers. The interrupt
  2078. * service routine processes mailbox completion interrupt and adds completed
  2079. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2080. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2081. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2082. * function returns the mailbox commands to the upper layer by calling the
  2083. * completion handler function of each mailbox.
  2084. **/
  2085. int
  2086. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2087. {
  2088. MAILBOX_t *pmbox;
  2089. LPFC_MBOXQ_t *pmb;
  2090. int rc;
  2091. LIST_HEAD(cmplq);
  2092. phba->sli.slistat.mbox_event++;
  2093. /* Get all completed mailboxe buffers into the cmplq */
  2094. spin_lock_irq(&phba->hbalock);
  2095. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2096. spin_unlock_irq(&phba->hbalock);
  2097. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2098. do {
  2099. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2100. if (pmb == NULL)
  2101. break;
  2102. pmbox = &pmb->u.mb;
  2103. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2104. if (pmb->vport) {
  2105. lpfc_debugfs_disc_trc(pmb->vport,
  2106. LPFC_DISC_TRC_MBOX_VPORT,
  2107. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2108. (uint32_t)pmbox->mbxCommand,
  2109. pmbox->un.varWords[0],
  2110. pmbox->un.varWords[1]);
  2111. }
  2112. else {
  2113. lpfc_debugfs_disc_trc(phba->pport,
  2114. LPFC_DISC_TRC_MBOX,
  2115. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2116. (uint32_t)pmbox->mbxCommand,
  2117. pmbox->un.varWords[0],
  2118. pmbox->un.varWords[1]);
  2119. }
  2120. }
  2121. /*
  2122. * It is a fatal error if unknown mbox command completion.
  2123. */
  2124. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2125. MBX_SHUTDOWN) {
  2126. /* Unknown mailbox command compl */
  2127. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2128. "(%d):0323 Unknown Mailbox command "
  2129. "x%x (x%x/x%x) Cmpl\n",
  2130. pmb->vport ? pmb->vport->vpi : 0,
  2131. pmbox->mbxCommand,
  2132. lpfc_sli_config_mbox_subsys_get(phba,
  2133. pmb),
  2134. lpfc_sli_config_mbox_opcode_get(phba,
  2135. pmb));
  2136. phba->link_state = LPFC_HBA_ERROR;
  2137. phba->work_hs = HS_FFER3;
  2138. lpfc_handle_eratt(phba);
  2139. continue;
  2140. }
  2141. if (pmbox->mbxStatus) {
  2142. phba->sli.slistat.mbox_stat_err++;
  2143. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2144. /* Mbox cmd cmpl error - RETRYing */
  2145. lpfc_printf_log(phba, KERN_INFO,
  2146. LOG_MBOX | LOG_SLI,
  2147. "(%d):0305 Mbox cmd cmpl "
  2148. "error - RETRYing Data: x%x "
  2149. "(x%x/x%x) x%x x%x x%x\n",
  2150. pmb->vport ? pmb->vport->vpi : 0,
  2151. pmbox->mbxCommand,
  2152. lpfc_sli_config_mbox_subsys_get(phba,
  2153. pmb),
  2154. lpfc_sli_config_mbox_opcode_get(phba,
  2155. pmb),
  2156. pmbox->mbxStatus,
  2157. pmbox->un.varWords[0],
  2158. pmb->vport->port_state);
  2159. pmbox->mbxStatus = 0;
  2160. pmbox->mbxOwner = OWN_HOST;
  2161. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2162. if (rc != MBX_NOT_FINISHED)
  2163. continue;
  2164. }
  2165. }
  2166. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2167. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2168. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2169. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  2170. "x%x x%x x%x\n",
  2171. pmb->vport ? pmb->vport->vpi : 0,
  2172. pmbox->mbxCommand,
  2173. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2174. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2175. pmb->mbox_cmpl,
  2176. *((uint32_t *) pmbox),
  2177. pmbox->un.varWords[0],
  2178. pmbox->un.varWords[1],
  2179. pmbox->un.varWords[2],
  2180. pmbox->un.varWords[3],
  2181. pmbox->un.varWords[4],
  2182. pmbox->un.varWords[5],
  2183. pmbox->un.varWords[6],
  2184. pmbox->un.varWords[7],
  2185. pmbox->un.varWords[8],
  2186. pmbox->un.varWords[9],
  2187. pmbox->un.varWords[10]);
  2188. if (pmb->mbox_cmpl)
  2189. pmb->mbox_cmpl(phba,pmb);
  2190. } while (1);
  2191. return 0;
  2192. }
  2193. /**
  2194. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2195. * @phba: Pointer to HBA context object.
  2196. * @pring: Pointer to driver SLI ring object.
  2197. * @tag: buffer tag.
  2198. *
  2199. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2200. * is set in the tag the buffer is posted for a particular exchange,
  2201. * the function will return the buffer without replacing the buffer.
  2202. * If the buffer is for unsolicited ELS or CT traffic, this function
  2203. * returns the buffer and also posts another buffer to the firmware.
  2204. **/
  2205. static struct lpfc_dmabuf *
  2206. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2207. struct lpfc_sli_ring *pring,
  2208. uint32_t tag)
  2209. {
  2210. struct hbq_dmabuf *hbq_entry;
  2211. if (tag & QUE_BUFTAG_BIT)
  2212. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2213. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2214. if (!hbq_entry)
  2215. return NULL;
  2216. return &hbq_entry->dbuf;
  2217. }
  2218. /**
  2219. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2220. * @phba: Pointer to HBA context object.
  2221. * @pring: Pointer to driver SLI ring object.
  2222. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2223. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2224. * @fch_type: the type for the first frame of the sequence.
  2225. *
  2226. * This function is called with no lock held. This function uses the r_ctl and
  2227. * type of the received sequence to find the correct callback function to call
  2228. * to process the sequence.
  2229. **/
  2230. static int
  2231. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2232. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2233. uint32_t fch_type)
  2234. {
  2235. int i;
  2236. /* unSolicited Responses */
  2237. if (pring->prt[0].profile) {
  2238. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2239. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2240. saveq);
  2241. return 1;
  2242. }
  2243. /* We must search, based on rctl / type
  2244. for the right routine */
  2245. for (i = 0; i < pring->num_mask; i++) {
  2246. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2247. (pring->prt[i].type == fch_type)) {
  2248. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2249. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2250. (phba, pring, saveq);
  2251. return 1;
  2252. }
  2253. }
  2254. return 0;
  2255. }
  2256. /**
  2257. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2258. * @phba: Pointer to HBA context object.
  2259. * @pring: Pointer to driver SLI ring object.
  2260. * @saveq: Pointer to the unsolicited iocb.
  2261. *
  2262. * This function is called with no lock held by the ring event handler
  2263. * when there is an unsolicited iocb posted to the response ring by the
  2264. * firmware. This function gets the buffer associated with the iocbs
  2265. * and calls the event handler for the ring. This function handles both
  2266. * qring buffers and hbq buffers.
  2267. * When the function returns 1 the caller can free the iocb object otherwise
  2268. * upper layer functions will free the iocb objects.
  2269. **/
  2270. static int
  2271. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2272. struct lpfc_iocbq *saveq)
  2273. {
  2274. IOCB_t * irsp;
  2275. WORD5 * w5p;
  2276. uint32_t Rctl, Type;
  2277. struct lpfc_iocbq *iocbq;
  2278. struct lpfc_dmabuf *dmzbuf;
  2279. irsp = &(saveq->iocb);
  2280. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2281. if (pring->lpfc_sli_rcv_async_status)
  2282. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2283. else
  2284. lpfc_printf_log(phba,
  2285. KERN_WARNING,
  2286. LOG_SLI,
  2287. "0316 Ring %d handler: unexpected "
  2288. "ASYNC_STATUS iocb received evt_code "
  2289. "0x%x\n",
  2290. pring->ringno,
  2291. irsp->un.asyncstat.evt_code);
  2292. return 1;
  2293. }
  2294. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2295. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2296. if (irsp->ulpBdeCount > 0) {
  2297. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2298. irsp->un.ulpWord[3]);
  2299. lpfc_in_buf_free(phba, dmzbuf);
  2300. }
  2301. if (irsp->ulpBdeCount > 1) {
  2302. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2303. irsp->unsli3.sli3Words[3]);
  2304. lpfc_in_buf_free(phba, dmzbuf);
  2305. }
  2306. if (irsp->ulpBdeCount > 2) {
  2307. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2308. irsp->unsli3.sli3Words[7]);
  2309. lpfc_in_buf_free(phba, dmzbuf);
  2310. }
  2311. return 1;
  2312. }
  2313. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2314. if (irsp->ulpBdeCount != 0) {
  2315. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2316. irsp->un.ulpWord[3]);
  2317. if (!saveq->context2)
  2318. lpfc_printf_log(phba,
  2319. KERN_ERR,
  2320. LOG_SLI,
  2321. "0341 Ring %d Cannot find buffer for "
  2322. "an unsolicited iocb. tag 0x%x\n",
  2323. pring->ringno,
  2324. irsp->un.ulpWord[3]);
  2325. }
  2326. if (irsp->ulpBdeCount == 2) {
  2327. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2328. irsp->unsli3.sli3Words[7]);
  2329. if (!saveq->context3)
  2330. lpfc_printf_log(phba,
  2331. KERN_ERR,
  2332. LOG_SLI,
  2333. "0342 Ring %d Cannot find buffer for an"
  2334. " unsolicited iocb. tag 0x%x\n",
  2335. pring->ringno,
  2336. irsp->unsli3.sli3Words[7]);
  2337. }
  2338. list_for_each_entry(iocbq, &saveq->list, list) {
  2339. irsp = &(iocbq->iocb);
  2340. if (irsp->ulpBdeCount != 0) {
  2341. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2342. irsp->un.ulpWord[3]);
  2343. if (!iocbq->context2)
  2344. lpfc_printf_log(phba,
  2345. KERN_ERR,
  2346. LOG_SLI,
  2347. "0343 Ring %d Cannot find "
  2348. "buffer for an unsolicited iocb"
  2349. ". tag 0x%x\n", pring->ringno,
  2350. irsp->un.ulpWord[3]);
  2351. }
  2352. if (irsp->ulpBdeCount == 2) {
  2353. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2354. irsp->unsli3.sli3Words[7]);
  2355. if (!iocbq->context3)
  2356. lpfc_printf_log(phba,
  2357. KERN_ERR,
  2358. LOG_SLI,
  2359. "0344 Ring %d Cannot find "
  2360. "buffer for an unsolicited "
  2361. "iocb. tag 0x%x\n",
  2362. pring->ringno,
  2363. irsp->unsli3.sli3Words[7]);
  2364. }
  2365. }
  2366. }
  2367. if (irsp->ulpBdeCount != 0 &&
  2368. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2369. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2370. int found = 0;
  2371. /* search continue save q for same XRI */
  2372. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2373. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2374. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2375. list_add_tail(&saveq->list, &iocbq->list);
  2376. found = 1;
  2377. break;
  2378. }
  2379. }
  2380. if (!found)
  2381. list_add_tail(&saveq->clist,
  2382. &pring->iocb_continue_saveq);
  2383. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2384. list_del_init(&iocbq->clist);
  2385. saveq = iocbq;
  2386. irsp = &(saveq->iocb);
  2387. } else
  2388. return 0;
  2389. }
  2390. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2391. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2392. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2393. Rctl = FC_RCTL_ELS_REQ;
  2394. Type = FC_TYPE_ELS;
  2395. } else {
  2396. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2397. Rctl = w5p->hcsw.Rctl;
  2398. Type = w5p->hcsw.Type;
  2399. /* Firmware Workaround */
  2400. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2401. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2402. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2403. Rctl = FC_RCTL_ELS_REQ;
  2404. Type = FC_TYPE_ELS;
  2405. w5p->hcsw.Rctl = Rctl;
  2406. w5p->hcsw.Type = Type;
  2407. }
  2408. }
  2409. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2410. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2411. "0313 Ring %d handler: unexpected Rctl x%x "
  2412. "Type x%x received\n",
  2413. pring->ringno, Rctl, Type);
  2414. return 1;
  2415. }
  2416. /**
  2417. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2418. * @phba: Pointer to HBA context object.
  2419. * @pring: Pointer to driver SLI ring object.
  2420. * @prspiocb: Pointer to response iocb object.
  2421. *
  2422. * This function looks up the iocb_lookup table to get the command iocb
  2423. * corresponding to the given response iocb using the iotag of the
  2424. * response iocb. This function is called with the hbalock held.
  2425. * This function returns the command iocb object if it finds the command
  2426. * iocb else returns NULL.
  2427. **/
  2428. static struct lpfc_iocbq *
  2429. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2430. struct lpfc_sli_ring *pring,
  2431. struct lpfc_iocbq *prspiocb)
  2432. {
  2433. struct lpfc_iocbq *cmd_iocb = NULL;
  2434. uint16_t iotag;
  2435. iotag = prspiocb->iocb.ulpIoTag;
  2436. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2437. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2438. list_del_init(&cmd_iocb->list);
  2439. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2440. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2441. }
  2442. return cmd_iocb;
  2443. }
  2444. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2445. "0317 iotag x%x is out off "
  2446. "range: max iotag x%x wd0 x%x\n",
  2447. iotag, phba->sli.last_iotag,
  2448. *(((uint32_t *) &prspiocb->iocb) + 7));
  2449. return NULL;
  2450. }
  2451. /**
  2452. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2453. * @phba: Pointer to HBA context object.
  2454. * @pring: Pointer to driver SLI ring object.
  2455. * @iotag: IOCB tag.
  2456. *
  2457. * This function looks up the iocb_lookup table to get the command iocb
  2458. * corresponding to the given iotag. This function is called with the
  2459. * hbalock held.
  2460. * This function returns the command iocb object if it finds the command
  2461. * iocb else returns NULL.
  2462. **/
  2463. static struct lpfc_iocbq *
  2464. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2465. struct lpfc_sli_ring *pring, uint16_t iotag)
  2466. {
  2467. struct lpfc_iocbq *cmd_iocb;
  2468. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2469. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2470. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2471. /* remove from txcmpl queue list */
  2472. list_del_init(&cmd_iocb->list);
  2473. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2474. return cmd_iocb;
  2475. }
  2476. }
  2477. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2478. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2479. iotag, phba->sli.last_iotag);
  2480. return NULL;
  2481. }
  2482. /**
  2483. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2484. * @phba: Pointer to HBA context object.
  2485. * @pring: Pointer to driver SLI ring object.
  2486. * @saveq: Pointer to the response iocb to be processed.
  2487. *
  2488. * This function is called by the ring event handler for non-fcp
  2489. * rings when there is a new response iocb in the response ring.
  2490. * The caller is not required to hold any locks. This function
  2491. * gets the command iocb associated with the response iocb and
  2492. * calls the completion handler for the command iocb. If there
  2493. * is no completion handler, the function will free the resources
  2494. * associated with command iocb. If the response iocb is for
  2495. * an already aborted command iocb, the status of the completion
  2496. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2497. * This function always returns 1.
  2498. **/
  2499. static int
  2500. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2501. struct lpfc_iocbq *saveq)
  2502. {
  2503. struct lpfc_iocbq *cmdiocbp;
  2504. int rc = 1;
  2505. unsigned long iflag;
  2506. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2507. spin_lock_irqsave(&phba->hbalock, iflag);
  2508. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2509. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2510. if (cmdiocbp) {
  2511. if (cmdiocbp->iocb_cmpl) {
  2512. /*
  2513. * If an ELS command failed send an event to mgmt
  2514. * application.
  2515. */
  2516. if (saveq->iocb.ulpStatus &&
  2517. (pring->ringno == LPFC_ELS_RING) &&
  2518. (cmdiocbp->iocb.ulpCommand ==
  2519. CMD_ELS_REQUEST64_CR))
  2520. lpfc_send_els_failure_event(phba,
  2521. cmdiocbp, saveq);
  2522. /*
  2523. * Post all ELS completions to the worker thread.
  2524. * All other are passed to the completion callback.
  2525. */
  2526. if (pring->ringno == LPFC_ELS_RING) {
  2527. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2528. (cmdiocbp->iocb_flag &
  2529. LPFC_DRIVER_ABORTED)) {
  2530. spin_lock_irqsave(&phba->hbalock,
  2531. iflag);
  2532. cmdiocbp->iocb_flag &=
  2533. ~LPFC_DRIVER_ABORTED;
  2534. spin_unlock_irqrestore(&phba->hbalock,
  2535. iflag);
  2536. saveq->iocb.ulpStatus =
  2537. IOSTAT_LOCAL_REJECT;
  2538. saveq->iocb.un.ulpWord[4] =
  2539. IOERR_SLI_ABORTED;
  2540. /* Firmware could still be in progress
  2541. * of DMAing payload, so don't free data
  2542. * buffer till after a hbeat.
  2543. */
  2544. spin_lock_irqsave(&phba->hbalock,
  2545. iflag);
  2546. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2547. spin_unlock_irqrestore(&phba->hbalock,
  2548. iflag);
  2549. }
  2550. if (phba->sli_rev == LPFC_SLI_REV4) {
  2551. if (saveq->iocb_flag &
  2552. LPFC_EXCHANGE_BUSY) {
  2553. /* Set cmdiocb flag for the
  2554. * exchange busy so sgl (xri)
  2555. * will not be released until
  2556. * the abort xri is received
  2557. * from hba.
  2558. */
  2559. spin_lock_irqsave(
  2560. &phba->hbalock, iflag);
  2561. cmdiocbp->iocb_flag |=
  2562. LPFC_EXCHANGE_BUSY;
  2563. spin_unlock_irqrestore(
  2564. &phba->hbalock, iflag);
  2565. }
  2566. if (cmdiocbp->iocb_flag &
  2567. LPFC_DRIVER_ABORTED) {
  2568. /*
  2569. * Clear LPFC_DRIVER_ABORTED
  2570. * bit in case it was driver
  2571. * initiated abort.
  2572. */
  2573. spin_lock_irqsave(
  2574. &phba->hbalock, iflag);
  2575. cmdiocbp->iocb_flag &=
  2576. ~LPFC_DRIVER_ABORTED;
  2577. spin_unlock_irqrestore(
  2578. &phba->hbalock, iflag);
  2579. cmdiocbp->iocb.ulpStatus =
  2580. IOSTAT_LOCAL_REJECT;
  2581. cmdiocbp->iocb.un.ulpWord[4] =
  2582. IOERR_ABORT_REQUESTED;
  2583. /*
  2584. * For SLI4, irsiocb contains
  2585. * NO_XRI in sli_xritag, it
  2586. * shall not affect releasing
  2587. * sgl (xri) process.
  2588. */
  2589. saveq->iocb.ulpStatus =
  2590. IOSTAT_LOCAL_REJECT;
  2591. saveq->iocb.un.ulpWord[4] =
  2592. IOERR_SLI_ABORTED;
  2593. spin_lock_irqsave(
  2594. &phba->hbalock, iflag);
  2595. saveq->iocb_flag |=
  2596. LPFC_DELAY_MEM_FREE;
  2597. spin_unlock_irqrestore(
  2598. &phba->hbalock, iflag);
  2599. }
  2600. }
  2601. }
  2602. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2603. } else
  2604. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2605. } else {
  2606. /*
  2607. * Unknown initiating command based on the response iotag.
  2608. * This could be the case on the ELS ring because of
  2609. * lpfc_els_abort().
  2610. */
  2611. if (pring->ringno != LPFC_ELS_RING) {
  2612. /*
  2613. * Ring <ringno> handler: unexpected completion IoTag
  2614. * <IoTag>
  2615. */
  2616. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2617. "0322 Ring %d handler: "
  2618. "unexpected completion IoTag x%x "
  2619. "Data: x%x x%x x%x x%x\n",
  2620. pring->ringno,
  2621. saveq->iocb.ulpIoTag,
  2622. saveq->iocb.ulpStatus,
  2623. saveq->iocb.un.ulpWord[4],
  2624. saveq->iocb.ulpCommand,
  2625. saveq->iocb.ulpContext);
  2626. }
  2627. }
  2628. return rc;
  2629. }
  2630. /**
  2631. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2632. * @phba: Pointer to HBA context object.
  2633. * @pring: Pointer to driver SLI ring object.
  2634. *
  2635. * This function is called from the iocb ring event handlers when
  2636. * put pointer is ahead of the get pointer for a ring. This function signal
  2637. * an error attention condition to the worker thread and the worker
  2638. * thread will transition the HBA to offline state.
  2639. **/
  2640. static void
  2641. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2642. {
  2643. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2644. /*
  2645. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2646. * rsp ring <portRspMax>
  2647. */
  2648. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2649. "0312 Ring %d handler: portRspPut %d "
  2650. "is bigger than rsp ring %d\n",
  2651. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2652. pring->sli.sli3.numRiocb);
  2653. phba->link_state = LPFC_HBA_ERROR;
  2654. /*
  2655. * All error attention handlers are posted to
  2656. * worker thread
  2657. */
  2658. phba->work_ha |= HA_ERATT;
  2659. phba->work_hs = HS_FFER3;
  2660. lpfc_worker_wake_up(phba);
  2661. return;
  2662. }
  2663. /**
  2664. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2665. * @ptr: Pointer to address of HBA context object.
  2666. *
  2667. * This function is invoked by the Error Attention polling timer when the
  2668. * timer times out. It will check the SLI Error Attention register for
  2669. * possible attention events. If so, it will post an Error Attention event
  2670. * and wake up worker thread to process it. Otherwise, it will set up the
  2671. * Error Attention polling timer for the next poll.
  2672. **/
  2673. void lpfc_poll_eratt(unsigned long ptr)
  2674. {
  2675. struct lpfc_hba *phba;
  2676. uint32_t eratt = 0;
  2677. uint64_t sli_intr, cnt;
  2678. phba = (struct lpfc_hba *)ptr;
  2679. /* Here we will also keep track of interrupts per sec of the hba */
  2680. sli_intr = phba->sli.slistat.sli_intr;
  2681. if (phba->sli.slistat.sli_prev_intr > sli_intr)
  2682. cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
  2683. sli_intr);
  2684. else
  2685. cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
  2686. /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
  2687. do_div(cnt, LPFC_ERATT_POLL_INTERVAL);
  2688. phba->sli.slistat.sli_ips = cnt;
  2689. phba->sli.slistat.sli_prev_intr = sli_intr;
  2690. /* Check chip HA register for error event */
  2691. eratt = lpfc_sli_check_eratt(phba);
  2692. if (eratt)
  2693. /* Tell the worker thread there is work to do */
  2694. lpfc_worker_wake_up(phba);
  2695. else
  2696. /* Restart the timer for next eratt poll */
  2697. mod_timer(&phba->eratt_poll,
  2698. jiffies +
  2699. msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  2700. return;
  2701. }
  2702. /**
  2703. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2704. * @phba: Pointer to HBA context object.
  2705. * @pring: Pointer to driver SLI ring object.
  2706. * @mask: Host attention register mask for this ring.
  2707. *
  2708. * This function is called from the interrupt context when there is a ring
  2709. * event for the fcp ring. The caller does not hold any lock.
  2710. * The function processes each response iocb in the response ring until it
  2711. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2712. * LE bit set. The function will call the completion handler of the command iocb
  2713. * if the response iocb indicates a completion for a command iocb or it is
  2714. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2715. * function if this is an unsolicited iocb.
  2716. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2717. * to check it explicitly.
  2718. */
  2719. int
  2720. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2721. struct lpfc_sli_ring *pring, uint32_t mask)
  2722. {
  2723. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2724. IOCB_t *irsp = NULL;
  2725. IOCB_t *entry = NULL;
  2726. struct lpfc_iocbq *cmdiocbq = NULL;
  2727. struct lpfc_iocbq rspiocbq;
  2728. uint32_t status;
  2729. uint32_t portRspPut, portRspMax;
  2730. int rc = 1;
  2731. lpfc_iocb_type type;
  2732. unsigned long iflag;
  2733. uint32_t rsp_cmpl = 0;
  2734. spin_lock_irqsave(&phba->hbalock, iflag);
  2735. pring->stats.iocb_event++;
  2736. /*
  2737. * The next available response entry should never exceed the maximum
  2738. * entries. If it does, treat it as an adapter hardware error.
  2739. */
  2740. portRspMax = pring->sli.sli3.numRiocb;
  2741. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2742. if (unlikely(portRspPut >= portRspMax)) {
  2743. lpfc_sli_rsp_pointers_error(phba, pring);
  2744. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2745. return 1;
  2746. }
  2747. if (phba->fcp_ring_in_use) {
  2748. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2749. return 1;
  2750. } else
  2751. phba->fcp_ring_in_use = 1;
  2752. rmb();
  2753. while (pring->sli.sli3.rspidx != portRspPut) {
  2754. /*
  2755. * Fetch an entry off the ring and copy it into a local data
  2756. * structure. The copy involves a byte-swap since the
  2757. * network byte order and pci byte orders are different.
  2758. */
  2759. entry = lpfc_resp_iocb(phba, pring);
  2760. phba->last_completion_time = jiffies;
  2761. if (++pring->sli.sli3.rspidx >= portRspMax)
  2762. pring->sli.sli3.rspidx = 0;
  2763. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2764. (uint32_t *) &rspiocbq.iocb,
  2765. phba->iocb_rsp_size);
  2766. INIT_LIST_HEAD(&(rspiocbq.list));
  2767. irsp = &rspiocbq.iocb;
  2768. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2769. pring->stats.iocb_rsp++;
  2770. rsp_cmpl++;
  2771. if (unlikely(irsp->ulpStatus)) {
  2772. /*
  2773. * If resource errors reported from HBA, reduce
  2774. * queuedepths of the SCSI device.
  2775. */
  2776. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2777. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2778. IOERR_NO_RESOURCES)) {
  2779. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2780. phba->lpfc_rampdown_queue_depth(phba);
  2781. spin_lock_irqsave(&phba->hbalock, iflag);
  2782. }
  2783. /* Rsp ring <ringno> error: IOCB */
  2784. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2785. "0336 Rsp Ring %d error: IOCB Data: "
  2786. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2787. pring->ringno,
  2788. irsp->un.ulpWord[0],
  2789. irsp->un.ulpWord[1],
  2790. irsp->un.ulpWord[2],
  2791. irsp->un.ulpWord[3],
  2792. irsp->un.ulpWord[4],
  2793. irsp->un.ulpWord[5],
  2794. *(uint32_t *)&irsp->un1,
  2795. *((uint32_t *)&irsp->un1 + 1));
  2796. }
  2797. switch (type) {
  2798. case LPFC_ABORT_IOCB:
  2799. case LPFC_SOL_IOCB:
  2800. /*
  2801. * Idle exchange closed via ABTS from port. No iocb
  2802. * resources need to be recovered.
  2803. */
  2804. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2805. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2806. "0333 IOCB cmd 0x%x"
  2807. " processed. Skipping"
  2808. " completion\n",
  2809. irsp->ulpCommand);
  2810. break;
  2811. }
  2812. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2813. &rspiocbq);
  2814. if (unlikely(!cmdiocbq))
  2815. break;
  2816. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2817. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2818. if (cmdiocbq->iocb_cmpl) {
  2819. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2820. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2821. &rspiocbq);
  2822. spin_lock_irqsave(&phba->hbalock, iflag);
  2823. }
  2824. break;
  2825. case LPFC_UNSOL_IOCB:
  2826. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2827. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2828. spin_lock_irqsave(&phba->hbalock, iflag);
  2829. break;
  2830. default:
  2831. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2832. char adaptermsg[LPFC_MAX_ADPTMSG];
  2833. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2834. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2835. MAX_MSG_DATA);
  2836. dev_warn(&((phba->pcidev)->dev),
  2837. "lpfc%d: %s\n",
  2838. phba->brd_no, adaptermsg);
  2839. } else {
  2840. /* Unknown IOCB command */
  2841. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2842. "0334 Unknown IOCB command "
  2843. "Data: x%x, x%x x%x x%x x%x\n",
  2844. type, irsp->ulpCommand,
  2845. irsp->ulpStatus,
  2846. irsp->ulpIoTag,
  2847. irsp->ulpContext);
  2848. }
  2849. break;
  2850. }
  2851. /*
  2852. * The response IOCB has been processed. Update the ring
  2853. * pointer in SLIM. If the port response put pointer has not
  2854. * been updated, sync the pgp->rspPutInx and fetch the new port
  2855. * response put pointer.
  2856. */
  2857. writel(pring->sli.sli3.rspidx,
  2858. &phba->host_gp[pring->ringno].rspGetInx);
  2859. if (pring->sli.sli3.rspidx == portRspPut)
  2860. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2861. }
  2862. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2863. pring->stats.iocb_rsp_full++;
  2864. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2865. writel(status, phba->CAregaddr);
  2866. readl(phba->CAregaddr);
  2867. }
  2868. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2869. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2870. pring->stats.iocb_cmd_empty++;
  2871. /* Force update of the local copy of cmdGetInx */
  2872. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2873. lpfc_sli_resume_iocb(phba, pring);
  2874. if ((pring->lpfc_sli_cmd_available))
  2875. (pring->lpfc_sli_cmd_available) (phba, pring);
  2876. }
  2877. phba->fcp_ring_in_use = 0;
  2878. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2879. return rc;
  2880. }
  2881. /**
  2882. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2883. * @phba: Pointer to HBA context object.
  2884. * @pring: Pointer to driver SLI ring object.
  2885. * @rspiocbp: Pointer to driver response IOCB object.
  2886. *
  2887. * This function is called from the worker thread when there is a slow-path
  2888. * response IOCB to process. This function chains all the response iocbs until
  2889. * seeing the iocb with the LE bit set. The function will call
  2890. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2891. * completion of a command iocb. The function will call the
  2892. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2893. * The function frees the resources or calls the completion handler if this
  2894. * iocb is an abort completion. The function returns NULL when the response
  2895. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2896. * this function shall chain the iocb on to the iocb_continueq and return the
  2897. * response iocb passed in.
  2898. **/
  2899. static struct lpfc_iocbq *
  2900. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2901. struct lpfc_iocbq *rspiocbp)
  2902. {
  2903. struct lpfc_iocbq *saveq;
  2904. struct lpfc_iocbq *cmdiocbp;
  2905. struct lpfc_iocbq *next_iocb;
  2906. IOCB_t *irsp = NULL;
  2907. uint32_t free_saveq;
  2908. uint8_t iocb_cmd_type;
  2909. lpfc_iocb_type type;
  2910. unsigned long iflag;
  2911. int rc;
  2912. spin_lock_irqsave(&phba->hbalock, iflag);
  2913. /* First add the response iocb to the countinueq list */
  2914. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2915. pring->iocb_continueq_cnt++;
  2916. /* Now, determine whether the list is completed for processing */
  2917. irsp = &rspiocbp->iocb;
  2918. if (irsp->ulpLe) {
  2919. /*
  2920. * By default, the driver expects to free all resources
  2921. * associated with this iocb completion.
  2922. */
  2923. free_saveq = 1;
  2924. saveq = list_get_first(&pring->iocb_continueq,
  2925. struct lpfc_iocbq, list);
  2926. irsp = &(saveq->iocb);
  2927. list_del_init(&pring->iocb_continueq);
  2928. pring->iocb_continueq_cnt = 0;
  2929. pring->stats.iocb_rsp++;
  2930. /*
  2931. * If resource errors reported from HBA, reduce
  2932. * queuedepths of the SCSI device.
  2933. */
  2934. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2935. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2936. IOERR_NO_RESOURCES)) {
  2937. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2938. phba->lpfc_rampdown_queue_depth(phba);
  2939. spin_lock_irqsave(&phba->hbalock, iflag);
  2940. }
  2941. if (irsp->ulpStatus) {
  2942. /* Rsp ring <ringno> error: IOCB */
  2943. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2944. "0328 Rsp Ring %d error: "
  2945. "IOCB Data: "
  2946. "x%x x%x x%x x%x "
  2947. "x%x x%x x%x x%x "
  2948. "x%x x%x x%x x%x "
  2949. "x%x x%x x%x x%x\n",
  2950. pring->ringno,
  2951. irsp->un.ulpWord[0],
  2952. irsp->un.ulpWord[1],
  2953. irsp->un.ulpWord[2],
  2954. irsp->un.ulpWord[3],
  2955. irsp->un.ulpWord[4],
  2956. irsp->un.ulpWord[5],
  2957. *(((uint32_t *) irsp) + 6),
  2958. *(((uint32_t *) irsp) + 7),
  2959. *(((uint32_t *) irsp) + 8),
  2960. *(((uint32_t *) irsp) + 9),
  2961. *(((uint32_t *) irsp) + 10),
  2962. *(((uint32_t *) irsp) + 11),
  2963. *(((uint32_t *) irsp) + 12),
  2964. *(((uint32_t *) irsp) + 13),
  2965. *(((uint32_t *) irsp) + 14),
  2966. *(((uint32_t *) irsp) + 15));
  2967. }
  2968. /*
  2969. * Fetch the IOCB command type and call the correct completion
  2970. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2971. * get freed back to the lpfc_iocb_list by the discovery
  2972. * kernel thread.
  2973. */
  2974. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2975. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2976. switch (type) {
  2977. case LPFC_SOL_IOCB:
  2978. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2979. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2980. spin_lock_irqsave(&phba->hbalock, iflag);
  2981. break;
  2982. case LPFC_UNSOL_IOCB:
  2983. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2984. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2985. spin_lock_irqsave(&phba->hbalock, iflag);
  2986. if (!rc)
  2987. free_saveq = 0;
  2988. break;
  2989. case LPFC_ABORT_IOCB:
  2990. cmdiocbp = NULL;
  2991. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2992. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2993. saveq);
  2994. if (cmdiocbp) {
  2995. /* Call the specified completion routine */
  2996. if (cmdiocbp->iocb_cmpl) {
  2997. spin_unlock_irqrestore(&phba->hbalock,
  2998. iflag);
  2999. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  3000. saveq);
  3001. spin_lock_irqsave(&phba->hbalock,
  3002. iflag);
  3003. } else
  3004. __lpfc_sli_release_iocbq(phba,
  3005. cmdiocbp);
  3006. }
  3007. break;
  3008. case LPFC_UNKNOWN_IOCB:
  3009. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  3010. char adaptermsg[LPFC_MAX_ADPTMSG];
  3011. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  3012. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  3013. MAX_MSG_DATA);
  3014. dev_warn(&((phba->pcidev)->dev),
  3015. "lpfc%d: %s\n",
  3016. phba->brd_no, adaptermsg);
  3017. } else {
  3018. /* Unknown IOCB command */
  3019. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3020. "0335 Unknown IOCB "
  3021. "command Data: x%x "
  3022. "x%x x%x x%x\n",
  3023. irsp->ulpCommand,
  3024. irsp->ulpStatus,
  3025. irsp->ulpIoTag,
  3026. irsp->ulpContext);
  3027. }
  3028. break;
  3029. }
  3030. if (free_saveq) {
  3031. list_for_each_entry_safe(rspiocbp, next_iocb,
  3032. &saveq->list, list) {
  3033. list_del_init(&rspiocbp->list);
  3034. __lpfc_sli_release_iocbq(phba, rspiocbp);
  3035. }
  3036. __lpfc_sli_release_iocbq(phba, saveq);
  3037. }
  3038. rspiocbp = NULL;
  3039. }
  3040. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3041. return rspiocbp;
  3042. }
  3043. /**
  3044. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  3045. * @phba: Pointer to HBA context object.
  3046. * @pring: Pointer to driver SLI ring object.
  3047. * @mask: Host attention register mask for this ring.
  3048. *
  3049. * This routine wraps the actual slow_ring event process routine from the
  3050. * API jump table function pointer from the lpfc_hba struct.
  3051. **/
  3052. void
  3053. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  3054. struct lpfc_sli_ring *pring, uint32_t mask)
  3055. {
  3056. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  3057. }
  3058. /**
  3059. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  3060. * @phba: Pointer to HBA context object.
  3061. * @pring: Pointer to driver SLI ring object.
  3062. * @mask: Host attention register mask for this ring.
  3063. *
  3064. * This function is called from the worker thread when there is a ring event
  3065. * for non-fcp rings. The caller does not hold any lock. The function will
  3066. * remove each response iocb in the response ring and calls the handle
  3067. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3068. **/
  3069. static void
  3070. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  3071. struct lpfc_sli_ring *pring, uint32_t mask)
  3072. {
  3073. struct lpfc_pgp *pgp;
  3074. IOCB_t *entry;
  3075. IOCB_t *irsp = NULL;
  3076. struct lpfc_iocbq *rspiocbp = NULL;
  3077. uint32_t portRspPut, portRspMax;
  3078. unsigned long iflag;
  3079. uint32_t status;
  3080. pgp = &phba->port_gp[pring->ringno];
  3081. spin_lock_irqsave(&phba->hbalock, iflag);
  3082. pring->stats.iocb_event++;
  3083. /*
  3084. * The next available response entry should never exceed the maximum
  3085. * entries. If it does, treat it as an adapter hardware error.
  3086. */
  3087. portRspMax = pring->sli.sli3.numRiocb;
  3088. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3089. if (portRspPut >= portRspMax) {
  3090. /*
  3091. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3092. * rsp ring <portRspMax>
  3093. */
  3094. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3095. "0303 Ring %d handler: portRspPut %d "
  3096. "is bigger than rsp ring %d\n",
  3097. pring->ringno, portRspPut, portRspMax);
  3098. phba->link_state = LPFC_HBA_ERROR;
  3099. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3100. phba->work_hs = HS_FFER3;
  3101. lpfc_handle_eratt(phba);
  3102. return;
  3103. }
  3104. rmb();
  3105. while (pring->sli.sli3.rspidx != portRspPut) {
  3106. /*
  3107. * Build a completion list and call the appropriate handler.
  3108. * The process is to get the next available response iocb, get
  3109. * a free iocb from the list, copy the response data into the
  3110. * free iocb, insert to the continuation list, and update the
  3111. * next response index to slim. This process makes response
  3112. * iocb's in the ring available to DMA as fast as possible but
  3113. * pays a penalty for a copy operation. Since the iocb is
  3114. * only 32 bytes, this penalty is considered small relative to
  3115. * the PCI reads for register values and a slim write. When
  3116. * the ulpLe field is set, the entire Command has been
  3117. * received.
  3118. */
  3119. entry = lpfc_resp_iocb(phba, pring);
  3120. phba->last_completion_time = jiffies;
  3121. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3122. if (rspiocbp == NULL) {
  3123. printk(KERN_ERR "%s: out of buffers! Failing "
  3124. "completion.\n", __func__);
  3125. break;
  3126. }
  3127. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3128. phba->iocb_rsp_size);
  3129. irsp = &rspiocbp->iocb;
  3130. if (++pring->sli.sli3.rspidx >= portRspMax)
  3131. pring->sli.sli3.rspidx = 0;
  3132. if (pring->ringno == LPFC_ELS_RING) {
  3133. lpfc_debugfs_slow_ring_trc(phba,
  3134. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3135. *(((uint32_t *) irsp) + 4),
  3136. *(((uint32_t *) irsp) + 6),
  3137. *(((uint32_t *) irsp) + 7));
  3138. }
  3139. writel(pring->sli.sli3.rspidx,
  3140. &phba->host_gp[pring->ringno].rspGetInx);
  3141. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3142. /* Handle the response IOCB */
  3143. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3144. spin_lock_irqsave(&phba->hbalock, iflag);
  3145. /*
  3146. * If the port response put pointer has not been updated, sync
  3147. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3148. * response put pointer.
  3149. */
  3150. if (pring->sli.sli3.rspidx == portRspPut) {
  3151. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3152. }
  3153. } /* while (pring->sli.sli3.rspidx != portRspPut) */
  3154. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3155. /* At least one response entry has been freed */
  3156. pring->stats.iocb_rsp_full++;
  3157. /* SET RxRE_RSP in Chip Att register */
  3158. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3159. writel(status, phba->CAregaddr);
  3160. readl(phba->CAregaddr); /* flush */
  3161. }
  3162. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3163. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3164. pring->stats.iocb_cmd_empty++;
  3165. /* Force update of the local copy of cmdGetInx */
  3166. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3167. lpfc_sli_resume_iocb(phba, pring);
  3168. if ((pring->lpfc_sli_cmd_available))
  3169. (pring->lpfc_sli_cmd_available) (phba, pring);
  3170. }
  3171. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3172. return;
  3173. }
  3174. /**
  3175. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3176. * @phba: Pointer to HBA context object.
  3177. * @pring: Pointer to driver SLI ring object.
  3178. * @mask: Host attention register mask for this ring.
  3179. *
  3180. * This function is called from the worker thread when there is a pending
  3181. * ELS response iocb on the driver internal slow-path response iocb worker
  3182. * queue. The caller does not hold any lock. The function will remove each
  3183. * response iocb from the response worker queue and calls the handle
  3184. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3185. **/
  3186. static void
  3187. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3188. struct lpfc_sli_ring *pring, uint32_t mask)
  3189. {
  3190. struct lpfc_iocbq *irspiocbq;
  3191. struct hbq_dmabuf *dmabuf;
  3192. struct lpfc_cq_event *cq_event;
  3193. unsigned long iflag;
  3194. int count = 0;
  3195. spin_lock_irqsave(&phba->hbalock, iflag);
  3196. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3197. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3198. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3199. /* Get the response iocb from the head of work queue */
  3200. spin_lock_irqsave(&phba->hbalock, iflag);
  3201. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3202. cq_event, struct lpfc_cq_event, list);
  3203. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3204. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3205. case CQE_CODE_COMPL_WQE:
  3206. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3207. cq_event);
  3208. /* Translate ELS WCQE to response IOCBQ */
  3209. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3210. irspiocbq);
  3211. if (irspiocbq)
  3212. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3213. irspiocbq);
  3214. count++;
  3215. break;
  3216. case CQE_CODE_RECEIVE:
  3217. case CQE_CODE_RECEIVE_V1:
  3218. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3219. cq_event);
  3220. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3221. count++;
  3222. break;
  3223. default:
  3224. break;
  3225. }
  3226. /* Limit the number of events to 64 to avoid soft lockups */
  3227. if (count == 64)
  3228. break;
  3229. }
  3230. }
  3231. /**
  3232. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3233. * @phba: Pointer to HBA context object.
  3234. * @pring: Pointer to driver SLI ring object.
  3235. *
  3236. * This function aborts all iocbs in the given ring and frees all the iocb
  3237. * objects in txq. This function issues an abort iocb for all the iocb commands
  3238. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3239. * the return of this function. The caller is not required to hold any locks.
  3240. **/
  3241. void
  3242. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3243. {
  3244. LIST_HEAD(completions);
  3245. struct lpfc_iocbq *iocb, *next_iocb;
  3246. if (pring->ringno == LPFC_ELS_RING) {
  3247. lpfc_fabric_abort_hba(phba);
  3248. }
  3249. /* Error everything on txq and txcmplq
  3250. * First do the txq.
  3251. */
  3252. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3253. spin_lock_irq(&pring->ring_lock);
  3254. list_splice_init(&pring->txq, &completions);
  3255. pring->txq_cnt = 0;
  3256. spin_unlock_irq(&pring->ring_lock);
  3257. spin_lock_irq(&phba->hbalock);
  3258. /* Next issue ABTS for everything on the txcmplq */
  3259. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3260. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3261. spin_unlock_irq(&phba->hbalock);
  3262. } else {
  3263. spin_lock_irq(&phba->hbalock);
  3264. list_splice_init(&pring->txq, &completions);
  3265. pring->txq_cnt = 0;
  3266. /* Next issue ABTS for everything on the txcmplq */
  3267. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3268. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3269. spin_unlock_irq(&phba->hbalock);
  3270. }
  3271. /* Cancel all the IOCBs from the completions list */
  3272. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3273. IOERR_SLI_ABORTED);
  3274. }
  3275. /**
  3276. * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
  3277. * @phba: Pointer to HBA context object.
  3278. * @pring: Pointer to driver SLI ring object.
  3279. *
  3280. * This function aborts all iocbs in FCP rings and frees all the iocb
  3281. * objects in txq. This function issues an abort iocb for all the iocb commands
  3282. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3283. * the return of this function. The caller is not required to hold any locks.
  3284. **/
  3285. void
  3286. lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
  3287. {
  3288. struct lpfc_sli *psli = &phba->sli;
  3289. struct lpfc_sli_ring *pring;
  3290. uint32_t i;
  3291. /* Look on all the FCP Rings for the iotag */
  3292. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3293. for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
  3294. pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS];
  3295. lpfc_sli_abort_iocb_ring(phba, pring);
  3296. }
  3297. } else {
  3298. pring = &psli->ring[psli->fcp_ring];
  3299. lpfc_sli_abort_iocb_ring(phba, pring);
  3300. }
  3301. }
  3302. /**
  3303. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3304. * @phba: Pointer to HBA context object.
  3305. *
  3306. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3307. * objects in txq and txcmplq. This function will not issue abort iocbs
  3308. * for all the iocb commands in txcmplq, they will just be returned with
  3309. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3310. * slot has been permanently disabled.
  3311. **/
  3312. void
  3313. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3314. {
  3315. LIST_HEAD(txq);
  3316. LIST_HEAD(txcmplq);
  3317. struct lpfc_sli *psli = &phba->sli;
  3318. struct lpfc_sli_ring *pring;
  3319. uint32_t i;
  3320. spin_lock_irq(&phba->hbalock);
  3321. /* Indicate the I/O queues are flushed */
  3322. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3323. spin_unlock_irq(&phba->hbalock);
  3324. /* Look on all the FCP Rings for the iotag */
  3325. if (phba->sli_rev >= LPFC_SLI_REV4) {
  3326. for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
  3327. pring = &psli->ring[i + MAX_SLI3_CONFIGURED_RINGS];
  3328. spin_lock_irq(&pring->ring_lock);
  3329. /* Retrieve everything on txq */
  3330. list_splice_init(&pring->txq, &txq);
  3331. /* Retrieve everything on the txcmplq */
  3332. list_splice_init(&pring->txcmplq, &txcmplq);
  3333. pring->txq_cnt = 0;
  3334. pring->txcmplq_cnt = 0;
  3335. spin_unlock_irq(&pring->ring_lock);
  3336. /* Flush the txq */
  3337. lpfc_sli_cancel_iocbs(phba, &txq,
  3338. IOSTAT_LOCAL_REJECT,
  3339. IOERR_SLI_DOWN);
  3340. /* Flush the txcmpq */
  3341. lpfc_sli_cancel_iocbs(phba, &txcmplq,
  3342. IOSTAT_LOCAL_REJECT,
  3343. IOERR_SLI_DOWN);
  3344. }
  3345. } else {
  3346. pring = &psli->ring[psli->fcp_ring];
  3347. spin_lock_irq(&phba->hbalock);
  3348. /* Retrieve everything on txq */
  3349. list_splice_init(&pring->txq, &txq);
  3350. /* Retrieve everything on the txcmplq */
  3351. list_splice_init(&pring->txcmplq, &txcmplq);
  3352. pring->txq_cnt = 0;
  3353. pring->txcmplq_cnt = 0;
  3354. spin_unlock_irq(&phba->hbalock);
  3355. /* Flush the txq */
  3356. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3357. IOERR_SLI_DOWN);
  3358. /* Flush the txcmpq */
  3359. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3360. IOERR_SLI_DOWN);
  3361. }
  3362. }
  3363. /**
  3364. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3365. * @phba: Pointer to HBA context object.
  3366. * @mask: Bit mask to be checked.
  3367. *
  3368. * This function reads the host status register and compares
  3369. * with the provided bit mask to check if HBA completed
  3370. * the restart. This function will wait in a loop for the
  3371. * HBA to complete restart. If the HBA does not restart within
  3372. * 15 iterations, the function will reset the HBA again. The
  3373. * function returns 1 when HBA fail to restart otherwise returns
  3374. * zero.
  3375. **/
  3376. static int
  3377. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3378. {
  3379. uint32_t status;
  3380. int i = 0;
  3381. int retval = 0;
  3382. /* Read the HBA Host Status Register */
  3383. if (lpfc_readl(phba->HSregaddr, &status))
  3384. return 1;
  3385. /*
  3386. * Check status register every 100ms for 5 retries, then every
  3387. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3388. * every 2.5 sec for 4.
  3389. * Break our of the loop if errors occurred during init.
  3390. */
  3391. while (((status & mask) != mask) &&
  3392. !(status & HS_FFERM) &&
  3393. i++ < 20) {
  3394. if (i <= 5)
  3395. msleep(10);
  3396. else if (i <= 10)
  3397. msleep(500);
  3398. else
  3399. msleep(2500);
  3400. if (i == 15) {
  3401. /* Do post */
  3402. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3403. lpfc_sli_brdrestart(phba);
  3404. }
  3405. /* Read the HBA Host Status Register */
  3406. if (lpfc_readl(phba->HSregaddr, &status)) {
  3407. retval = 1;
  3408. break;
  3409. }
  3410. }
  3411. /* Check to see if any errors occurred during init */
  3412. if ((status & HS_FFERM) || (i >= 20)) {
  3413. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3414. "2751 Adapter failed to restart, "
  3415. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3416. status,
  3417. readl(phba->MBslimaddr + 0xa8),
  3418. readl(phba->MBslimaddr + 0xac));
  3419. phba->link_state = LPFC_HBA_ERROR;
  3420. retval = 1;
  3421. }
  3422. return retval;
  3423. }
  3424. /**
  3425. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3426. * @phba: Pointer to HBA context object.
  3427. * @mask: Bit mask to be checked.
  3428. *
  3429. * This function checks the host status register to check if HBA is
  3430. * ready. This function will wait in a loop for the HBA to be ready
  3431. * If the HBA is not ready , the function will will reset the HBA PCI
  3432. * function again. The function returns 1 when HBA fail to be ready
  3433. * otherwise returns zero.
  3434. **/
  3435. static int
  3436. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3437. {
  3438. uint32_t status;
  3439. int retval = 0;
  3440. /* Read the HBA Host Status Register */
  3441. status = lpfc_sli4_post_status_check(phba);
  3442. if (status) {
  3443. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3444. lpfc_sli_brdrestart(phba);
  3445. status = lpfc_sli4_post_status_check(phba);
  3446. }
  3447. /* Check to see if any errors occurred during init */
  3448. if (status) {
  3449. phba->link_state = LPFC_HBA_ERROR;
  3450. retval = 1;
  3451. } else
  3452. phba->sli4_hba.intr_enable = 0;
  3453. return retval;
  3454. }
  3455. /**
  3456. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3457. * @phba: Pointer to HBA context object.
  3458. * @mask: Bit mask to be checked.
  3459. *
  3460. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3461. * from the API jump table function pointer from the lpfc_hba struct.
  3462. **/
  3463. int
  3464. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3465. {
  3466. return phba->lpfc_sli_brdready(phba, mask);
  3467. }
  3468. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3469. /**
  3470. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3471. * @phba: Pointer to HBA context object.
  3472. *
  3473. * This function is called before resetting an HBA. This function is called
  3474. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3475. **/
  3476. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3477. {
  3478. uint32_t __iomem *resp_buf;
  3479. uint32_t __iomem *mbox_buf;
  3480. volatile uint32_t mbox;
  3481. uint32_t hc_copy, ha_copy, resp_data;
  3482. int i;
  3483. uint8_t hdrtype;
  3484. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3485. if (hdrtype != 0x80 ||
  3486. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3487. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3488. return;
  3489. /*
  3490. * Tell the other part of the chip to suspend temporarily all
  3491. * its DMA activity.
  3492. */
  3493. resp_buf = phba->MBslimaddr;
  3494. /* Disable the error attention */
  3495. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3496. return;
  3497. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3498. readl(phba->HCregaddr); /* flush */
  3499. phba->link_flag |= LS_IGNORE_ERATT;
  3500. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3501. return;
  3502. if (ha_copy & HA_ERATT) {
  3503. /* Clear Chip error bit */
  3504. writel(HA_ERATT, phba->HAregaddr);
  3505. phba->pport->stopped = 1;
  3506. }
  3507. mbox = 0;
  3508. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3509. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3510. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3511. mbox_buf = phba->MBslimaddr;
  3512. writel(mbox, mbox_buf);
  3513. for (i = 0; i < 50; i++) {
  3514. if (lpfc_readl((resp_buf + 1), &resp_data))
  3515. return;
  3516. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3517. mdelay(1);
  3518. else
  3519. break;
  3520. }
  3521. resp_data = 0;
  3522. if (lpfc_readl((resp_buf + 1), &resp_data))
  3523. return;
  3524. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3525. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3526. phba->pport->stopped)
  3527. goto restore_hc;
  3528. else
  3529. goto clear_errat;
  3530. }
  3531. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3532. resp_data = 0;
  3533. for (i = 0; i < 500; i++) {
  3534. if (lpfc_readl(resp_buf, &resp_data))
  3535. return;
  3536. if (resp_data != mbox)
  3537. mdelay(1);
  3538. else
  3539. break;
  3540. }
  3541. clear_errat:
  3542. while (++i < 500) {
  3543. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3544. return;
  3545. if (!(ha_copy & HA_ERATT))
  3546. mdelay(1);
  3547. else
  3548. break;
  3549. }
  3550. if (readl(phba->HAregaddr) & HA_ERATT) {
  3551. writel(HA_ERATT, phba->HAregaddr);
  3552. phba->pport->stopped = 1;
  3553. }
  3554. restore_hc:
  3555. phba->link_flag &= ~LS_IGNORE_ERATT;
  3556. writel(hc_copy, phba->HCregaddr);
  3557. readl(phba->HCregaddr); /* flush */
  3558. }
  3559. /**
  3560. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3561. * @phba: Pointer to HBA context object.
  3562. *
  3563. * This function issues a kill_board mailbox command and waits for
  3564. * the error attention interrupt. This function is called for stopping
  3565. * the firmware processing. The caller is not required to hold any
  3566. * locks. This function calls lpfc_hba_down_post function to free
  3567. * any pending commands after the kill. The function will return 1 when it
  3568. * fails to kill the board else will return 0.
  3569. **/
  3570. int
  3571. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3572. {
  3573. struct lpfc_sli *psli;
  3574. LPFC_MBOXQ_t *pmb;
  3575. uint32_t status;
  3576. uint32_t ha_copy;
  3577. int retval;
  3578. int i = 0;
  3579. psli = &phba->sli;
  3580. /* Kill HBA */
  3581. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3582. "0329 Kill HBA Data: x%x x%x\n",
  3583. phba->pport->port_state, psli->sli_flag);
  3584. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3585. if (!pmb)
  3586. return 1;
  3587. /* Disable the error attention */
  3588. spin_lock_irq(&phba->hbalock);
  3589. if (lpfc_readl(phba->HCregaddr, &status)) {
  3590. spin_unlock_irq(&phba->hbalock);
  3591. mempool_free(pmb, phba->mbox_mem_pool);
  3592. return 1;
  3593. }
  3594. status &= ~HC_ERINT_ENA;
  3595. writel(status, phba->HCregaddr);
  3596. readl(phba->HCregaddr); /* flush */
  3597. phba->link_flag |= LS_IGNORE_ERATT;
  3598. spin_unlock_irq(&phba->hbalock);
  3599. lpfc_kill_board(phba, pmb);
  3600. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3601. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3602. if (retval != MBX_SUCCESS) {
  3603. if (retval != MBX_BUSY)
  3604. mempool_free(pmb, phba->mbox_mem_pool);
  3605. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3606. "2752 KILL_BOARD command failed retval %d\n",
  3607. retval);
  3608. spin_lock_irq(&phba->hbalock);
  3609. phba->link_flag &= ~LS_IGNORE_ERATT;
  3610. spin_unlock_irq(&phba->hbalock);
  3611. return 1;
  3612. }
  3613. spin_lock_irq(&phba->hbalock);
  3614. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3615. spin_unlock_irq(&phba->hbalock);
  3616. mempool_free(pmb, phba->mbox_mem_pool);
  3617. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3618. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3619. * 3 seconds we still set HBA_ERROR state because the status of the
  3620. * board is now undefined.
  3621. */
  3622. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3623. return 1;
  3624. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3625. mdelay(100);
  3626. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3627. return 1;
  3628. }
  3629. del_timer_sync(&psli->mbox_tmo);
  3630. if (ha_copy & HA_ERATT) {
  3631. writel(HA_ERATT, phba->HAregaddr);
  3632. phba->pport->stopped = 1;
  3633. }
  3634. spin_lock_irq(&phba->hbalock);
  3635. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3636. psli->mbox_active = NULL;
  3637. phba->link_flag &= ~LS_IGNORE_ERATT;
  3638. spin_unlock_irq(&phba->hbalock);
  3639. lpfc_hba_down_post(phba);
  3640. phba->link_state = LPFC_HBA_ERROR;
  3641. return ha_copy & HA_ERATT ? 0 : 1;
  3642. }
  3643. /**
  3644. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3645. * @phba: Pointer to HBA context object.
  3646. *
  3647. * This function resets the HBA by writing HC_INITFF to the control
  3648. * register. After the HBA resets, this function resets all the iocb ring
  3649. * indices. This function disables PCI layer parity checking during
  3650. * the reset.
  3651. * This function returns 0 always.
  3652. * The caller is not required to hold any locks.
  3653. **/
  3654. int
  3655. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3656. {
  3657. struct lpfc_sli *psli;
  3658. struct lpfc_sli_ring *pring;
  3659. uint16_t cfg_value;
  3660. int i;
  3661. psli = &phba->sli;
  3662. /* Reset HBA */
  3663. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3664. "0325 Reset HBA Data: x%x x%x\n",
  3665. phba->pport->port_state, psli->sli_flag);
  3666. /* perform board reset */
  3667. phba->fc_eventTag = 0;
  3668. phba->link_events = 0;
  3669. phba->pport->fc_myDID = 0;
  3670. phba->pport->fc_prevDID = 0;
  3671. /* Turn off parity checking and serr during the physical reset */
  3672. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3673. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3674. (cfg_value &
  3675. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3676. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3677. /* Now toggle INITFF bit in the Host Control Register */
  3678. writel(HC_INITFF, phba->HCregaddr);
  3679. mdelay(1);
  3680. readl(phba->HCregaddr); /* flush */
  3681. writel(0, phba->HCregaddr);
  3682. readl(phba->HCregaddr); /* flush */
  3683. /* Restore PCI cmd register */
  3684. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3685. /* Initialize relevant SLI info */
  3686. for (i = 0; i < psli->num_rings; i++) {
  3687. pring = &psli->ring[i];
  3688. pring->flag = 0;
  3689. pring->sli.sli3.rspidx = 0;
  3690. pring->sli.sli3.next_cmdidx = 0;
  3691. pring->sli.sli3.local_getidx = 0;
  3692. pring->sli.sli3.cmdidx = 0;
  3693. pring->missbufcnt = 0;
  3694. }
  3695. phba->link_state = LPFC_WARM_START;
  3696. return 0;
  3697. }
  3698. /**
  3699. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3700. * @phba: Pointer to HBA context object.
  3701. *
  3702. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3703. * checking during resets the device. The caller is not required to hold
  3704. * any locks.
  3705. *
  3706. * This function returns 0 always.
  3707. **/
  3708. int
  3709. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3710. {
  3711. struct lpfc_sli *psli = &phba->sli;
  3712. uint16_t cfg_value;
  3713. int rc = 0;
  3714. /* Reset HBA */
  3715. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3716. "0295 Reset HBA Data: x%x x%x x%x\n",
  3717. phba->pport->port_state, psli->sli_flag,
  3718. phba->hba_flag);
  3719. /* perform board reset */
  3720. phba->fc_eventTag = 0;
  3721. phba->link_events = 0;
  3722. phba->pport->fc_myDID = 0;
  3723. phba->pport->fc_prevDID = 0;
  3724. spin_lock_irq(&phba->hbalock);
  3725. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3726. phba->fcf.fcf_flag = 0;
  3727. spin_unlock_irq(&phba->hbalock);
  3728. /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
  3729. if (phba->hba_flag & HBA_FW_DUMP_OP) {
  3730. phba->hba_flag &= ~HBA_FW_DUMP_OP;
  3731. return rc;
  3732. }
  3733. /* Now physically reset the device */
  3734. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3735. "0389 Performing PCI function reset!\n");
  3736. /* Turn off parity checking and serr during the physical reset */
  3737. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3738. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3739. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3740. /* Perform FCoE PCI function reset before freeing queue memory */
  3741. rc = lpfc_pci_function_reset(phba);
  3742. lpfc_sli4_queue_destroy(phba);
  3743. /* Restore PCI cmd register */
  3744. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3745. return rc;
  3746. }
  3747. /**
  3748. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3749. * @phba: Pointer to HBA context object.
  3750. *
  3751. * This function is called in the SLI initialization code path to
  3752. * restart the HBA. The caller is not required to hold any lock.
  3753. * This function writes MBX_RESTART mailbox command to the SLIM and
  3754. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3755. * function to free any pending commands. The function enables
  3756. * POST only during the first initialization. The function returns zero.
  3757. * The function does not guarantee completion of MBX_RESTART mailbox
  3758. * command before the return of this function.
  3759. **/
  3760. static int
  3761. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3762. {
  3763. MAILBOX_t *mb;
  3764. struct lpfc_sli *psli;
  3765. volatile uint32_t word0;
  3766. void __iomem *to_slim;
  3767. uint32_t hba_aer_enabled;
  3768. spin_lock_irq(&phba->hbalock);
  3769. /* Take PCIe device Advanced Error Reporting (AER) state */
  3770. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3771. psli = &phba->sli;
  3772. /* Restart HBA */
  3773. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3774. "0337 Restart HBA Data: x%x x%x\n",
  3775. phba->pport->port_state, psli->sli_flag);
  3776. word0 = 0;
  3777. mb = (MAILBOX_t *) &word0;
  3778. mb->mbxCommand = MBX_RESTART;
  3779. mb->mbxHc = 1;
  3780. lpfc_reset_barrier(phba);
  3781. to_slim = phba->MBslimaddr;
  3782. writel(*(uint32_t *) mb, to_slim);
  3783. readl(to_slim); /* flush */
  3784. /* Only skip post after fc_ffinit is completed */
  3785. if (phba->pport->port_state)
  3786. word0 = 1; /* This is really setting up word1 */
  3787. else
  3788. word0 = 0; /* This is really setting up word1 */
  3789. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3790. writel(*(uint32_t *) mb, to_slim);
  3791. readl(to_slim); /* flush */
  3792. lpfc_sli_brdreset(phba);
  3793. phba->pport->stopped = 0;
  3794. phba->link_state = LPFC_INIT_START;
  3795. phba->hba_flag = 0;
  3796. spin_unlock_irq(&phba->hbalock);
  3797. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3798. psli->stats_start = get_seconds();
  3799. /* Give the INITFF and Post time to settle. */
  3800. mdelay(100);
  3801. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3802. if (hba_aer_enabled)
  3803. pci_disable_pcie_error_reporting(phba->pcidev);
  3804. lpfc_hba_down_post(phba);
  3805. return 0;
  3806. }
  3807. /**
  3808. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3809. * @phba: Pointer to HBA context object.
  3810. *
  3811. * This function is called in the SLI initialization code path to restart
  3812. * a SLI4 HBA. The caller is not required to hold any lock.
  3813. * At the end of the function, it calls lpfc_hba_down_post function to
  3814. * free any pending commands.
  3815. **/
  3816. static int
  3817. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3818. {
  3819. struct lpfc_sli *psli = &phba->sli;
  3820. uint32_t hba_aer_enabled;
  3821. int rc;
  3822. /* Restart HBA */
  3823. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3824. "0296 Restart HBA Data: x%x x%x\n",
  3825. phba->pport->port_state, psli->sli_flag);
  3826. /* Take PCIe device Advanced Error Reporting (AER) state */
  3827. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3828. rc = lpfc_sli4_brdreset(phba);
  3829. spin_lock_irq(&phba->hbalock);
  3830. phba->pport->stopped = 0;
  3831. phba->link_state = LPFC_INIT_START;
  3832. phba->hba_flag = 0;
  3833. spin_unlock_irq(&phba->hbalock);
  3834. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3835. psli->stats_start = get_seconds();
  3836. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3837. if (hba_aer_enabled)
  3838. pci_disable_pcie_error_reporting(phba->pcidev);
  3839. lpfc_hba_down_post(phba);
  3840. return rc;
  3841. }
  3842. /**
  3843. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3844. * @phba: Pointer to HBA context object.
  3845. *
  3846. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3847. * API jump table function pointer from the lpfc_hba struct.
  3848. **/
  3849. int
  3850. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3851. {
  3852. return phba->lpfc_sli_brdrestart(phba);
  3853. }
  3854. /**
  3855. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3856. * @phba: Pointer to HBA context object.
  3857. *
  3858. * This function is called after a HBA restart to wait for successful
  3859. * restart of the HBA. Successful restart of the HBA is indicated by
  3860. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3861. * iteration, the function will restart the HBA again. The function returns
  3862. * zero if HBA successfully restarted else returns negative error code.
  3863. **/
  3864. static int
  3865. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3866. {
  3867. uint32_t status, i = 0;
  3868. /* Read the HBA Host Status Register */
  3869. if (lpfc_readl(phba->HSregaddr, &status))
  3870. return -EIO;
  3871. /* Check status register to see what current state is */
  3872. i = 0;
  3873. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3874. /* Check every 10ms for 10 retries, then every 100ms for 90
  3875. * retries, then every 1 sec for 50 retires for a total of
  3876. * ~60 seconds before reset the board again and check every
  3877. * 1 sec for 50 retries. The up to 60 seconds before the
  3878. * board ready is required by the Falcon FIPS zeroization
  3879. * complete, and any reset the board in between shall cause
  3880. * restart of zeroization, further delay the board ready.
  3881. */
  3882. if (i++ >= 200) {
  3883. /* Adapter failed to init, timeout, status reg
  3884. <status> */
  3885. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3886. "0436 Adapter failed to init, "
  3887. "timeout, status reg x%x, "
  3888. "FW Data: A8 x%x AC x%x\n", status,
  3889. readl(phba->MBslimaddr + 0xa8),
  3890. readl(phba->MBslimaddr + 0xac));
  3891. phba->link_state = LPFC_HBA_ERROR;
  3892. return -ETIMEDOUT;
  3893. }
  3894. /* Check to see if any errors occurred during init */
  3895. if (status & HS_FFERM) {
  3896. /* ERROR: During chipset initialization */
  3897. /* Adapter failed to init, chipset, status reg
  3898. <status> */
  3899. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3900. "0437 Adapter failed to init, "
  3901. "chipset, status reg x%x, "
  3902. "FW Data: A8 x%x AC x%x\n", status,
  3903. readl(phba->MBslimaddr + 0xa8),
  3904. readl(phba->MBslimaddr + 0xac));
  3905. phba->link_state = LPFC_HBA_ERROR;
  3906. return -EIO;
  3907. }
  3908. if (i <= 10)
  3909. msleep(10);
  3910. else if (i <= 100)
  3911. msleep(100);
  3912. else
  3913. msleep(1000);
  3914. if (i == 150) {
  3915. /* Do post */
  3916. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3917. lpfc_sli_brdrestart(phba);
  3918. }
  3919. /* Read the HBA Host Status Register */
  3920. if (lpfc_readl(phba->HSregaddr, &status))
  3921. return -EIO;
  3922. }
  3923. /* Check to see if any errors occurred during init */
  3924. if (status & HS_FFERM) {
  3925. /* ERROR: During chipset initialization */
  3926. /* Adapter failed to init, chipset, status reg <status> */
  3927. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3928. "0438 Adapter failed to init, chipset, "
  3929. "status reg x%x, "
  3930. "FW Data: A8 x%x AC x%x\n", status,
  3931. readl(phba->MBslimaddr + 0xa8),
  3932. readl(phba->MBslimaddr + 0xac));
  3933. phba->link_state = LPFC_HBA_ERROR;
  3934. return -EIO;
  3935. }
  3936. /* Clear all interrupt enable conditions */
  3937. writel(0, phba->HCregaddr);
  3938. readl(phba->HCregaddr); /* flush */
  3939. /* setup host attn register */
  3940. writel(0xffffffff, phba->HAregaddr);
  3941. readl(phba->HAregaddr); /* flush */
  3942. return 0;
  3943. }
  3944. /**
  3945. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3946. *
  3947. * This function calculates and returns the number of HBQs required to be
  3948. * configured.
  3949. **/
  3950. int
  3951. lpfc_sli_hbq_count(void)
  3952. {
  3953. return ARRAY_SIZE(lpfc_hbq_defs);
  3954. }
  3955. /**
  3956. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3957. *
  3958. * This function adds the number of hbq entries in every HBQ to get
  3959. * the total number of hbq entries required for the HBA and returns
  3960. * the total count.
  3961. **/
  3962. static int
  3963. lpfc_sli_hbq_entry_count(void)
  3964. {
  3965. int hbq_count = lpfc_sli_hbq_count();
  3966. int count = 0;
  3967. int i;
  3968. for (i = 0; i < hbq_count; ++i)
  3969. count += lpfc_hbq_defs[i]->entry_count;
  3970. return count;
  3971. }
  3972. /**
  3973. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3974. *
  3975. * This function calculates amount of memory required for all hbq entries
  3976. * to be configured and returns the total memory required.
  3977. **/
  3978. int
  3979. lpfc_sli_hbq_size(void)
  3980. {
  3981. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3982. }
  3983. /**
  3984. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3985. * @phba: Pointer to HBA context object.
  3986. *
  3987. * This function is called during the SLI initialization to configure
  3988. * all the HBQs and post buffers to the HBQ. The caller is not
  3989. * required to hold any locks. This function will return zero if successful
  3990. * else it will return negative error code.
  3991. **/
  3992. static int
  3993. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3994. {
  3995. int hbq_count = lpfc_sli_hbq_count();
  3996. LPFC_MBOXQ_t *pmb;
  3997. MAILBOX_t *pmbox;
  3998. uint32_t hbqno;
  3999. uint32_t hbq_entry_index;
  4000. /* Get a Mailbox buffer to setup mailbox
  4001. * commands for HBA initialization
  4002. */
  4003. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4004. if (!pmb)
  4005. return -ENOMEM;
  4006. pmbox = &pmb->u.mb;
  4007. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  4008. phba->link_state = LPFC_INIT_MBX_CMDS;
  4009. phba->hbq_in_use = 1;
  4010. hbq_entry_index = 0;
  4011. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  4012. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  4013. phba->hbqs[hbqno].hbqPutIdx = 0;
  4014. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  4015. phba->hbqs[hbqno].entry_count =
  4016. lpfc_hbq_defs[hbqno]->entry_count;
  4017. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  4018. hbq_entry_index, pmb);
  4019. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  4020. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  4021. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  4022. mbxStatus <status>, ring <num> */
  4023. lpfc_printf_log(phba, KERN_ERR,
  4024. LOG_SLI | LOG_VPORT,
  4025. "1805 Adapter failed to init. "
  4026. "Data: x%x x%x x%x\n",
  4027. pmbox->mbxCommand,
  4028. pmbox->mbxStatus, hbqno);
  4029. phba->link_state = LPFC_HBA_ERROR;
  4030. mempool_free(pmb, phba->mbox_mem_pool);
  4031. return -ENXIO;
  4032. }
  4033. }
  4034. phba->hbq_count = hbq_count;
  4035. mempool_free(pmb, phba->mbox_mem_pool);
  4036. /* Initially populate or replenish the HBQs */
  4037. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  4038. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  4039. return 0;
  4040. }
  4041. /**
  4042. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  4043. * @phba: Pointer to HBA context object.
  4044. *
  4045. * This function is called during the SLI initialization to configure
  4046. * all the HBQs and post buffers to the HBQ. The caller is not
  4047. * required to hold any locks. This function will return zero if successful
  4048. * else it will return negative error code.
  4049. **/
  4050. static int
  4051. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  4052. {
  4053. phba->hbq_in_use = 1;
  4054. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  4055. phba->hbq_count = 1;
  4056. /* Initially populate or replenish the HBQs */
  4057. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  4058. return 0;
  4059. }
  4060. /**
  4061. * lpfc_sli_config_port - Issue config port mailbox command
  4062. * @phba: Pointer to HBA context object.
  4063. * @sli_mode: sli mode - 2/3
  4064. *
  4065. * This function is called by the sli intialization code path
  4066. * to issue config_port mailbox command. This function restarts the
  4067. * HBA firmware and issues a config_port mailbox command to configure
  4068. * the SLI interface in the sli mode specified by sli_mode
  4069. * variable. The caller is not required to hold any locks.
  4070. * The function returns 0 if successful, else returns negative error
  4071. * code.
  4072. **/
  4073. int
  4074. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  4075. {
  4076. LPFC_MBOXQ_t *pmb;
  4077. uint32_t resetcount = 0, rc = 0, done = 0;
  4078. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4079. if (!pmb) {
  4080. phba->link_state = LPFC_HBA_ERROR;
  4081. return -ENOMEM;
  4082. }
  4083. phba->sli_rev = sli_mode;
  4084. while (resetcount < 2 && !done) {
  4085. spin_lock_irq(&phba->hbalock);
  4086. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  4087. spin_unlock_irq(&phba->hbalock);
  4088. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  4089. lpfc_sli_brdrestart(phba);
  4090. rc = lpfc_sli_chipset_init(phba);
  4091. if (rc)
  4092. break;
  4093. spin_lock_irq(&phba->hbalock);
  4094. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4095. spin_unlock_irq(&phba->hbalock);
  4096. resetcount++;
  4097. /* Call pre CONFIG_PORT mailbox command initialization. A
  4098. * value of 0 means the call was successful. Any other
  4099. * nonzero value is a failure, but if ERESTART is returned,
  4100. * the driver may reset the HBA and try again.
  4101. */
  4102. rc = lpfc_config_port_prep(phba);
  4103. if (rc == -ERESTART) {
  4104. phba->link_state = LPFC_LINK_UNKNOWN;
  4105. continue;
  4106. } else if (rc)
  4107. break;
  4108. phba->link_state = LPFC_INIT_MBX_CMDS;
  4109. lpfc_config_port(phba, pmb);
  4110. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4111. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  4112. LPFC_SLI3_HBQ_ENABLED |
  4113. LPFC_SLI3_CRP_ENABLED |
  4114. LPFC_SLI3_BG_ENABLED |
  4115. LPFC_SLI3_DSS_ENABLED);
  4116. if (rc != MBX_SUCCESS) {
  4117. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4118. "0442 Adapter failed to init, mbxCmd x%x "
  4119. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  4120. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  4121. spin_lock_irq(&phba->hbalock);
  4122. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  4123. spin_unlock_irq(&phba->hbalock);
  4124. rc = -ENXIO;
  4125. } else {
  4126. /* Allow asynchronous mailbox command to go through */
  4127. spin_lock_irq(&phba->hbalock);
  4128. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4129. spin_unlock_irq(&phba->hbalock);
  4130. done = 1;
  4131. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  4132. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  4133. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4134. "3110 Port did not grant ASABT\n");
  4135. }
  4136. }
  4137. if (!done) {
  4138. rc = -EINVAL;
  4139. goto do_prep_failed;
  4140. }
  4141. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  4142. if (!pmb->u.mb.un.varCfgPort.cMA) {
  4143. rc = -ENXIO;
  4144. goto do_prep_failed;
  4145. }
  4146. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  4147. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  4148. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  4149. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  4150. phba->max_vpi : phba->max_vports;
  4151. } else
  4152. phba->max_vpi = 0;
  4153. phba->fips_level = 0;
  4154. phba->fips_spec_rev = 0;
  4155. if (pmb->u.mb.un.varCfgPort.gdss) {
  4156. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  4157. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  4158. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  4159. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4160. "2850 Security Crypto Active. FIPS x%d "
  4161. "(Spec Rev: x%d)",
  4162. phba->fips_level, phba->fips_spec_rev);
  4163. }
  4164. if (pmb->u.mb.un.varCfgPort.sec_err) {
  4165. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4166. "2856 Config Port Security Crypto "
  4167. "Error: x%x ",
  4168. pmb->u.mb.un.varCfgPort.sec_err);
  4169. }
  4170. if (pmb->u.mb.un.varCfgPort.gerbm)
  4171. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  4172. if (pmb->u.mb.un.varCfgPort.gcrp)
  4173. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  4174. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  4175. phba->port_gp = phba->mbox->us.s3_pgp.port;
  4176. if (phba->cfg_enable_bg) {
  4177. if (pmb->u.mb.un.varCfgPort.gbg)
  4178. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  4179. else
  4180. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4181. "0443 Adapter did not grant "
  4182. "BlockGuard\n");
  4183. }
  4184. } else {
  4185. phba->hbq_get = NULL;
  4186. phba->port_gp = phba->mbox->us.s2.port;
  4187. phba->max_vpi = 0;
  4188. }
  4189. do_prep_failed:
  4190. mempool_free(pmb, phba->mbox_mem_pool);
  4191. return rc;
  4192. }
  4193. /**
  4194. * lpfc_sli_hba_setup - SLI intialization function
  4195. * @phba: Pointer to HBA context object.
  4196. *
  4197. * This function is the main SLI intialization function. This function
  4198. * is called by the HBA intialization code, HBA reset code and HBA
  4199. * error attention handler code. Caller is not required to hold any
  4200. * locks. This function issues config_port mailbox command to configure
  4201. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4202. * calls the config_port_post function to issue init_link mailbox
  4203. * command and to start the discovery. The function will return zero
  4204. * if successful, else it will return negative error code.
  4205. **/
  4206. int
  4207. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4208. {
  4209. uint32_t rc;
  4210. int mode = 3, i;
  4211. int longs;
  4212. switch (lpfc_sli_mode) {
  4213. case 2:
  4214. if (phba->cfg_enable_npiv) {
  4215. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4216. "1824 NPIV enabled: Override lpfc_sli_mode "
  4217. "parameter (%d) to auto (0).\n",
  4218. lpfc_sli_mode);
  4219. break;
  4220. }
  4221. mode = 2;
  4222. break;
  4223. case 0:
  4224. case 3:
  4225. break;
  4226. default:
  4227. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4228. "1819 Unrecognized lpfc_sli_mode "
  4229. "parameter: %d.\n", lpfc_sli_mode);
  4230. break;
  4231. }
  4232. rc = lpfc_sli_config_port(phba, mode);
  4233. if (rc && lpfc_sli_mode == 3)
  4234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4235. "1820 Unable to select SLI-3. "
  4236. "Not supported by adapter.\n");
  4237. if (rc && mode != 2)
  4238. rc = lpfc_sli_config_port(phba, 2);
  4239. if (rc)
  4240. goto lpfc_sli_hba_setup_error;
  4241. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4242. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4243. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4244. if (!rc) {
  4245. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4246. "2709 This device supports "
  4247. "Advanced Error Reporting (AER)\n");
  4248. spin_lock_irq(&phba->hbalock);
  4249. phba->hba_flag |= HBA_AER_ENABLED;
  4250. spin_unlock_irq(&phba->hbalock);
  4251. } else {
  4252. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4253. "2708 This device does not support "
  4254. "Advanced Error Reporting (AER): %d\n",
  4255. rc);
  4256. phba->cfg_aer_support = 0;
  4257. }
  4258. }
  4259. if (phba->sli_rev == 3) {
  4260. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4261. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4262. } else {
  4263. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4264. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4265. phba->sli3_options = 0;
  4266. }
  4267. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4268. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4269. phba->sli_rev, phba->max_vpi);
  4270. rc = lpfc_sli_ring_map(phba);
  4271. if (rc)
  4272. goto lpfc_sli_hba_setup_error;
  4273. /* Initialize VPIs. */
  4274. if (phba->sli_rev == LPFC_SLI_REV3) {
  4275. /*
  4276. * The VPI bitmask and physical ID array are allocated
  4277. * and initialized once only - at driver load. A port
  4278. * reset doesn't need to reinitialize this memory.
  4279. */
  4280. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4281. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4282. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4283. GFP_KERNEL);
  4284. if (!phba->vpi_bmask) {
  4285. rc = -ENOMEM;
  4286. goto lpfc_sli_hba_setup_error;
  4287. }
  4288. phba->vpi_ids = kzalloc(
  4289. (phba->max_vpi+1) * sizeof(uint16_t),
  4290. GFP_KERNEL);
  4291. if (!phba->vpi_ids) {
  4292. kfree(phba->vpi_bmask);
  4293. rc = -ENOMEM;
  4294. goto lpfc_sli_hba_setup_error;
  4295. }
  4296. for (i = 0; i < phba->max_vpi; i++)
  4297. phba->vpi_ids[i] = i;
  4298. }
  4299. }
  4300. /* Init HBQs */
  4301. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4302. rc = lpfc_sli_hbq_setup(phba);
  4303. if (rc)
  4304. goto lpfc_sli_hba_setup_error;
  4305. }
  4306. spin_lock_irq(&phba->hbalock);
  4307. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4308. spin_unlock_irq(&phba->hbalock);
  4309. rc = lpfc_config_port_post(phba);
  4310. if (rc)
  4311. goto lpfc_sli_hba_setup_error;
  4312. return rc;
  4313. lpfc_sli_hba_setup_error:
  4314. phba->link_state = LPFC_HBA_ERROR;
  4315. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4316. "0445 Firmware initialization failed\n");
  4317. return rc;
  4318. }
  4319. /**
  4320. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4321. * @phba: Pointer to HBA context object.
  4322. * @mboxq: mailbox pointer.
  4323. * This function issue a dump mailbox command to read config region
  4324. * 23 and parse the records in the region and populate driver
  4325. * data structure.
  4326. **/
  4327. static int
  4328. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4329. {
  4330. LPFC_MBOXQ_t *mboxq;
  4331. struct lpfc_dmabuf *mp;
  4332. struct lpfc_mqe *mqe;
  4333. uint32_t data_length;
  4334. int rc;
  4335. /* Program the default value of vlan_id and fc_map */
  4336. phba->valid_vlan = 0;
  4337. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4338. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4339. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4340. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4341. if (!mboxq)
  4342. return -ENOMEM;
  4343. mqe = &mboxq->u.mqe;
  4344. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4345. rc = -ENOMEM;
  4346. goto out_free_mboxq;
  4347. }
  4348. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4349. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4350. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4351. "(%d):2571 Mailbox cmd x%x Status x%x "
  4352. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4353. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4354. "CQ: x%x x%x x%x x%x\n",
  4355. mboxq->vport ? mboxq->vport->vpi : 0,
  4356. bf_get(lpfc_mqe_command, mqe),
  4357. bf_get(lpfc_mqe_status, mqe),
  4358. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4359. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4360. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4361. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4362. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4363. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4364. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4365. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4366. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4367. mboxq->mcqe.word0,
  4368. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4369. mboxq->mcqe.trailer);
  4370. if (rc) {
  4371. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4372. kfree(mp);
  4373. rc = -EIO;
  4374. goto out_free_mboxq;
  4375. }
  4376. data_length = mqe->un.mb_words[5];
  4377. if (data_length > DMP_RGN23_SIZE) {
  4378. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4379. kfree(mp);
  4380. rc = -EIO;
  4381. goto out_free_mboxq;
  4382. }
  4383. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4384. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4385. kfree(mp);
  4386. rc = 0;
  4387. out_free_mboxq:
  4388. mempool_free(mboxq, phba->mbox_mem_pool);
  4389. return rc;
  4390. }
  4391. /**
  4392. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4393. * @phba: pointer to lpfc hba data structure.
  4394. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4395. * @vpd: pointer to the memory to hold resulting port vpd data.
  4396. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4397. * On output, the number of data bytes in @vpd.
  4398. *
  4399. * This routine executes a READ_REV SLI4 mailbox command. In
  4400. * addition, this routine gets the port vpd data.
  4401. *
  4402. * Return codes
  4403. * 0 - successful
  4404. * -ENOMEM - could not allocated memory.
  4405. **/
  4406. static int
  4407. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4408. uint8_t *vpd, uint32_t *vpd_size)
  4409. {
  4410. int rc = 0;
  4411. uint32_t dma_size;
  4412. struct lpfc_dmabuf *dmabuf;
  4413. struct lpfc_mqe *mqe;
  4414. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4415. if (!dmabuf)
  4416. return -ENOMEM;
  4417. /*
  4418. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4419. * mailbox command.
  4420. */
  4421. dma_size = *vpd_size;
  4422. dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size,
  4423. &dmabuf->phys, GFP_KERNEL);
  4424. if (!dmabuf->virt) {
  4425. kfree(dmabuf);
  4426. return -ENOMEM;
  4427. }
  4428. /*
  4429. * The SLI4 implementation of READ_REV conflicts at word1,
  4430. * bits 31:16 and SLI4 adds vpd functionality not present
  4431. * in SLI3. This code corrects the conflicts.
  4432. */
  4433. lpfc_read_rev(phba, mboxq);
  4434. mqe = &mboxq->u.mqe;
  4435. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4436. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4437. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4438. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4439. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4440. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4441. if (rc) {
  4442. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4443. dmabuf->virt, dmabuf->phys);
  4444. kfree(dmabuf);
  4445. return -EIO;
  4446. }
  4447. /*
  4448. * The available vpd length cannot be bigger than the
  4449. * DMA buffer passed to the port. Catch the less than
  4450. * case and update the caller's size.
  4451. */
  4452. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4453. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4454. memcpy(vpd, dmabuf->virt, *vpd_size);
  4455. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4456. dmabuf->virt, dmabuf->phys);
  4457. kfree(dmabuf);
  4458. return 0;
  4459. }
  4460. /**
  4461. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4462. * @phba: pointer to lpfc hba data structure.
  4463. *
  4464. * This routine retrieves SLI4 device physical port name this PCI function
  4465. * is attached to.
  4466. *
  4467. * Return codes
  4468. * 0 - successful
  4469. * otherwise - failed to retrieve physical port name
  4470. **/
  4471. static int
  4472. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4473. {
  4474. LPFC_MBOXQ_t *mboxq;
  4475. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4476. struct lpfc_controller_attribute *cntl_attr;
  4477. struct lpfc_mbx_get_port_name *get_port_name;
  4478. void *virtaddr = NULL;
  4479. uint32_t alloclen, reqlen;
  4480. uint32_t shdr_status, shdr_add_status;
  4481. union lpfc_sli4_cfg_shdr *shdr;
  4482. char cport_name = 0;
  4483. int rc;
  4484. /* We assume nothing at this point */
  4485. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4486. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4487. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4488. if (!mboxq)
  4489. return -ENOMEM;
  4490. /* obtain link type and link number via READ_CONFIG */
  4491. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4492. lpfc_sli4_read_config(phba);
  4493. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4494. goto retrieve_ppname;
  4495. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4496. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4497. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4498. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4499. LPFC_SLI4_MBX_NEMBED);
  4500. if (alloclen < reqlen) {
  4501. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4502. "3084 Allocated DMA memory size (%d) is "
  4503. "less than the requested DMA memory size "
  4504. "(%d)\n", alloclen, reqlen);
  4505. rc = -ENOMEM;
  4506. goto out_free_mboxq;
  4507. }
  4508. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4509. virtaddr = mboxq->sge_array->addr[0];
  4510. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4511. shdr = &mbx_cntl_attr->cfg_shdr;
  4512. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4513. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4514. if (shdr_status || shdr_add_status || rc) {
  4515. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4516. "3085 Mailbox x%x (x%x/x%x) failed, "
  4517. "rc:x%x, status:x%x, add_status:x%x\n",
  4518. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4519. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4520. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4521. rc, shdr_status, shdr_add_status);
  4522. rc = -ENXIO;
  4523. goto out_free_mboxq;
  4524. }
  4525. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4526. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4527. phba->sli4_hba.lnk_info.lnk_tp =
  4528. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4529. phba->sli4_hba.lnk_info.lnk_no =
  4530. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4531. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4532. "3086 lnk_type:%d, lnk_numb:%d\n",
  4533. phba->sli4_hba.lnk_info.lnk_tp,
  4534. phba->sli4_hba.lnk_info.lnk_no);
  4535. retrieve_ppname:
  4536. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4537. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4538. sizeof(struct lpfc_mbx_get_port_name) -
  4539. sizeof(struct lpfc_sli4_cfg_mhdr),
  4540. LPFC_SLI4_MBX_EMBED);
  4541. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4542. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4543. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4544. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4545. phba->sli4_hba.lnk_info.lnk_tp);
  4546. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4547. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4548. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4549. if (shdr_status || shdr_add_status || rc) {
  4550. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4551. "3087 Mailbox x%x (x%x/x%x) failed: "
  4552. "rc:x%x, status:x%x, add_status:x%x\n",
  4553. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4554. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4555. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4556. rc, shdr_status, shdr_add_status);
  4557. rc = -ENXIO;
  4558. goto out_free_mboxq;
  4559. }
  4560. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4561. case LPFC_LINK_NUMBER_0:
  4562. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4563. &get_port_name->u.response);
  4564. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4565. break;
  4566. case LPFC_LINK_NUMBER_1:
  4567. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4568. &get_port_name->u.response);
  4569. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4570. break;
  4571. case LPFC_LINK_NUMBER_2:
  4572. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4573. &get_port_name->u.response);
  4574. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4575. break;
  4576. case LPFC_LINK_NUMBER_3:
  4577. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4578. &get_port_name->u.response);
  4579. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4580. break;
  4581. default:
  4582. break;
  4583. }
  4584. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4585. phba->Port[0] = cport_name;
  4586. phba->Port[1] = '\0';
  4587. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4588. "3091 SLI get port name: %s\n", phba->Port);
  4589. }
  4590. out_free_mboxq:
  4591. if (rc != MBX_TIMEOUT) {
  4592. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4593. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4594. else
  4595. mempool_free(mboxq, phba->mbox_mem_pool);
  4596. }
  4597. return rc;
  4598. }
  4599. /**
  4600. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4601. * @phba: pointer to lpfc hba data structure.
  4602. *
  4603. * This routine is called to explicitly arm the SLI4 device's completion and
  4604. * event queues
  4605. **/
  4606. static void
  4607. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4608. {
  4609. int fcp_eqidx;
  4610. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4611. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4612. fcp_eqidx = 0;
  4613. if (phba->sli4_hba.fcp_cq) {
  4614. do {
  4615. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4616. LPFC_QUEUE_REARM);
  4617. } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
  4618. }
  4619. if (phba->cfg_fof)
  4620. lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM);
  4621. if (phba->sli4_hba.hba_eq) {
  4622. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
  4623. fcp_eqidx++)
  4624. lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
  4625. LPFC_QUEUE_REARM);
  4626. }
  4627. if (phba->cfg_fof)
  4628. lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM);
  4629. }
  4630. /**
  4631. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4632. * @phba: Pointer to HBA context object.
  4633. * @type: The resource extent type.
  4634. * @extnt_count: buffer to hold port available extent count.
  4635. * @extnt_size: buffer to hold element count per extent.
  4636. *
  4637. * This function calls the port and retrievs the number of available
  4638. * extents and their size for a particular extent type.
  4639. *
  4640. * Returns: 0 if successful. Nonzero otherwise.
  4641. **/
  4642. int
  4643. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4644. uint16_t *extnt_count, uint16_t *extnt_size)
  4645. {
  4646. int rc = 0;
  4647. uint32_t length;
  4648. uint32_t mbox_tmo;
  4649. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4650. LPFC_MBOXQ_t *mbox;
  4651. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4652. if (!mbox)
  4653. return -ENOMEM;
  4654. /* Find out how many extents are available for this resource type */
  4655. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4656. sizeof(struct lpfc_sli4_cfg_mhdr));
  4657. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4658. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4659. length, LPFC_SLI4_MBX_EMBED);
  4660. /* Send an extents count of 0 - the GET doesn't use it. */
  4661. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4662. LPFC_SLI4_MBX_EMBED);
  4663. if (unlikely(rc)) {
  4664. rc = -EIO;
  4665. goto err_exit;
  4666. }
  4667. if (!phba->sli4_hba.intr_enable)
  4668. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4669. else {
  4670. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4671. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4672. }
  4673. if (unlikely(rc)) {
  4674. rc = -EIO;
  4675. goto err_exit;
  4676. }
  4677. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4678. if (bf_get(lpfc_mbox_hdr_status,
  4679. &rsrc_info->header.cfg_shdr.response)) {
  4680. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4681. "2930 Failed to get resource extents "
  4682. "Status 0x%x Add'l Status 0x%x\n",
  4683. bf_get(lpfc_mbox_hdr_status,
  4684. &rsrc_info->header.cfg_shdr.response),
  4685. bf_get(lpfc_mbox_hdr_add_status,
  4686. &rsrc_info->header.cfg_shdr.response));
  4687. rc = -EIO;
  4688. goto err_exit;
  4689. }
  4690. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4691. &rsrc_info->u.rsp);
  4692. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4693. &rsrc_info->u.rsp);
  4694. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4695. "3162 Retrieved extents type-%d from port: count:%d, "
  4696. "size:%d\n", type, *extnt_count, *extnt_size);
  4697. err_exit:
  4698. mempool_free(mbox, phba->mbox_mem_pool);
  4699. return rc;
  4700. }
  4701. /**
  4702. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4703. * @phba: Pointer to HBA context object.
  4704. * @type: The extent type to check.
  4705. *
  4706. * This function reads the current available extents from the port and checks
  4707. * if the extent count or extent size has changed since the last access.
  4708. * Callers use this routine post port reset to understand if there is a
  4709. * extent reprovisioning requirement.
  4710. *
  4711. * Returns:
  4712. * -Error: error indicates problem.
  4713. * 1: Extent count or size has changed.
  4714. * 0: No changes.
  4715. **/
  4716. static int
  4717. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4718. {
  4719. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4720. uint16_t size_diff, rsrc_ext_size;
  4721. int rc = 0;
  4722. struct lpfc_rsrc_blks *rsrc_entry;
  4723. struct list_head *rsrc_blk_list = NULL;
  4724. size_diff = 0;
  4725. curr_ext_cnt = 0;
  4726. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4727. &rsrc_ext_cnt,
  4728. &rsrc_ext_size);
  4729. if (unlikely(rc))
  4730. return -EIO;
  4731. switch (type) {
  4732. case LPFC_RSC_TYPE_FCOE_RPI:
  4733. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4734. break;
  4735. case LPFC_RSC_TYPE_FCOE_VPI:
  4736. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4737. break;
  4738. case LPFC_RSC_TYPE_FCOE_XRI:
  4739. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4740. break;
  4741. case LPFC_RSC_TYPE_FCOE_VFI:
  4742. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4743. break;
  4744. default:
  4745. break;
  4746. }
  4747. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4748. curr_ext_cnt++;
  4749. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4750. size_diff++;
  4751. }
  4752. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4753. rc = 1;
  4754. return rc;
  4755. }
  4756. /**
  4757. * lpfc_sli4_cfg_post_extnts -
  4758. * @phba: Pointer to HBA context object.
  4759. * @extnt_cnt - number of available extents.
  4760. * @type - the extent type (rpi, xri, vfi, vpi).
  4761. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4762. * @mbox - pointer to the caller's allocated mailbox structure.
  4763. *
  4764. * This function executes the extents allocation request. It also
  4765. * takes care of the amount of memory needed to allocate or get the
  4766. * allocated extents. It is the caller's responsibility to evaluate
  4767. * the response.
  4768. *
  4769. * Returns:
  4770. * -Error: Error value describes the condition found.
  4771. * 0: if successful
  4772. **/
  4773. static int
  4774. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4775. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4776. {
  4777. int rc = 0;
  4778. uint32_t req_len;
  4779. uint32_t emb_len;
  4780. uint32_t alloc_len, mbox_tmo;
  4781. /* Calculate the total requested length of the dma memory */
  4782. req_len = extnt_cnt * sizeof(uint16_t);
  4783. /*
  4784. * Calculate the size of an embedded mailbox. The uint32_t
  4785. * accounts for extents-specific word.
  4786. */
  4787. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4788. sizeof(uint32_t);
  4789. /*
  4790. * Presume the allocation and response will fit into an embedded
  4791. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4792. */
  4793. *emb = LPFC_SLI4_MBX_EMBED;
  4794. if (req_len > emb_len) {
  4795. req_len = extnt_cnt * sizeof(uint16_t) +
  4796. sizeof(union lpfc_sli4_cfg_shdr) +
  4797. sizeof(uint32_t);
  4798. *emb = LPFC_SLI4_MBX_NEMBED;
  4799. }
  4800. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4801. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4802. req_len, *emb);
  4803. if (alloc_len < req_len) {
  4804. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4805. "2982 Allocated DMA memory size (x%x) is "
  4806. "less than the requested DMA memory "
  4807. "size (x%x)\n", alloc_len, req_len);
  4808. return -ENOMEM;
  4809. }
  4810. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4811. if (unlikely(rc))
  4812. return -EIO;
  4813. if (!phba->sli4_hba.intr_enable)
  4814. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4815. else {
  4816. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4817. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4818. }
  4819. if (unlikely(rc))
  4820. rc = -EIO;
  4821. return rc;
  4822. }
  4823. /**
  4824. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4825. * @phba: Pointer to HBA context object.
  4826. * @type: The resource extent type to allocate.
  4827. *
  4828. * This function allocates the number of elements for the specified
  4829. * resource type.
  4830. **/
  4831. static int
  4832. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4833. {
  4834. bool emb = false;
  4835. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4836. uint16_t rsrc_id, rsrc_start, j, k;
  4837. uint16_t *ids;
  4838. int i, rc;
  4839. unsigned long longs;
  4840. unsigned long *bmask;
  4841. struct lpfc_rsrc_blks *rsrc_blks;
  4842. LPFC_MBOXQ_t *mbox;
  4843. uint32_t length;
  4844. struct lpfc_id_range *id_array = NULL;
  4845. void *virtaddr = NULL;
  4846. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4847. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4848. struct list_head *ext_blk_list;
  4849. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4850. &rsrc_cnt,
  4851. &rsrc_size);
  4852. if (unlikely(rc))
  4853. return -EIO;
  4854. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4855. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4856. "3009 No available Resource Extents "
  4857. "for resource type 0x%x: Count: 0x%x, "
  4858. "Size 0x%x\n", type, rsrc_cnt,
  4859. rsrc_size);
  4860. return -ENOMEM;
  4861. }
  4862. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4863. "2903 Post resource extents type-0x%x: "
  4864. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4865. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4866. if (!mbox)
  4867. return -ENOMEM;
  4868. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4869. if (unlikely(rc)) {
  4870. rc = -EIO;
  4871. goto err_exit;
  4872. }
  4873. /*
  4874. * Figure out where the response is located. Then get local pointers
  4875. * to the response data. The port does not guarantee to respond to
  4876. * all extents counts request so update the local variable with the
  4877. * allocated count from the port.
  4878. */
  4879. if (emb == LPFC_SLI4_MBX_EMBED) {
  4880. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4881. id_array = &rsrc_ext->u.rsp.id[0];
  4882. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4883. } else {
  4884. virtaddr = mbox->sge_array->addr[0];
  4885. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4886. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4887. id_array = &n_rsrc->id;
  4888. }
  4889. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4890. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4891. /*
  4892. * Based on the resource size and count, correct the base and max
  4893. * resource values.
  4894. */
  4895. length = sizeof(struct lpfc_rsrc_blks);
  4896. switch (type) {
  4897. case LPFC_RSC_TYPE_FCOE_RPI:
  4898. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4899. sizeof(unsigned long),
  4900. GFP_KERNEL);
  4901. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4902. rc = -ENOMEM;
  4903. goto err_exit;
  4904. }
  4905. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4906. sizeof(uint16_t),
  4907. GFP_KERNEL);
  4908. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4909. kfree(phba->sli4_hba.rpi_bmask);
  4910. rc = -ENOMEM;
  4911. goto err_exit;
  4912. }
  4913. /*
  4914. * The next_rpi was initialized with the maximum available
  4915. * count but the port may allocate a smaller number. Catch
  4916. * that case and update the next_rpi.
  4917. */
  4918. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4919. /* Initialize local ptrs for common extent processing later. */
  4920. bmask = phba->sli4_hba.rpi_bmask;
  4921. ids = phba->sli4_hba.rpi_ids;
  4922. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4923. break;
  4924. case LPFC_RSC_TYPE_FCOE_VPI:
  4925. phba->vpi_bmask = kzalloc(longs *
  4926. sizeof(unsigned long),
  4927. GFP_KERNEL);
  4928. if (unlikely(!phba->vpi_bmask)) {
  4929. rc = -ENOMEM;
  4930. goto err_exit;
  4931. }
  4932. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4933. sizeof(uint16_t),
  4934. GFP_KERNEL);
  4935. if (unlikely(!phba->vpi_ids)) {
  4936. kfree(phba->vpi_bmask);
  4937. rc = -ENOMEM;
  4938. goto err_exit;
  4939. }
  4940. /* Initialize local ptrs for common extent processing later. */
  4941. bmask = phba->vpi_bmask;
  4942. ids = phba->vpi_ids;
  4943. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4944. break;
  4945. case LPFC_RSC_TYPE_FCOE_XRI:
  4946. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4947. sizeof(unsigned long),
  4948. GFP_KERNEL);
  4949. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4950. rc = -ENOMEM;
  4951. goto err_exit;
  4952. }
  4953. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4954. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4955. sizeof(uint16_t),
  4956. GFP_KERNEL);
  4957. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4958. kfree(phba->sli4_hba.xri_bmask);
  4959. rc = -ENOMEM;
  4960. goto err_exit;
  4961. }
  4962. /* Initialize local ptrs for common extent processing later. */
  4963. bmask = phba->sli4_hba.xri_bmask;
  4964. ids = phba->sli4_hba.xri_ids;
  4965. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4966. break;
  4967. case LPFC_RSC_TYPE_FCOE_VFI:
  4968. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4969. sizeof(unsigned long),
  4970. GFP_KERNEL);
  4971. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4972. rc = -ENOMEM;
  4973. goto err_exit;
  4974. }
  4975. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4976. sizeof(uint16_t),
  4977. GFP_KERNEL);
  4978. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4979. kfree(phba->sli4_hba.vfi_bmask);
  4980. rc = -ENOMEM;
  4981. goto err_exit;
  4982. }
  4983. /* Initialize local ptrs for common extent processing later. */
  4984. bmask = phba->sli4_hba.vfi_bmask;
  4985. ids = phba->sli4_hba.vfi_ids;
  4986. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4987. break;
  4988. default:
  4989. /* Unsupported Opcode. Fail call. */
  4990. id_array = NULL;
  4991. bmask = NULL;
  4992. ids = NULL;
  4993. ext_blk_list = NULL;
  4994. goto err_exit;
  4995. }
  4996. /*
  4997. * Complete initializing the extent configuration with the
  4998. * allocated ids assigned to this function. The bitmask serves
  4999. * as an index into the array and manages the available ids. The
  5000. * array just stores the ids communicated to the port via the wqes.
  5001. */
  5002. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  5003. if ((i % 2) == 0)
  5004. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  5005. &id_array[k]);
  5006. else
  5007. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  5008. &id_array[k]);
  5009. rsrc_blks = kzalloc(length, GFP_KERNEL);
  5010. if (unlikely(!rsrc_blks)) {
  5011. rc = -ENOMEM;
  5012. kfree(bmask);
  5013. kfree(ids);
  5014. goto err_exit;
  5015. }
  5016. rsrc_blks->rsrc_start = rsrc_id;
  5017. rsrc_blks->rsrc_size = rsrc_size;
  5018. list_add_tail(&rsrc_blks->list, ext_blk_list);
  5019. rsrc_start = rsrc_id;
  5020. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  5021. phba->sli4_hba.scsi_xri_start = rsrc_start +
  5022. lpfc_sli4_get_els_iocb_cnt(phba);
  5023. while (rsrc_id < (rsrc_start + rsrc_size)) {
  5024. ids[j] = rsrc_id;
  5025. rsrc_id++;
  5026. j++;
  5027. }
  5028. /* Entire word processed. Get next word.*/
  5029. if ((i % 2) == 1)
  5030. k++;
  5031. }
  5032. err_exit:
  5033. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5034. return rc;
  5035. }
  5036. /**
  5037. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  5038. * @phba: Pointer to HBA context object.
  5039. * @type: the extent's type.
  5040. *
  5041. * This function deallocates all extents of a particular resource type.
  5042. * SLI4 does not allow for deallocating a particular extent range. It
  5043. * is the caller's responsibility to release all kernel memory resources.
  5044. **/
  5045. static int
  5046. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  5047. {
  5048. int rc;
  5049. uint32_t length, mbox_tmo = 0;
  5050. LPFC_MBOXQ_t *mbox;
  5051. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  5052. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  5053. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5054. if (!mbox)
  5055. return -ENOMEM;
  5056. /*
  5057. * This function sends an embedded mailbox because it only sends the
  5058. * the resource type. All extents of this type are released by the
  5059. * port.
  5060. */
  5061. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  5062. sizeof(struct lpfc_sli4_cfg_mhdr));
  5063. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5064. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  5065. length, LPFC_SLI4_MBX_EMBED);
  5066. /* Send an extents count of 0 - the dealloc doesn't use it. */
  5067. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  5068. LPFC_SLI4_MBX_EMBED);
  5069. if (unlikely(rc)) {
  5070. rc = -EIO;
  5071. goto out_free_mbox;
  5072. }
  5073. if (!phba->sli4_hba.intr_enable)
  5074. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5075. else {
  5076. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5077. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5078. }
  5079. if (unlikely(rc)) {
  5080. rc = -EIO;
  5081. goto out_free_mbox;
  5082. }
  5083. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  5084. if (bf_get(lpfc_mbox_hdr_status,
  5085. &dealloc_rsrc->header.cfg_shdr.response)) {
  5086. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5087. "2919 Failed to release resource extents "
  5088. "for type %d - Status 0x%x Add'l Status 0x%x. "
  5089. "Resource memory not released.\n",
  5090. type,
  5091. bf_get(lpfc_mbox_hdr_status,
  5092. &dealloc_rsrc->header.cfg_shdr.response),
  5093. bf_get(lpfc_mbox_hdr_add_status,
  5094. &dealloc_rsrc->header.cfg_shdr.response));
  5095. rc = -EIO;
  5096. goto out_free_mbox;
  5097. }
  5098. /* Release kernel memory resources for the specific type. */
  5099. switch (type) {
  5100. case LPFC_RSC_TYPE_FCOE_VPI:
  5101. kfree(phba->vpi_bmask);
  5102. kfree(phba->vpi_ids);
  5103. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5104. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5105. &phba->lpfc_vpi_blk_list, list) {
  5106. list_del_init(&rsrc_blk->list);
  5107. kfree(rsrc_blk);
  5108. }
  5109. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5110. break;
  5111. case LPFC_RSC_TYPE_FCOE_XRI:
  5112. kfree(phba->sli4_hba.xri_bmask);
  5113. kfree(phba->sli4_hba.xri_ids);
  5114. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5115. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  5116. list_del_init(&rsrc_blk->list);
  5117. kfree(rsrc_blk);
  5118. }
  5119. break;
  5120. case LPFC_RSC_TYPE_FCOE_VFI:
  5121. kfree(phba->sli4_hba.vfi_bmask);
  5122. kfree(phba->sli4_hba.vfi_ids);
  5123. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5124. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5125. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  5126. list_del_init(&rsrc_blk->list);
  5127. kfree(rsrc_blk);
  5128. }
  5129. break;
  5130. case LPFC_RSC_TYPE_FCOE_RPI:
  5131. /* RPI bitmask and physical id array are cleaned up earlier. */
  5132. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5133. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  5134. list_del_init(&rsrc_blk->list);
  5135. kfree(rsrc_blk);
  5136. }
  5137. break;
  5138. default:
  5139. break;
  5140. }
  5141. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5142. out_free_mbox:
  5143. mempool_free(mbox, phba->mbox_mem_pool);
  5144. return rc;
  5145. }
  5146. /**
  5147. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  5148. * @phba: Pointer to HBA context object.
  5149. *
  5150. * This function allocates all SLI4 resource identifiers.
  5151. **/
  5152. int
  5153. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  5154. {
  5155. int i, rc, error = 0;
  5156. uint16_t count, base;
  5157. unsigned long longs;
  5158. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5159. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  5160. if (phba->sli4_hba.extents_in_use) {
  5161. /*
  5162. * The port supports resource extents. The XRI, VPI, VFI, RPI
  5163. * resource extent count must be read and allocated before
  5164. * provisioning the resource id arrays.
  5165. */
  5166. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5167. LPFC_IDX_RSRC_RDY) {
  5168. /*
  5169. * Extent-based resources are set - the driver could
  5170. * be in a port reset. Figure out if any corrective
  5171. * actions need to be taken.
  5172. */
  5173. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5174. LPFC_RSC_TYPE_FCOE_VFI);
  5175. if (rc != 0)
  5176. error++;
  5177. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5178. LPFC_RSC_TYPE_FCOE_VPI);
  5179. if (rc != 0)
  5180. error++;
  5181. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5182. LPFC_RSC_TYPE_FCOE_XRI);
  5183. if (rc != 0)
  5184. error++;
  5185. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5186. LPFC_RSC_TYPE_FCOE_RPI);
  5187. if (rc != 0)
  5188. error++;
  5189. /*
  5190. * It's possible that the number of resources
  5191. * provided to this port instance changed between
  5192. * resets. Detect this condition and reallocate
  5193. * resources. Otherwise, there is no action.
  5194. */
  5195. if (error) {
  5196. lpfc_printf_log(phba, KERN_INFO,
  5197. LOG_MBOX | LOG_INIT,
  5198. "2931 Detected extent resource "
  5199. "change. Reallocating all "
  5200. "extents.\n");
  5201. rc = lpfc_sli4_dealloc_extent(phba,
  5202. LPFC_RSC_TYPE_FCOE_VFI);
  5203. rc = lpfc_sli4_dealloc_extent(phba,
  5204. LPFC_RSC_TYPE_FCOE_VPI);
  5205. rc = lpfc_sli4_dealloc_extent(phba,
  5206. LPFC_RSC_TYPE_FCOE_XRI);
  5207. rc = lpfc_sli4_dealloc_extent(phba,
  5208. LPFC_RSC_TYPE_FCOE_RPI);
  5209. } else
  5210. return 0;
  5211. }
  5212. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5213. if (unlikely(rc))
  5214. goto err_exit;
  5215. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5216. if (unlikely(rc))
  5217. goto err_exit;
  5218. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5219. if (unlikely(rc))
  5220. goto err_exit;
  5221. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5222. if (unlikely(rc))
  5223. goto err_exit;
  5224. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5225. LPFC_IDX_RSRC_RDY);
  5226. return rc;
  5227. } else {
  5228. /*
  5229. * The port does not support resource extents. The XRI, VPI,
  5230. * VFI, RPI resource ids were determined from READ_CONFIG.
  5231. * Just allocate the bitmasks and provision the resource id
  5232. * arrays. If a port reset is active, the resources don't
  5233. * need any action - just exit.
  5234. */
  5235. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5236. LPFC_IDX_RSRC_RDY) {
  5237. lpfc_sli4_dealloc_resource_identifiers(phba);
  5238. lpfc_sli4_remove_rpis(phba);
  5239. }
  5240. /* RPIs. */
  5241. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5242. if (count <= 0) {
  5243. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5244. "3279 Invalid provisioning of "
  5245. "rpi:%d\n", count);
  5246. rc = -EINVAL;
  5247. goto err_exit;
  5248. }
  5249. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5250. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5251. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5252. sizeof(unsigned long),
  5253. GFP_KERNEL);
  5254. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5255. rc = -ENOMEM;
  5256. goto err_exit;
  5257. }
  5258. phba->sli4_hba.rpi_ids = kzalloc(count *
  5259. sizeof(uint16_t),
  5260. GFP_KERNEL);
  5261. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5262. rc = -ENOMEM;
  5263. goto free_rpi_bmask;
  5264. }
  5265. for (i = 0; i < count; i++)
  5266. phba->sli4_hba.rpi_ids[i] = base + i;
  5267. /* VPIs. */
  5268. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5269. if (count <= 0) {
  5270. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5271. "3280 Invalid provisioning of "
  5272. "vpi:%d\n", count);
  5273. rc = -EINVAL;
  5274. goto free_rpi_ids;
  5275. }
  5276. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5277. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5278. phba->vpi_bmask = kzalloc(longs *
  5279. sizeof(unsigned long),
  5280. GFP_KERNEL);
  5281. if (unlikely(!phba->vpi_bmask)) {
  5282. rc = -ENOMEM;
  5283. goto free_rpi_ids;
  5284. }
  5285. phba->vpi_ids = kzalloc(count *
  5286. sizeof(uint16_t),
  5287. GFP_KERNEL);
  5288. if (unlikely(!phba->vpi_ids)) {
  5289. rc = -ENOMEM;
  5290. goto free_vpi_bmask;
  5291. }
  5292. for (i = 0; i < count; i++)
  5293. phba->vpi_ids[i] = base + i;
  5294. /* XRIs. */
  5295. count = phba->sli4_hba.max_cfg_param.max_xri;
  5296. if (count <= 0) {
  5297. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5298. "3281 Invalid provisioning of "
  5299. "xri:%d\n", count);
  5300. rc = -EINVAL;
  5301. goto free_vpi_ids;
  5302. }
  5303. base = phba->sli4_hba.max_cfg_param.xri_base;
  5304. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5305. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5306. sizeof(unsigned long),
  5307. GFP_KERNEL);
  5308. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5309. rc = -ENOMEM;
  5310. goto free_vpi_ids;
  5311. }
  5312. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5313. phba->sli4_hba.xri_ids = kzalloc(count *
  5314. sizeof(uint16_t),
  5315. GFP_KERNEL);
  5316. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5317. rc = -ENOMEM;
  5318. goto free_xri_bmask;
  5319. }
  5320. for (i = 0; i < count; i++)
  5321. phba->sli4_hba.xri_ids[i] = base + i;
  5322. /* VFIs. */
  5323. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5324. if (count <= 0) {
  5325. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5326. "3282 Invalid provisioning of "
  5327. "vfi:%d\n", count);
  5328. rc = -EINVAL;
  5329. goto free_xri_ids;
  5330. }
  5331. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5332. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5333. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5334. sizeof(unsigned long),
  5335. GFP_KERNEL);
  5336. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5337. rc = -ENOMEM;
  5338. goto free_xri_ids;
  5339. }
  5340. phba->sli4_hba.vfi_ids = kzalloc(count *
  5341. sizeof(uint16_t),
  5342. GFP_KERNEL);
  5343. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5344. rc = -ENOMEM;
  5345. goto free_vfi_bmask;
  5346. }
  5347. for (i = 0; i < count; i++)
  5348. phba->sli4_hba.vfi_ids[i] = base + i;
  5349. /*
  5350. * Mark all resources ready. An HBA reset doesn't need
  5351. * to reset the initialization.
  5352. */
  5353. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5354. LPFC_IDX_RSRC_RDY);
  5355. return 0;
  5356. }
  5357. free_vfi_bmask:
  5358. kfree(phba->sli4_hba.vfi_bmask);
  5359. phba->sli4_hba.vfi_bmask = NULL;
  5360. free_xri_ids:
  5361. kfree(phba->sli4_hba.xri_ids);
  5362. phba->sli4_hba.xri_ids = NULL;
  5363. free_xri_bmask:
  5364. kfree(phba->sli4_hba.xri_bmask);
  5365. phba->sli4_hba.xri_bmask = NULL;
  5366. free_vpi_ids:
  5367. kfree(phba->vpi_ids);
  5368. phba->vpi_ids = NULL;
  5369. free_vpi_bmask:
  5370. kfree(phba->vpi_bmask);
  5371. phba->vpi_bmask = NULL;
  5372. free_rpi_ids:
  5373. kfree(phba->sli4_hba.rpi_ids);
  5374. phba->sli4_hba.rpi_ids = NULL;
  5375. free_rpi_bmask:
  5376. kfree(phba->sli4_hba.rpi_bmask);
  5377. phba->sli4_hba.rpi_bmask = NULL;
  5378. err_exit:
  5379. return rc;
  5380. }
  5381. /**
  5382. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5383. * @phba: Pointer to HBA context object.
  5384. *
  5385. * This function allocates the number of elements for the specified
  5386. * resource type.
  5387. **/
  5388. int
  5389. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5390. {
  5391. if (phba->sli4_hba.extents_in_use) {
  5392. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5393. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5394. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5395. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5396. } else {
  5397. kfree(phba->vpi_bmask);
  5398. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5399. kfree(phba->vpi_ids);
  5400. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5401. kfree(phba->sli4_hba.xri_bmask);
  5402. kfree(phba->sli4_hba.xri_ids);
  5403. kfree(phba->sli4_hba.vfi_bmask);
  5404. kfree(phba->sli4_hba.vfi_ids);
  5405. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5406. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5407. }
  5408. return 0;
  5409. }
  5410. /**
  5411. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5412. * @phba: Pointer to HBA context object.
  5413. * @type: The resource extent type.
  5414. * @extnt_count: buffer to hold port extent count response
  5415. * @extnt_size: buffer to hold port extent size response.
  5416. *
  5417. * This function calls the port to read the host allocated extents
  5418. * for a particular type.
  5419. **/
  5420. int
  5421. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5422. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5423. {
  5424. bool emb;
  5425. int rc = 0;
  5426. uint16_t curr_blks = 0;
  5427. uint32_t req_len, emb_len;
  5428. uint32_t alloc_len, mbox_tmo;
  5429. struct list_head *blk_list_head;
  5430. struct lpfc_rsrc_blks *rsrc_blk;
  5431. LPFC_MBOXQ_t *mbox;
  5432. void *virtaddr = NULL;
  5433. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5434. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5435. union lpfc_sli4_cfg_shdr *shdr;
  5436. switch (type) {
  5437. case LPFC_RSC_TYPE_FCOE_VPI:
  5438. blk_list_head = &phba->lpfc_vpi_blk_list;
  5439. break;
  5440. case LPFC_RSC_TYPE_FCOE_XRI:
  5441. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5442. break;
  5443. case LPFC_RSC_TYPE_FCOE_VFI:
  5444. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5445. break;
  5446. case LPFC_RSC_TYPE_FCOE_RPI:
  5447. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5448. break;
  5449. default:
  5450. return -EIO;
  5451. }
  5452. /* Count the number of extents currently allocatd for this type. */
  5453. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5454. if (curr_blks == 0) {
  5455. /*
  5456. * The GET_ALLOCATED mailbox does not return the size,
  5457. * just the count. The size should be just the size
  5458. * stored in the current allocated block and all sizes
  5459. * for an extent type are the same so set the return
  5460. * value now.
  5461. */
  5462. *extnt_size = rsrc_blk->rsrc_size;
  5463. }
  5464. curr_blks++;
  5465. }
  5466. /*
  5467. * Calculate the size of an embedded mailbox. The uint32_t
  5468. * accounts for extents-specific word.
  5469. */
  5470. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5471. sizeof(uint32_t);
  5472. /*
  5473. * Presume the allocation and response will fit into an embedded
  5474. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5475. */
  5476. emb = LPFC_SLI4_MBX_EMBED;
  5477. req_len = emb_len;
  5478. if (req_len > emb_len) {
  5479. req_len = curr_blks * sizeof(uint16_t) +
  5480. sizeof(union lpfc_sli4_cfg_shdr) +
  5481. sizeof(uint32_t);
  5482. emb = LPFC_SLI4_MBX_NEMBED;
  5483. }
  5484. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5485. if (!mbox)
  5486. return -ENOMEM;
  5487. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5488. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5489. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5490. req_len, emb);
  5491. if (alloc_len < req_len) {
  5492. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5493. "2983 Allocated DMA memory size (x%x) is "
  5494. "less than the requested DMA memory "
  5495. "size (x%x)\n", alloc_len, req_len);
  5496. rc = -ENOMEM;
  5497. goto err_exit;
  5498. }
  5499. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5500. if (unlikely(rc)) {
  5501. rc = -EIO;
  5502. goto err_exit;
  5503. }
  5504. if (!phba->sli4_hba.intr_enable)
  5505. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5506. else {
  5507. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5508. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5509. }
  5510. if (unlikely(rc)) {
  5511. rc = -EIO;
  5512. goto err_exit;
  5513. }
  5514. /*
  5515. * Figure out where the response is located. Then get local pointers
  5516. * to the response data. The port does not guarantee to respond to
  5517. * all extents counts request so update the local variable with the
  5518. * allocated count from the port.
  5519. */
  5520. if (emb == LPFC_SLI4_MBX_EMBED) {
  5521. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5522. shdr = &rsrc_ext->header.cfg_shdr;
  5523. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5524. } else {
  5525. virtaddr = mbox->sge_array->addr[0];
  5526. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5527. shdr = &n_rsrc->cfg_shdr;
  5528. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5529. }
  5530. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5531. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5532. "2984 Failed to read allocated resources "
  5533. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5534. type,
  5535. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5536. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5537. rc = -EIO;
  5538. goto err_exit;
  5539. }
  5540. err_exit:
  5541. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5542. return rc;
  5543. }
  5544. /**
  5545. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5546. * @phba: pointer to lpfc hba data structure.
  5547. *
  5548. * This routine walks the list of els buffers that have been allocated and
  5549. * repost them to the port by using SGL block post. This is needed after a
  5550. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5551. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5552. * SGL block post mailbox commands to post them to the port. For single els
  5553. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5554. * mailbox command for posting.
  5555. *
  5556. * Returns: 0 = success, non-zero failure.
  5557. **/
  5558. static int
  5559. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5560. {
  5561. struct lpfc_sglq *sglq_entry = NULL;
  5562. struct lpfc_sglq *sglq_entry_next = NULL;
  5563. struct lpfc_sglq *sglq_entry_first = NULL;
  5564. int status, total_cnt, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5565. int last_xritag = NO_XRI;
  5566. struct lpfc_sli_ring *pring;
  5567. LIST_HEAD(prep_sgl_list);
  5568. LIST_HEAD(blck_sgl_list);
  5569. LIST_HEAD(allc_sgl_list);
  5570. LIST_HEAD(post_sgl_list);
  5571. LIST_HEAD(free_sgl_list);
  5572. pring = &phba->sli.ring[LPFC_ELS_RING];
  5573. spin_lock_irq(&phba->hbalock);
  5574. spin_lock(&pring->ring_lock);
  5575. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5576. spin_unlock(&pring->ring_lock);
  5577. spin_unlock_irq(&phba->hbalock);
  5578. total_cnt = phba->sli4_hba.els_xri_cnt;
  5579. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5580. &allc_sgl_list, list) {
  5581. list_del_init(&sglq_entry->list);
  5582. block_cnt++;
  5583. if ((last_xritag != NO_XRI) &&
  5584. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5585. /* a hole in xri block, form a sgl posting block */
  5586. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5587. post_cnt = block_cnt - 1;
  5588. /* prepare list for next posting block */
  5589. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5590. block_cnt = 1;
  5591. } else {
  5592. /* prepare list for next posting block */
  5593. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5594. /* enough sgls for non-embed sgl mbox command */
  5595. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5596. list_splice_init(&prep_sgl_list,
  5597. &blck_sgl_list);
  5598. post_cnt = block_cnt;
  5599. block_cnt = 0;
  5600. }
  5601. }
  5602. num_posted++;
  5603. /* keep track of last sgl's xritag */
  5604. last_xritag = sglq_entry->sli4_xritag;
  5605. /* end of repost sgl list condition for els buffers */
  5606. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5607. if (post_cnt == 0) {
  5608. list_splice_init(&prep_sgl_list,
  5609. &blck_sgl_list);
  5610. post_cnt = block_cnt;
  5611. } else if (block_cnt == 1) {
  5612. status = lpfc_sli4_post_sgl(phba,
  5613. sglq_entry->phys, 0,
  5614. sglq_entry->sli4_xritag);
  5615. if (!status) {
  5616. /* successful, put sgl to posted list */
  5617. list_add_tail(&sglq_entry->list,
  5618. &post_sgl_list);
  5619. } else {
  5620. /* Failure, put sgl to free list */
  5621. lpfc_printf_log(phba, KERN_WARNING,
  5622. LOG_SLI,
  5623. "3159 Failed to post els "
  5624. "sgl, xritag:x%x\n",
  5625. sglq_entry->sli4_xritag);
  5626. list_add_tail(&sglq_entry->list,
  5627. &free_sgl_list);
  5628. total_cnt--;
  5629. }
  5630. }
  5631. }
  5632. /* continue until a nembed page worth of sgls */
  5633. if (post_cnt == 0)
  5634. continue;
  5635. /* post the els buffer list sgls as a block */
  5636. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5637. post_cnt);
  5638. if (!status) {
  5639. /* success, put sgl list to posted sgl list */
  5640. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5641. } else {
  5642. /* Failure, put sgl list to free sgl list */
  5643. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5644. struct lpfc_sglq,
  5645. list);
  5646. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5647. "3160 Failed to post els sgl-list, "
  5648. "xritag:x%x-x%x\n",
  5649. sglq_entry_first->sli4_xritag,
  5650. (sglq_entry_first->sli4_xritag +
  5651. post_cnt - 1));
  5652. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5653. total_cnt -= post_cnt;
  5654. }
  5655. /* don't reset xirtag due to hole in xri block */
  5656. if (block_cnt == 0)
  5657. last_xritag = NO_XRI;
  5658. /* reset els sgl post count for next round of posting */
  5659. post_cnt = 0;
  5660. }
  5661. /* update the number of XRIs posted for ELS */
  5662. phba->sli4_hba.els_xri_cnt = total_cnt;
  5663. /* free the els sgls failed to post */
  5664. lpfc_free_sgl_list(phba, &free_sgl_list);
  5665. /* push els sgls posted to the availble list */
  5666. if (!list_empty(&post_sgl_list)) {
  5667. spin_lock_irq(&phba->hbalock);
  5668. spin_lock(&pring->ring_lock);
  5669. list_splice_init(&post_sgl_list,
  5670. &phba->sli4_hba.lpfc_sgl_list);
  5671. spin_unlock(&pring->ring_lock);
  5672. spin_unlock_irq(&phba->hbalock);
  5673. } else {
  5674. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5675. "3161 Failure to post els sgl to port.\n");
  5676. return -EIO;
  5677. }
  5678. return 0;
  5679. }
  5680. /**
  5681. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5682. * @phba: Pointer to HBA context object.
  5683. *
  5684. * This function is the main SLI4 device intialization PCI function. This
  5685. * function is called by the HBA intialization code, HBA reset code and
  5686. * HBA error attention handler code. Caller is not required to hold any
  5687. * locks.
  5688. **/
  5689. int
  5690. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5691. {
  5692. int rc;
  5693. LPFC_MBOXQ_t *mboxq;
  5694. struct lpfc_mqe *mqe;
  5695. uint8_t *vpd;
  5696. uint32_t vpd_size;
  5697. uint32_t ftr_rsp = 0;
  5698. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5699. struct lpfc_vport *vport = phba->pport;
  5700. struct lpfc_dmabuf *mp;
  5701. /* Perform a PCI function reset to start from clean */
  5702. rc = lpfc_pci_function_reset(phba);
  5703. if (unlikely(rc))
  5704. return -ENODEV;
  5705. /* Check the HBA Host Status Register for readyness */
  5706. rc = lpfc_sli4_post_status_check(phba);
  5707. if (unlikely(rc))
  5708. return -ENODEV;
  5709. else {
  5710. spin_lock_irq(&phba->hbalock);
  5711. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5712. spin_unlock_irq(&phba->hbalock);
  5713. }
  5714. /*
  5715. * Allocate a single mailbox container for initializing the
  5716. * port.
  5717. */
  5718. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5719. if (!mboxq)
  5720. return -ENOMEM;
  5721. /* Issue READ_REV to collect vpd and FW information. */
  5722. vpd_size = SLI4_PAGE_SIZE;
  5723. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5724. if (!vpd) {
  5725. rc = -ENOMEM;
  5726. goto out_free_mbox;
  5727. }
  5728. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5729. if (unlikely(rc)) {
  5730. kfree(vpd);
  5731. goto out_free_mbox;
  5732. }
  5733. mqe = &mboxq->u.mqe;
  5734. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5735. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5736. phba->hba_flag |= HBA_FCOE_MODE;
  5737. else
  5738. phba->hba_flag &= ~HBA_FCOE_MODE;
  5739. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5740. LPFC_DCBX_CEE_MODE)
  5741. phba->hba_flag |= HBA_FIP_SUPPORT;
  5742. else
  5743. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5744. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5745. if (phba->sli_rev != LPFC_SLI_REV4) {
  5746. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5747. "0376 READ_REV Error. SLI Level %d "
  5748. "FCoE enabled %d\n",
  5749. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5750. rc = -EIO;
  5751. kfree(vpd);
  5752. goto out_free_mbox;
  5753. }
  5754. /*
  5755. * Continue initialization with default values even if driver failed
  5756. * to read FCoE param config regions, only read parameters if the
  5757. * board is FCoE
  5758. */
  5759. if (phba->hba_flag & HBA_FCOE_MODE &&
  5760. lpfc_sli4_read_fcoe_params(phba))
  5761. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5762. "2570 Failed to read FCoE parameters\n");
  5763. /*
  5764. * Retrieve sli4 device physical port name, failure of doing it
  5765. * is considered as non-fatal.
  5766. */
  5767. rc = lpfc_sli4_retrieve_pport_name(phba);
  5768. if (!rc)
  5769. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5770. "3080 Successful retrieving SLI4 device "
  5771. "physical port name: %s.\n", phba->Port);
  5772. /*
  5773. * Evaluate the read rev and vpd data. Populate the driver
  5774. * state with the results. If this routine fails, the failure
  5775. * is not fatal as the driver will use generic values.
  5776. */
  5777. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5778. if (unlikely(!rc)) {
  5779. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5780. "0377 Error %d parsing vpd. "
  5781. "Using defaults.\n", rc);
  5782. rc = 0;
  5783. }
  5784. kfree(vpd);
  5785. /* Save information as VPD data */
  5786. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5787. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5788. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5789. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5790. &mqe->un.read_rev);
  5791. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5792. &mqe->un.read_rev);
  5793. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5794. &mqe->un.read_rev);
  5795. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5796. &mqe->un.read_rev);
  5797. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5798. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5799. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5800. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5801. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5802. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5803. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5804. "(%d):0380 READ_REV Status x%x "
  5805. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5806. mboxq->vport ? mboxq->vport->vpi : 0,
  5807. bf_get(lpfc_mqe_status, mqe),
  5808. phba->vpd.rev.opFwName,
  5809. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5810. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5811. /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
  5812. rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3);
  5813. if (phba->pport->cfg_lun_queue_depth > rc) {
  5814. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5815. "3362 LUN queue depth changed from %d to %d\n",
  5816. phba->pport->cfg_lun_queue_depth, rc);
  5817. phba->pport->cfg_lun_queue_depth = rc;
  5818. }
  5819. /*
  5820. * Discover the port's supported feature set and match it against the
  5821. * hosts requests.
  5822. */
  5823. lpfc_request_features(phba, mboxq);
  5824. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5825. if (unlikely(rc)) {
  5826. rc = -EIO;
  5827. goto out_free_mbox;
  5828. }
  5829. /*
  5830. * The port must support FCP initiator mode as this is the
  5831. * only mode running in the host.
  5832. */
  5833. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5834. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5835. "0378 No support for fcpi mode.\n");
  5836. ftr_rsp++;
  5837. }
  5838. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5839. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5840. else
  5841. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5842. /*
  5843. * If the port cannot support the host's requested features
  5844. * then turn off the global config parameters to disable the
  5845. * feature in the driver. This is not a fatal error.
  5846. */
  5847. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5848. if (phba->cfg_enable_bg) {
  5849. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5850. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5851. else
  5852. ftr_rsp++;
  5853. }
  5854. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5855. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5856. ftr_rsp++;
  5857. if (ftr_rsp) {
  5858. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5859. "0379 Feature Mismatch Data: x%08x %08x "
  5860. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5861. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5862. phba->cfg_enable_npiv, phba->max_vpi);
  5863. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5864. phba->cfg_enable_bg = 0;
  5865. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5866. phba->cfg_enable_npiv = 0;
  5867. }
  5868. /* These SLI3 features are assumed in SLI4 */
  5869. spin_lock_irq(&phba->hbalock);
  5870. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5871. spin_unlock_irq(&phba->hbalock);
  5872. /*
  5873. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5874. * calls depends on these resources to complete port setup.
  5875. */
  5876. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5877. if (rc) {
  5878. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5879. "2920 Failed to alloc Resource IDs "
  5880. "rc = x%x\n", rc);
  5881. goto out_free_mbox;
  5882. }
  5883. /* Read the port's service parameters. */
  5884. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5885. if (rc) {
  5886. phba->link_state = LPFC_HBA_ERROR;
  5887. rc = -ENOMEM;
  5888. goto out_free_mbox;
  5889. }
  5890. mboxq->vport = vport;
  5891. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5892. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5893. if (rc == MBX_SUCCESS) {
  5894. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5895. rc = 0;
  5896. }
  5897. /*
  5898. * This memory was allocated by the lpfc_read_sparam routine. Release
  5899. * it to the mbuf pool.
  5900. */
  5901. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5902. kfree(mp);
  5903. mboxq->context1 = NULL;
  5904. if (unlikely(rc)) {
  5905. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5906. "0382 READ_SPARAM command failed "
  5907. "status %d, mbxStatus x%x\n",
  5908. rc, bf_get(lpfc_mqe_status, mqe));
  5909. phba->link_state = LPFC_HBA_ERROR;
  5910. rc = -EIO;
  5911. goto out_free_mbox;
  5912. }
  5913. lpfc_update_vport_wwn(vport);
  5914. /* Update the fc_host data structures with new wwn. */
  5915. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5916. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5917. /* update host els and scsi xri-sgl sizes and mappings */
  5918. rc = lpfc_sli4_xri_sgl_update(phba);
  5919. if (unlikely(rc)) {
  5920. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5921. "1400 Failed to update xri-sgl size and "
  5922. "mapping: %d\n", rc);
  5923. goto out_free_mbox;
  5924. }
  5925. /* register the els sgl pool to the port */
  5926. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5927. if (unlikely(rc)) {
  5928. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5929. "0582 Error %d during els sgl post "
  5930. "operation\n", rc);
  5931. rc = -ENODEV;
  5932. goto out_free_mbox;
  5933. }
  5934. /* register the allocated scsi sgl pool to the port */
  5935. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5936. if (unlikely(rc)) {
  5937. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5938. "0383 Error %d during scsi sgl post "
  5939. "operation\n", rc);
  5940. /* Some Scsi buffers were moved to the abort scsi list */
  5941. /* A pci function reset will repost them */
  5942. rc = -ENODEV;
  5943. goto out_free_mbox;
  5944. }
  5945. /* Post the rpi header region to the device. */
  5946. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5947. if (unlikely(rc)) {
  5948. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5949. "0393 Error %d during rpi post operation\n",
  5950. rc);
  5951. rc = -ENODEV;
  5952. goto out_free_mbox;
  5953. }
  5954. lpfc_sli4_node_prep(phba);
  5955. /* Create all the SLI4 queues */
  5956. rc = lpfc_sli4_queue_create(phba);
  5957. if (rc) {
  5958. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5959. "3089 Failed to allocate queues\n");
  5960. rc = -ENODEV;
  5961. goto out_stop_timers;
  5962. }
  5963. /* Set up all the queues to the device */
  5964. rc = lpfc_sli4_queue_setup(phba);
  5965. if (unlikely(rc)) {
  5966. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5967. "0381 Error %d during queue setup.\n ", rc);
  5968. goto out_destroy_queue;
  5969. }
  5970. /* Arm the CQs and then EQs on device */
  5971. lpfc_sli4_arm_cqeq_intr(phba);
  5972. /* Indicate device interrupt mode */
  5973. phba->sli4_hba.intr_enable = 1;
  5974. /* Allow asynchronous mailbox command to go through */
  5975. spin_lock_irq(&phba->hbalock);
  5976. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5977. spin_unlock_irq(&phba->hbalock);
  5978. /* Post receive buffers to the device */
  5979. lpfc_sli4_rb_setup(phba);
  5980. /* Reset HBA FCF states after HBA reset */
  5981. phba->fcf.fcf_flag = 0;
  5982. phba->fcf.current_rec.flag = 0;
  5983. /* Start the ELS watchdog timer */
  5984. mod_timer(&vport->els_tmofunc,
  5985. jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
  5986. /* Start heart beat timer */
  5987. mod_timer(&phba->hb_tmofunc,
  5988. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  5989. phba->hb_outstanding = 0;
  5990. phba->last_completion_time = jiffies;
  5991. /* Start error attention (ERATT) polling timer */
  5992. mod_timer(&phba->eratt_poll,
  5993. jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  5994. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5995. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5996. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5997. if (!rc) {
  5998. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5999. "2829 This device supports "
  6000. "Advanced Error Reporting (AER)\n");
  6001. spin_lock_irq(&phba->hbalock);
  6002. phba->hba_flag |= HBA_AER_ENABLED;
  6003. spin_unlock_irq(&phba->hbalock);
  6004. } else {
  6005. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6006. "2830 This device does not support "
  6007. "Advanced Error Reporting (AER)\n");
  6008. phba->cfg_aer_support = 0;
  6009. }
  6010. rc = 0;
  6011. }
  6012. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  6013. /*
  6014. * The FC Port needs to register FCFI (index 0)
  6015. */
  6016. lpfc_reg_fcfi(phba, mboxq);
  6017. mboxq->vport = phba->pport;
  6018. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6019. if (rc != MBX_SUCCESS)
  6020. goto out_unset_queue;
  6021. rc = 0;
  6022. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  6023. &mboxq->u.mqe.un.reg_fcfi);
  6024. /* Check if the port is configured to be disabled */
  6025. lpfc_sli_read_link_ste(phba);
  6026. }
  6027. /*
  6028. * The port is ready, set the host's link state to LINK_DOWN
  6029. * in preparation for link interrupts.
  6030. */
  6031. spin_lock_irq(&phba->hbalock);
  6032. phba->link_state = LPFC_LINK_DOWN;
  6033. spin_unlock_irq(&phba->hbalock);
  6034. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  6035. (phba->hba_flag & LINK_DISABLED)) {
  6036. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  6037. "3103 Adapter Link is disabled.\n");
  6038. lpfc_down_link(phba, mboxq);
  6039. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6040. if (rc != MBX_SUCCESS) {
  6041. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  6042. "3104 Adapter failed to issue "
  6043. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  6044. goto out_unset_queue;
  6045. }
  6046. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  6047. /* don't perform init_link on SLI4 FC port loopback test */
  6048. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  6049. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  6050. if (rc)
  6051. goto out_unset_queue;
  6052. }
  6053. }
  6054. mempool_free(mboxq, phba->mbox_mem_pool);
  6055. return rc;
  6056. out_unset_queue:
  6057. /* Unset all the queues set up in this routine when error out */
  6058. lpfc_sli4_queue_unset(phba);
  6059. out_destroy_queue:
  6060. lpfc_sli4_queue_destroy(phba);
  6061. out_stop_timers:
  6062. lpfc_stop_hba_timers(phba);
  6063. out_free_mbox:
  6064. mempool_free(mboxq, phba->mbox_mem_pool);
  6065. return rc;
  6066. }
  6067. /**
  6068. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  6069. * @ptr: context object - pointer to hba structure.
  6070. *
  6071. * This is the callback function for mailbox timer. The mailbox
  6072. * timer is armed when a new mailbox command is issued and the timer
  6073. * is deleted when the mailbox complete. The function is called by
  6074. * the kernel timer code when a mailbox does not complete within
  6075. * expected time. This function wakes up the worker thread to
  6076. * process the mailbox timeout and returns. All the processing is
  6077. * done by the worker thread function lpfc_mbox_timeout_handler.
  6078. **/
  6079. void
  6080. lpfc_mbox_timeout(unsigned long ptr)
  6081. {
  6082. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  6083. unsigned long iflag;
  6084. uint32_t tmo_posted;
  6085. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  6086. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  6087. if (!tmo_posted)
  6088. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  6089. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  6090. if (!tmo_posted)
  6091. lpfc_worker_wake_up(phba);
  6092. return;
  6093. }
  6094. /**
  6095. * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
  6096. * are pending
  6097. * @phba: Pointer to HBA context object.
  6098. *
  6099. * This function checks if any mailbox completions are present on the mailbox
  6100. * completion queue.
  6101. **/
  6102. static bool
  6103. lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
  6104. {
  6105. uint32_t idx;
  6106. struct lpfc_queue *mcq;
  6107. struct lpfc_mcqe *mcqe;
  6108. bool pending_completions = false;
  6109. if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
  6110. return false;
  6111. /* Check for completions on mailbox completion queue */
  6112. mcq = phba->sli4_hba.mbx_cq;
  6113. idx = mcq->hba_index;
  6114. while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) {
  6115. mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe;
  6116. if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
  6117. (!bf_get_le32(lpfc_trailer_async, mcqe))) {
  6118. pending_completions = true;
  6119. break;
  6120. }
  6121. idx = (idx + 1) % mcq->entry_count;
  6122. if (mcq->hba_index == idx)
  6123. break;
  6124. }
  6125. return pending_completions;
  6126. }
  6127. /**
  6128. * lpfc_sli4_process_missed_mbox_completions - process mbox completions
  6129. * that were missed.
  6130. * @phba: Pointer to HBA context object.
  6131. *
  6132. * For sli4, it is possible to miss an interrupt. As such mbox completions
  6133. * maybe missed causing erroneous mailbox timeouts to occur. This function
  6134. * checks to see if mbox completions are on the mailbox completion queue
  6135. * and will process all the completions associated with the eq for the
  6136. * mailbox completion queue.
  6137. **/
  6138. bool
  6139. lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
  6140. {
  6141. uint32_t eqidx;
  6142. struct lpfc_queue *fpeq = NULL;
  6143. struct lpfc_eqe *eqe;
  6144. bool mbox_pending;
  6145. if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
  6146. return false;
  6147. /* Find the eq associated with the mcq */
  6148. if (phba->sli4_hba.hba_eq)
  6149. for (eqidx = 0; eqidx < phba->cfg_fcp_io_channel; eqidx++)
  6150. if (phba->sli4_hba.hba_eq[eqidx]->queue_id ==
  6151. phba->sli4_hba.mbx_cq->assoc_qid) {
  6152. fpeq = phba->sli4_hba.hba_eq[eqidx];
  6153. break;
  6154. }
  6155. if (!fpeq)
  6156. return false;
  6157. /* Turn off interrupts from this EQ */
  6158. lpfc_sli4_eq_clr_intr(fpeq);
  6159. /* Check to see if a mbox completion is pending */
  6160. mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
  6161. /*
  6162. * If a mbox completion is pending, process all the events on EQ
  6163. * associated with the mbox completion queue (this could include
  6164. * mailbox commands, async events, els commands, receive queue data
  6165. * and fcp commands)
  6166. */
  6167. if (mbox_pending)
  6168. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  6169. lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx);
  6170. fpeq->EQ_processed++;
  6171. }
  6172. /* Always clear and re-arm the EQ */
  6173. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  6174. return mbox_pending;
  6175. }
  6176. /**
  6177. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  6178. * @phba: Pointer to HBA context object.
  6179. *
  6180. * This function is called from worker thread when a mailbox command times out.
  6181. * The caller is not required to hold any locks. This function will reset the
  6182. * HBA and recover all the pending commands.
  6183. **/
  6184. void
  6185. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  6186. {
  6187. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  6188. MAILBOX_t *mb = NULL;
  6189. struct lpfc_sli *psli = &phba->sli;
  6190. /* If the mailbox completed, process the completion and return */
  6191. if (lpfc_sli4_process_missed_mbox_completions(phba))
  6192. return;
  6193. if (pmbox != NULL)
  6194. mb = &pmbox->u.mb;
  6195. /* Check the pmbox pointer first. There is a race condition
  6196. * between the mbox timeout handler getting executed in the
  6197. * worklist and the mailbox actually completing. When this
  6198. * race condition occurs, the mbox_active will be NULL.
  6199. */
  6200. spin_lock_irq(&phba->hbalock);
  6201. if (pmbox == NULL) {
  6202. lpfc_printf_log(phba, KERN_WARNING,
  6203. LOG_MBOX | LOG_SLI,
  6204. "0353 Active Mailbox cleared - mailbox timeout "
  6205. "exiting\n");
  6206. spin_unlock_irq(&phba->hbalock);
  6207. return;
  6208. }
  6209. /* Mbox cmd <mbxCommand> timeout */
  6210. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6211. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  6212. mb->mbxCommand,
  6213. phba->pport->port_state,
  6214. phba->sli.sli_flag,
  6215. phba->sli.mbox_active);
  6216. spin_unlock_irq(&phba->hbalock);
  6217. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  6218. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  6219. * it to fail all outstanding SCSI IO.
  6220. */
  6221. spin_lock_irq(&phba->pport->work_port_lock);
  6222. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6223. spin_unlock_irq(&phba->pport->work_port_lock);
  6224. spin_lock_irq(&phba->hbalock);
  6225. phba->link_state = LPFC_LINK_UNKNOWN;
  6226. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6227. spin_unlock_irq(&phba->hbalock);
  6228. lpfc_sli_abort_fcp_rings(phba);
  6229. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6230. "0345 Resetting board due to mailbox timeout\n");
  6231. /* Reset the HBA device */
  6232. lpfc_reset_hba(phba);
  6233. }
  6234. /**
  6235. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  6236. * @phba: Pointer to HBA context object.
  6237. * @pmbox: Pointer to mailbox object.
  6238. * @flag: Flag indicating how the mailbox need to be processed.
  6239. *
  6240. * This function is called by discovery code and HBA management code
  6241. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  6242. * function gets the hbalock to protect the data structures.
  6243. * The mailbox command can be submitted in polling mode, in which case
  6244. * this function will wait in a polling loop for the completion of the
  6245. * mailbox.
  6246. * If the mailbox is submitted in no_wait mode (not polling) the
  6247. * function will submit the command and returns immediately without waiting
  6248. * for the mailbox completion. The no_wait is supported only when HBA
  6249. * is in SLI2/SLI3 mode - interrupts are enabled.
  6250. * The SLI interface allows only one mailbox pending at a time. If the
  6251. * mailbox is issued in polling mode and there is already a mailbox
  6252. * pending, then the function will return an error. If the mailbox is issued
  6253. * in NO_WAIT mode and there is a mailbox pending already, the function
  6254. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  6255. * The sli layer owns the mailbox object until the completion of mailbox
  6256. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  6257. * return codes the caller owns the mailbox command after the return of
  6258. * the function.
  6259. **/
  6260. static int
  6261. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  6262. uint32_t flag)
  6263. {
  6264. MAILBOX_t *mbx;
  6265. struct lpfc_sli *psli = &phba->sli;
  6266. uint32_t status, evtctr;
  6267. uint32_t ha_copy, hc_copy;
  6268. int i;
  6269. unsigned long timeout;
  6270. unsigned long drvr_flag = 0;
  6271. uint32_t word0, ldata;
  6272. void __iomem *to_slim;
  6273. int processing_queue = 0;
  6274. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6275. if (!pmbox) {
  6276. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6277. /* processing mbox queue from intr_handler */
  6278. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6279. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6280. return MBX_SUCCESS;
  6281. }
  6282. processing_queue = 1;
  6283. pmbox = lpfc_mbox_get(phba);
  6284. if (!pmbox) {
  6285. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6286. return MBX_SUCCESS;
  6287. }
  6288. }
  6289. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  6290. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  6291. if(!pmbox->vport) {
  6292. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6293. lpfc_printf_log(phba, KERN_ERR,
  6294. LOG_MBOX | LOG_VPORT,
  6295. "1806 Mbox x%x failed. No vport\n",
  6296. pmbox->u.mb.mbxCommand);
  6297. dump_stack();
  6298. goto out_not_finished;
  6299. }
  6300. }
  6301. /* If the PCI channel is in offline state, do not post mbox. */
  6302. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6303. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6304. goto out_not_finished;
  6305. }
  6306. /* If HBA has a deferred error attention, fail the iocb. */
  6307. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6308. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6309. goto out_not_finished;
  6310. }
  6311. psli = &phba->sli;
  6312. mbx = &pmbox->u.mb;
  6313. status = MBX_SUCCESS;
  6314. if (phba->link_state == LPFC_HBA_ERROR) {
  6315. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6316. /* Mbox command <mbxCommand> cannot issue */
  6317. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6318. "(%d):0311 Mailbox command x%x cannot "
  6319. "issue Data: x%x x%x\n",
  6320. pmbox->vport ? pmbox->vport->vpi : 0,
  6321. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6322. goto out_not_finished;
  6323. }
  6324. if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6325. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6326. !(hc_copy & HC_MBINT_ENA)) {
  6327. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6328. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6329. "(%d):2528 Mailbox command x%x cannot "
  6330. "issue Data: x%x x%x\n",
  6331. pmbox->vport ? pmbox->vport->vpi : 0,
  6332. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6333. goto out_not_finished;
  6334. }
  6335. }
  6336. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6337. /* Polling for a mbox command when another one is already active
  6338. * is not allowed in SLI. Also, the driver must have established
  6339. * SLI2 mode to queue and process multiple mbox commands.
  6340. */
  6341. if (flag & MBX_POLL) {
  6342. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6343. /* Mbox command <mbxCommand> cannot issue */
  6344. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6345. "(%d):2529 Mailbox command x%x "
  6346. "cannot issue Data: x%x x%x\n",
  6347. pmbox->vport ? pmbox->vport->vpi : 0,
  6348. pmbox->u.mb.mbxCommand,
  6349. psli->sli_flag, flag);
  6350. goto out_not_finished;
  6351. }
  6352. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6353. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6354. /* Mbox command <mbxCommand> cannot issue */
  6355. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6356. "(%d):2530 Mailbox command x%x "
  6357. "cannot issue Data: x%x x%x\n",
  6358. pmbox->vport ? pmbox->vport->vpi : 0,
  6359. pmbox->u.mb.mbxCommand,
  6360. psli->sli_flag, flag);
  6361. goto out_not_finished;
  6362. }
  6363. /* Another mailbox command is still being processed, queue this
  6364. * command to be processed later.
  6365. */
  6366. lpfc_mbox_put(phba, pmbox);
  6367. /* Mbox cmd issue - BUSY */
  6368. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6369. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6370. "x%x x%x x%x x%x\n",
  6371. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6372. mbx->mbxCommand, phba->pport->port_state,
  6373. psli->sli_flag, flag);
  6374. psli->slistat.mbox_busy++;
  6375. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6376. if (pmbox->vport) {
  6377. lpfc_debugfs_disc_trc(pmbox->vport,
  6378. LPFC_DISC_TRC_MBOX_VPORT,
  6379. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6380. (uint32_t)mbx->mbxCommand,
  6381. mbx->un.varWords[0], mbx->un.varWords[1]);
  6382. }
  6383. else {
  6384. lpfc_debugfs_disc_trc(phba->pport,
  6385. LPFC_DISC_TRC_MBOX,
  6386. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6387. (uint32_t)mbx->mbxCommand,
  6388. mbx->un.varWords[0], mbx->un.varWords[1]);
  6389. }
  6390. return MBX_BUSY;
  6391. }
  6392. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6393. /* If we are not polling, we MUST be in SLI2 mode */
  6394. if (flag != MBX_POLL) {
  6395. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6396. (mbx->mbxCommand != MBX_KILL_BOARD)) {
  6397. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6398. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6399. /* Mbox command <mbxCommand> cannot issue */
  6400. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6401. "(%d):2531 Mailbox command x%x "
  6402. "cannot issue Data: x%x x%x\n",
  6403. pmbox->vport ? pmbox->vport->vpi : 0,
  6404. pmbox->u.mb.mbxCommand,
  6405. psli->sli_flag, flag);
  6406. goto out_not_finished;
  6407. }
  6408. /* timeout active mbox command */
  6409. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6410. 1000);
  6411. mod_timer(&psli->mbox_tmo, jiffies + timeout);
  6412. }
  6413. /* Mailbox cmd <cmd> issue */
  6414. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6415. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6416. "x%x\n",
  6417. pmbox->vport ? pmbox->vport->vpi : 0,
  6418. mbx->mbxCommand, phba->pport->port_state,
  6419. psli->sli_flag, flag);
  6420. if (mbx->mbxCommand != MBX_HEARTBEAT) {
  6421. if (pmbox->vport) {
  6422. lpfc_debugfs_disc_trc(pmbox->vport,
  6423. LPFC_DISC_TRC_MBOX_VPORT,
  6424. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6425. (uint32_t)mbx->mbxCommand,
  6426. mbx->un.varWords[0], mbx->un.varWords[1]);
  6427. }
  6428. else {
  6429. lpfc_debugfs_disc_trc(phba->pport,
  6430. LPFC_DISC_TRC_MBOX,
  6431. "MBOX Send: cmd:x%x mb:x%x x%x",
  6432. (uint32_t)mbx->mbxCommand,
  6433. mbx->un.varWords[0], mbx->un.varWords[1]);
  6434. }
  6435. }
  6436. psli->slistat.mbox_cmd++;
  6437. evtctr = psli->slistat.mbox_event;
  6438. /* next set own bit for the adapter and copy over command word */
  6439. mbx->mbxOwner = OWN_CHIP;
  6440. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6441. /* Populate mbox extension offset word. */
  6442. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6443. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6444. = (uint8_t *)phba->mbox_ext
  6445. - (uint8_t *)phba->mbox;
  6446. }
  6447. /* Copy the mailbox extension data */
  6448. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6449. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6450. (uint8_t *)phba->mbox_ext,
  6451. pmbox->in_ext_byte_len);
  6452. }
  6453. /* Copy command data to host SLIM area */
  6454. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6455. } else {
  6456. /* Populate mbox extension offset word. */
  6457. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6458. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6459. = MAILBOX_HBA_EXT_OFFSET;
  6460. /* Copy the mailbox extension data */
  6461. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6462. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6463. MAILBOX_HBA_EXT_OFFSET,
  6464. pmbox->context2, pmbox->in_ext_byte_len);
  6465. }
  6466. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6467. /* copy command data into host mbox for cmpl */
  6468. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6469. }
  6470. /* First copy mbox command data to HBA SLIM, skip past first
  6471. word */
  6472. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6473. lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
  6474. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6475. /* Next copy over first word, with mbxOwner set */
  6476. ldata = *((uint32_t *)mbx);
  6477. to_slim = phba->MBslimaddr;
  6478. writel(ldata, to_slim);
  6479. readl(to_slim); /* flush */
  6480. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6481. /* switch over to host mailbox */
  6482. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6483. }
  6484. }
  6485. wmb();
  6486. switch (flag) {
  6487. case MBX_NOWAIT:
  6488. /* Set up reference to mailbox command */
  6489. psli->mbox_active = pmbox;
  6490. /* Interrupt board to do it */
  6491. writel(CA_MBATT, phba->CAregaddr);
  6492. readl(phba->CAregaddr); /* flush */
  6493. /* Don't wait for it to finish, just return */
  6494. break;
  6495. case MBX_POLL:
  6496. /* Set up null reference to mailbox command */
  6497. psli->mbox_active = NULL;
  6498. /* Interrupt board to do it */
  6499. writel(CA_MBATT, phba->CAregaddr);
  6500. readl(phba->CAregaddr); /* flush */
  6501. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6502. /* First read mbox status word */
  6503. word0 = *((uint32_t *)phba->mbox);
  6504. word0 = le32_to_cpu(word0);
  6505. } else {
  6506. /* First read mbox status word */
  6507. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6508. spin_unlock_irqrestore(&phba->hbalock,
  6509. drvr_flag);
  6510. goto out_not_finished;
  6511. }
  6512. }
  6513. /* Read the HBA Host Attention Register */
  6514. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6515. spin_unlock_irqrestore(&phba->hbalock,
  6516. drvr_flag);
  6517. goto out_not_finished;
  6518. }
  6519. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6520. 1000) + jiffies;
  6521. i = 0;
  6522. /* Wait for command to complete */
  6523. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6524. (!(ha_copy & HA_MBATT) &&
  6525. (phba->link_state > LPFC_WARM_START))) {
  6526. if (time_after(jiffies, timeout)) {
  6527. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6528. spin_unlock_irqrestore(&phba->hbalock,
  6529. drvr_flag);
  6530. goto out_not_finished;
  6531. }
  6532. /* Check if we took a mbox interrupt while we were
  6533. polling */
  6534. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6535. && (evtctr != psli->slistat.mbox_event))
  6536. break;
  6537. if (i++ > 10) {
  6538. spin_unlock_irqrestore(&phba->hbalock,
  6539. drvr_flag);
  6540. msleep(1);
  6541. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6542. }
  6543. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6544. /* First copy command data */
  6545. word0 = *((uint32_t *)phba->mbox);
  6546. word0 = le32_to_cpu(word0);
  6547. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6548. MAILBOX_t *slimmb;
  6549. uint32_t slimword0;
  6550. /* Check real SLIM for any errors */
  6551. slimword0 = readl(phba->MBslimaddr);
  6552. slimmb = (MAILBOX_t *) & slimword0;
  6553. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6554. && slimmb->mbxStatus) {
  6555. psli->sli_flag &=
  6556. ~LPFC_SLI_ACTIVE;
  6557. word0 = slimword0;
  6558. }
  6559. }
  6560. } else {
  6561. /* First copy command data */
  6562. word0 = readl(phba->MBslimaddr);
  6563. }
  6564. /* Read the HBA Host Attention Register */
  6565. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6566. spin_unlock_irqrestore(&phba->hbalock,
  6567. drvr_flag);
  6568. goto out_not_finished;
  6569. }
  6570. }
  6571. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6572. /* copy results back to user */
  6573. lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE);
  6574. /* Copy the mailbox extension data */
  6575. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6576. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6577. pmbox->context2,
  6578. pmbox->out_ext_byte_len);
  6579. }
  6580. } else {
  6581. /* First copy command data */
  6582. lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
  6583. MAILBOX_CMD_SIZE);
  6584. /* Copy the mailbox extension data */
  6585. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6586. lpfc_memcpy_from_slim(pmbox->context2,
  6587. phba->MBslimaddr +
  6588. MAILBOX_HBA_EXT_OFFSET,
  6589. pmbox->out_ext_byte_len);
  6590. }
  6591. }
  6592. writel(HA_MBATT, phba->HAregaddr);
  6593. readl(phba->HAregaddr); /* flush */
  6594. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6595. status = mbx->mbxStatus;
  6596. }
  6597. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6598. return status;
  6599. out_not_finished:
  6600. if (processing_queue) {
  6601. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6602. lpfc_mbox_cmpl_put(phba, pmbox);
  6603. }
  6604. return MBX_NOT_FINISHED;
  6605. }
  6606. /**
  6607. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6608. * @phba: Pointer to HBA context object.
  6609. *
  6610. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6611. * the driver internal pending mailbox queue. It will then try to wait out the
  6612. * possible outstanding mailbox command before return.
  6613. *
  6614. * Returns:
  6615. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6616. * the outstanding mailbox command timed out.
  6617. **/
  6618. static int
  6619. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6620. {
  6621. struct lpfc_sli *psli = &phba->sli;
  6622. int rc = 0;
  6623. unsigned long timeout = 0;
  6624. /* Mark the asynchronous mailbox command posting as blocked */
  6625. spin_lock_irq(&phba->hbalock);
  6626. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6627. /* Determine how long we might wait for the active mailbox
  6628. * command to be gracefully completed by firmware.
  6629. */
  6630. if (phba->sli.mbox_active)
  6631. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6632. phba->sli.mbox_active) *
  6633. 1000) + jiffies;
  6634. spin_unlock_irq(&phba->hbalock);
  6635. /* Make sure the mailbox is really active */
  6636. if (timeout)
  6637. lpfc_sli4_process_missed_mbox_completions(phba);
  6638. /* Wait for the outstnading mailbox command to complete */
  6639. while (phba->sli.mbox_active) {
  6640. /* Check active mailbox complete status every 2ms */
  6641. msleep(2);
  6642. if (time_after(jiffies, timeout)) {
  6643. /* Timeout, marked the outstanding cmd not complete */
  6644. rc = 1;
  6645. break;
  6646. }
  6647. }
  6648. /* Can not cleanly block async mailbox command, fails it */
  6649. if (rc) {
  6650. spin_lock_irq(&phba->hbalock);
  6651. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6652. spin_unlock_irq(&phba->hbalock);
  6653. }
  6654. return rc;
  6655. }
  6656. /**
  6657. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6658. * @phba: Pointer to HBA context object.
  6659. *
  6660. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6661. * commands from the driver internal pending mailbox queue. It makes sure
  6662. * that there is no outstanding mailbox command before resuming posting
  6663. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6664. * mailbox command, it will try to wait it out before resuming asynchronous
  6665. * mailbox command posting.
  6666. **/
  6667. static void
  6668. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6669. {
  6670. struct lpfc_sli *psli = &phba->sli;
  6671. spin_lock_irq(&phba->hbalock);
  6672. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6673. /* Asynchronous mailbox posting is not blocked, do nothing */
  6674. spin_unlock_irq(&phba->hbalock);
  6675. return;
  6676. }
  6677. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6678. * successful or timeout, after timing-out the outstanding mailbox
  6679. * command shall always be removed, so just unblock posting async
  6680. * mailbox command and resume
  6681. */
  6682. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6683. spin_unlock_irq(&phba->hbalock);
  6684. /* wake up worker thread to post asynchronlous mailbox command */
  6685. lpfc_worker_wake_up(phba);
  6686. }
  6687. /**
  6688. * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
  6689. * @phba: Pointer to HBA context object.
  6690. * @mboxq: Pointer to mailbox object.
  6691. *
  6692. * The function waits for the bootstrap mailbox register ready bit from
  6693. * port for twice the regular mailbox command timeout value.
  6694. *
  6695. * 0 - no timeout on waiting for bootstrap mailbox register ready.
  6696. * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
  6697. **/
  6698. static int
  6699. lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6700. {
  6701. uint32_t db_ready;
  6702. unsigned long timeout;
  6703. struct lpfc_register bmbx_reg;
  6704. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6705. * 1000) + jiffies;
  6706. do {
  6707. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6708. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6709. if (!db_ready)
  6710. msleep(2);
  6711. if (time_after(jiffies, timeout))
  6712. return MBXERR_ERROR;
  6713. } while (!db_ready);
  6714. return 0;
  6715. }
  6716. /**
  6717. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6718. * @phba: Pointer to HBA context object.
  6719. * @mboxq: Pointer to mailbox object.
  6720. *
  6721. * The function posts a mailbox to the port. The mailbox is expected
  6722. * to be comletely filled in and ready for the port to operate on it.
  6723. * This routine executes a synchronous completion operation on the
  6724. * mailbox by polling for its completion.
  6725. *
  6726. * The caller must not be holding any locks when calling this routine.
  6727. *
  6728. * Returns:
  6729. * MBX_SUCCESS - mailbox posted successfully
  6730. * Any of the MBX error values.
  6731. **/
  6732. static int
  6733. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6734. {
  6735. int rc = MBX_SUCCESS;
  6736. unsigned long iflag;
  6737. uint32_t mcqe_status;
  6738. uint32_t mbx_cmnd;
  6739. struct lpfc_sli *psli = &phba->sli;
  6740. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6741. struct lpfc_bmbx_create *mbox_rgn;
  6742. struct dma_address *dma_address;
  6743. /*
  6744. * Only one mailbox can be active to the bootstrap mailbox region
  6745. * at a time and there is no queueing provided.
  6746. */
  6747. spin_lock_irqsave(&phba->hbalock, iflag);
  6748. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6749. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6750. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6751. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6752. "cannot issue Data: x%x x%x\n",
  6753. mboxq->vport ? mboxq->vport->vpi : 0,
  6754. mboxq->u.mb.mbxCommand,
  6755. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6756. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6757. psli->sli_flag, MBX_POLL);
  6758. return MBXERR_ERROR;
  6759. }
  6760. /* The server grabs the token and owns it until release */
  6761. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6762. phba->sli.mbox_active = mboxq;
  6763. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6764. /* wait for bootstrap mbox register for readyness */
  6765. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6766. if (rc)
  6767. goto exit;
  6768. /*
  6769. * Initialize the bootstrap memory region to avoid stale data areas
  6770. * in the mailbox post. Then copy the caller's mailbox contents to
  6771. * the bmbx mailbox region.
  6772. */
  6773. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6774. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6775. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6776. sizeof(struct lpfc_mqe));
  6777. /* Post the high mailbox dma address to the port and wait for ready. */
  6778. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6779. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6780. /* wait for bootstrap mbox register for hi-address write done */
  6781. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6782. if (rc)
  6783. goto exit;
  6784. /* Post the low mailbox dma address to the port. */
  6785. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6786. /* wait for bootstrap mbox register for low address write done */
  6787. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6788. if (rc)
  6789. goto exit;
  6790. /*
  6791. * Read the CQ to ensure the mailbox has completed.
  6792. * If so, update the mailbox status so that the upper layers
  6793. * can complete the request normally.
  6794. */
  6795. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6796. sizeof(struct lpfc_mqe));
  6797. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6798. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6799. sizeof(struct lpfc_mcqe));
  6800. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6801. /*
  6802. * When the CQE status indicates a failure and the mailbox status
  6803. * indicates success then copy the CQE status into the mailbox status
  6804. * (and prefix it with x4000).
  6805. */
  6806. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6807. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6808. bf_set(lpfc_mqe_status, mb,
  6809. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6810. rc = MBXERR_ERROR;
  6811. } else
  6812. lpfc_sli4_swap_str(phba, mboxq);
  6813. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6814. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6815. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6816. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6817. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6818. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6819. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6820. bf_get(lpfc_mqe_status, mb),
  6821. mb->un.mb_words[0], mb->un.mb_words[1],
  6822. mb->un.mb_words[2], mb->un.mb_words[3],
  6823. mb->un.mb_words[4], mb->un.mb_words[5],
  6824. mb->un.mb_words[6], mb->un.mb_words[7],
  6825. mb->un.mb_words[8], mb->un.mb_words[9],
  6826. mb->un.mb_words[10], mb->un.mb_words[11],
  6827. mb->un.mb_words[12], mboxq->mcqe.word0,
  6828. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6829. mboxq->mcqe.trailer);
  6830. exit:
  6831. /* We are holding the token, no needed for lock when release */
  6832. spin_lock_irqsave(&phba->hbalock, iflag);
  6833. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6834. phba->sli.mbox_active = NULL;
  6835. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6836. return rc;
  6837. }
  6838. /**
  6839. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6840. * @phba: Pointer to HBA context object.
  6841. * @pmbox: Pointer to mailbox object.
  6842. * @flag: Flag indicating how the mailbox need to be processed.
  6843. *
  6844. * This function is called by discovery code and HBA management code to submit
  6845. * a mailbox command to firmware with SLI-4 interface spec.
  6846. *
  6847. * Return codes the caller owns the mailbox command after the return of the
  6848. * function.
  6849. **/
  6850. static int
  6851. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6852. uint32_t flag)
  6853. {
  6854. struct lpfc_sli *psli = &phba->sli;
  6855. unsigned long iflags;
  6856. int rc;
  6857. /* dump from issue mailbox command if setup */
  6858. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6859. rc = lpfc_mbox_dev_check(phba);
  6860. if (unlikely(rc)) {
  6861. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6862. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6863. "cannot issue Data: x%x x%x\n",
  6864. mboxq->vport ? mboxq->vport->vpi : 0,
  6865. mboxq->u.mb.mbxCommand,
  6866. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6867. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6868. psli->sli_flag, flag);
  6869. goto out_not_finished;
  6870. }
  6871. /* Detect polling mode and jump to a handler */
  6872. if (!phba->sli4_hba.intr_enable) {
  6873. if (flag == MBX_POLL)
  6874. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6875. else
  6876. rc = -EIO;
  6877. if (rc != MBX_SUCCESS)
  6878. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6879. "(%d):2541 Mailbox command x%x "
  6880. "(x%x/x%x) failure: "
  6881. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6882. "Data: x%x x%x\n,",
  6883. mboxq->vport ? mboxq->vport->vpi : 0,
  6884. mboxq->u.mb.mbxCommand,
  6885. lpfc_sli_config_mbox_subsys_get(phba,
  6886. mboxq),
  6887. lpfc_sli_config_mbox_opcode_get(phba,
  6888. mboxq),
  6889. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6890. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6891. bf_get(lpfc_mcqe_ext_status,
  6892. &mboxq->mcqe),
  6893. psli->sli_flag, flag);
  6894. return rc;
  6895. } else if (flag == MBX_POLL) {
  6896. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6897. "(%d):2542 Try to issue mailbox command "
  6898. "x%x (x%x/x%x) synchronously ahead of async"
  6899. "mailbox command queue: x%x x%x\n",
  6900. mboxq->vport ? mboxq->vport->vpi : 0,
  6901. mboxq->u.mb.mbxCommand,
  6902. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6903. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6904. psli->sli_flag, flag);
  6905. /* Try to block the asynchronous mailbox posting */
  6906. rc = lpfc_sli4_async_mbox_block(phba);
  6907. if (!rc) {
  6908. /* Successfully blocked, now issue sync mbox cmd */
  6909. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6910. if (rc != MBX_SUCCESS)
  6911. lpfc_printf_log(phba, KERN_WARNING,
  6912. LOG_MBOX | LOG_SLI,
  6913. "(%d):2597 Sync Mailbox command "
  6914. "x%x (x%x/x%x) failure: "
  6915. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6916. "Data: x%x x%x\n,",
  6917. mboxq->vport ? mboxq->vport->vpi : 0,
  6918. mboxq->u.mb.mbxCommand,
  6919. lpfc_sli_config_mbox_subsys_get(phba,
  6920. mboxq),
  6921. lpfc_sli_config_mbox_opcode_get(phba,
  6922. mboxq),
  6923. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6924. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6925. bf_get(lpfc_mcqe_ext_status,
  6926. &mboxq->mcqe),
  6927. psli->sli_flag, flag);
  6928. /* Unblock the async mailbox posting afterward */
  6929. lpfc_sli4_async_mbox_unblock(phba);
  6930. }
  6931. return rc;
  6932. }
  6933. /* Now, interrupt mode asynchrous mailbox command */
  6934. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6935. if (rc) {
  6936. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6937. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6938. "cannot issue Data: x%x x%x\n",
  6939. mboxq->vport ? mboxq->vport->vpi : 0,
  6940. mboxq->u.mb.mbxCommand,
  6941. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6942. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6943. psli->sli_flag, flag);
  6944. goto out_not_finished;
  6945. }
  6946. /* Put the mailbox command to the driver internal FIFO */
  6947. psli->slistat.mbox_busy++;
  6948. spin_lock_irqsave(&phba->hbalock, iflags);
  6949. lpfc_mbox_put(phba, mboxq);
  6950. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6951. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6952. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6953. "x%x (x%x/x%x) x%x x%x x%x\n",
  6954. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6955. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6956. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6957. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6958. phba->pport->port_state,
  6959. psli->sli_flag, MBX_NOWAIT);
  6960. /* Wake up worker thread to transport mailbox command from head */
  6961. lpfc_worker_wake_up(phba);
  6962. return MBX_BUSY;
  6963. out_not_finished:
  6964. return MBX_NOT_FINISHED;
  6965. }
  6966. /**
  6967. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6968. * @phba: Pointer to HBA context object.
  6969. *
  6970. * This function is called by worker thread to send a mailbox command to
  6971. * SLI4 HBA firmware.
  6972. *
  6973. **/
  6974. int
  6975. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6976. {
  6977. struct lpfc_sli *psli = &phba->sli;
  6978. LPFC_MBOXQ_t *mboxq;
  6979. int rc = MBX_SUCCESS;
  6980. unsigned long iflags;
  6981. struct lpfc_mqe *mqe;
  6982. uint32_t mbx_cmnd;
  6983. /* Check interrupt mode before post async mailbox command */
  6984. if (unlikely(!phba->sli4_hba.intr_enable))
  6985. return MBX_NOT_FINISHED;
  6986. /* Check for mailbox command service token */
  6987. spin_lock_irqsave(&phba->hbalock, iflags);
  6988. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6989. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6990. return MBX_NOT_FINISHED;
  6991. }
  6992. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6993. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6994. return MBX_NOT_FINISHED;
  6995. }
  6996. if (unlikely(phba->sli.mbox_active)) {
  6997. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6998. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6999. "0384 There is pending active mailbox cmd\n");
  7000. return MBX_NOT_FINISHED;
  7001. }
  7002. /* Take the mailbox command service token */
  7003. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  7004. /* Get the next mailbox command from head of queue */
  7005. mboxq = lpfc_mbox_get(phba);
  7006. /* If no more mailbox command waiting for post, we're done */
  7007. if (!mboxq) {
  7008. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7009. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7010. return MBX_SUCCESS;
  7011. }
  7012. phba->sli.mbox_active = mboxq;
  7013. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7014. /* Check device readiness for posting mailbox command */
  7015. rc = lpfc_mbox_dev_check(phba);
  7016. if (unlikely(rc))
  7017. /* Driver clean routine will clean up pending mailbox */
  7018. goto out_not_finished;
  7019. /* Prepare the mbox command to be posted */
  7020. mqe = &mboxq->u.mqe;
  7021. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  7022. /* Start timer for the mbox_tmo and log some mailbox post messages */
  7023. mod_timer(&psli->mbox_tmo, (jiffies +
  7024. msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
  7025. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  7026. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  7027. "x%x x%x\n",
  7028. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  7029. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7030. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7031. phba->pport->port_state, psli->sli_flag);
  7032. if (mbx_cmnd != MBX_HEARTBEAT) {
  7033. if (mboxq->vport) {
  7034. lpfc_debugfs_disc_trc(mboxq->vport,
  7035. LPFC_DISC_TRC_MBOX_VPORT,
  7036. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  7037. mbx_cmnd, mqe->un.mb_words[0],
  7038. mqe->un.mb_words[1]);
  7039. } else {
  7040. lpfc_debugfs_disc_trc(phba->pport,
  7041. LPFC_DISC_TRC_MBOX,
  7042. "MBOX Send: cmd:x%x mb:x%x x%x",
  7043. mbx_cmnd, mqe->un.mb_words[0],
  7044. mqe->un.mb_words[1]);
  7045. }
  7046. }
  7047. psli->slistat.mbox_cmd++;
  7048. /* Post the mailbox command to the port */
  7049. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  7050. if (rc != MBX_SUCCESS) {
  7051. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  7052. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  7053. "cannot issue Data: x%x x%x\n",
  7054. mboxq->vport ? mboxq->vport->vpi : 0,
  7055. mboxq->u.mb.mbxCommand,
  7056. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  7057. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  7058. psli->sli_flag, MBX_NOWAIT);
  7059. goto out_not_finished;
  7060. }
  7061. return rc;
  7062. out_not_finished:
  7063. spin_lock_irqsave(&phba->hbalock, iflags);
  7064. if (phba->sli.mbox_active) {
  7065. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  7066. __lpfc_mbox_cmpl_put(phba, mboxq);
  7067. /* Release the token */
  7068. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7069. phba->sli.mbox_active = NULL;
  7070. }
  7071. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7072. return MBX_NOT_FINISHED;
  7073. }
  7074. /**
  7075. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  7076. * @phba: Pointer to HBA context object.
  7077. * @pmbox: Pointer to mailbox object.
  7078. * @flag: Flag indicating how the mailbox need to be processed.
  7079. *
  7080. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  7081. * the API jump table function pointer from the lpfc_hba struct.
  7082. *
  7083. * Return codes the caller owns the mailbox command after the return of the
  7084. * function.
  7085. **/
  7086. int
  7087. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  7088. {
  7089. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  7090. }
  7091. /**
  7092. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  7093. * @phba: The hba struct for which this call is being executed.
  7094. * @dev_grp: The HBA PCI-Device group number.
  7095. *
  7096. * This routine sets up the mbox interface API function jump table in @phba
  7097. * struct.
  7098. * Returns: 0 - success, -ENODEV - failure.
  7099. **/
  7100. int
  7101. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7102. {
  7103. switch (dev_grp) {
  7104. case LPFC_PCI_DEV_LP:
  7105. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  7106. phba->lpfc_sli_handle_slow_ring_event =
  7107. lpfc_sli_handle_slow_ring_event_s3;
  7108. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  7109. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  7110. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  7111. break;
  7112. case LPFC_PCI_DEV_OC:
  7113. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  7114. phba->lpfc_sli_handle_slow_ring_event =
  7115. lpfc_sli_handle_slow_ring_event_s4;
  7116. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  7117. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  7118. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  7119. break;
  7120. default:
  7121. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7122. "1420 Invalid HBA PCI-device group: 0x%x\n",
  7123. dev_grp);
  7124. return -ENODEV;
  7125. break;
  7126. }
  7127. return 0;
  7128. }
  7129. /**
  7130. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  7131. * @phba: Pointer to HBA context object.
  7132. * @pring: Pointer to driver SLI ring object.
  7133. * @piocb: Pointer to address of newly added command iocb.
  7134. *
  7135. * This function is called with hbalock held to add a command
  7136. * iocb to the txq when SLI layer cannot submit the command iocb
  7137. * to the ring.
  7138. **/
  7139. void
  7140. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7141. struct lpfc_iocbq *piocb)
  7142. {
  7143. /* Insert the caller's iocb in the txq tail for later processing. */
  7144. list_add_tail(&piocb->list, &pring->txq);
  7145. }
  7146. /**
  7147. * lpfc_sli_next_iocb - Get the next iocb in the txq
  7148. * @phba: Pointer to HBA context object.
  7149. * @pring: Pointer to driver SLI ring object.
  7150. * @piocb: Pointer to address of newly added command iocb.
  7151. *
  7152. * This function is called with hbalock held before a new
  7153. * iocb is submitted to the firmware. This function checks
  7154. * txq to flush the iocbs in txq to Firmware before
  7155. * submitting new iocbs to the Firmware.
  7156. * If there are iocbs in the txq which need to be submitted
  7157. * to firmware, lpfc_sli_next_iocb returns the first element
  7158. * of the txq after dequeuing it from txq.
  7159. * If there is no iocb in the txq then the function will return
  7160. * *piocb and *piocb is set to NULL. Caller needs to check
  7161. * *piocb to find if there are more commands in the txq.
  7162. **/
  7163. static struct lpfc_iocbq *
  7164. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  7165. struct lpfc_iocbq **piocb)
  7166. {
  7167. struct lpfc_iocbq * nextiocb;
  7168. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  7169. if (!nextiocb) {
  7170. nextiocb = *piocb;
  7171. *piocb = NULL;
  7172. }
  7173. return nextiocb;
  7174. }
  7175. /**
  7176. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  7177. * @phba: Pointer to HBA context object.
  7178. * @ring_number: SLI ring number to issue iocb on.
  7179. * @piocb: Pointer to command iocb.
  7180. * @flag: Flag indicating if this command can be put into txq.
  7181. *
  7182. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  7183. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  7184. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  7185. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  7186. * this function allows only iocbs for posting buffers. This function finds
  7187. * next available slot in the command ring and posts the command to the
  7188. * available slot and writes the port attention register to request HBA start
  7189. * processing new iocb. If there is no slot available in the ring and
  7190. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  7191. * the function returns IOCB_BUSY.
  7192. *
  7193. * This function is called with hbalock held. The function will return success
  7194. * after it successfully submit the iocb to firmware or after adding to the
  7195. * txq.
  7196. **/
  7197. static int
  7198. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  7199. struct lpfc_iocbq *piocb, uint32_t flag)
  7200. {
  7201. struct lpfc_iocbq *nextiocb;
  7202. IOCB_t *iocb;
  7203. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7204. if (piocb->iocb_cmpl && (!piocb->vport) &&
  7205. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  7206. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  7207. lpfc_printf_log(phba, KERN_ERR,
  7208. LOG_SLI | LOG_VPORT,
  7209. "1807 IOCB x%x failed. No vport\n",
  7210. piocb->iocb.ulpCommand);
  7211. dump_stack();
  7212. return IOCB_ERROR;
  7213. }
  7214. /* If the PCI channel is in offline state, do not post iocbs. */
  7215. if (unlikely(pci_channel_offline(phba->pcidev)))
  7216. return IOCB_ERROR;
  7217. /* If HBA has a deferred error attention, fail the iocb. */
  7218. if (unlikely(phba->hba_flag & DEFER_ERATT))
  7219. return IOCB_ERROR;
  7220. /*
  7221. * We should never get an IOCB if we are in a < LINK_DOWN state
  7222. */
  7223. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7224. return IOCB_ERROR;
  7225. /*
  7226. * Check to see if we are blocking IOCB processing because of a
  7227. * outstanding event.
  7228. */
  7229. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  7230. goto iocb_busy;
  7231. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  7232. /*
  7233. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  7234. * can be issued if the link is not up.
  7235. */
  7236. switch (piocb->iocb.ulpCommand) {
  7237. case CMD_GEN_REQUEST64_CR:
  7238. case CMD_GEN_REQUEST64_CX:
  7239. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  7240. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  7241. FC_RCTL_DD_UNSOL_CMD) ||
  7242. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  7243. MENLO_TRANSPORT_TYPE))
  7244. goto iocb_busy;
  7245. break;
  7246. case CMD_QUE_RING_BUF_CN:
  7247. case CMD_QUE_RING_BUF64_CN:
  7248. /*
  7249. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  7250. * completion, iocb_cmpl MUST be 0.
  7251. */
  7252. if (piocb->iocb_cmpl)
  7253. piocb->iocb_cmpl = NULL;
  7254. /*FALLTHROUGH*/
  7255. case CMD_CREATE_XRI_CR:
  7256. case CMD_CLOSE_XRI_CN:
  7257. case CMD_CLOSE_XRI_CX:
  7258. break;
  7259. default:
  7260. goto iocb_busy;
  7261. }
  7262. /*
  7263. * For FCP commands, we must be in a state where we can process link
  7264. * attention events.
  7265. */
  7266. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  7267. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  7268. goto iocb_busy;
  7269. }
  7270. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  7271. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  7272. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  7273. if (iocb)
  7274. lpfc_sli_update_ring(phba, pring);
  7275. else
  7276. lpfc_sli_update_full_ring(phba, pring);
  7277. if (!piocb)
  7278. return IOCB_SUCCESS;
  7279. goto out_busy;
  7280. iocb_busy:
  7281. pring->stats.iocb_cmd_delay++;
  7282. out_busy:
  7283. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7284. __lpfc_sli_ringtx_put(phba, pring, piocb);
  7285. return IOCB_SUCCESS;
  7286. }
  7287. return IOCB_BUSY;
  7288. }
  7289. /**
  7290. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  7291. * @phba: Pointer to HBA context object.
  7292. * @piocb: Pointer to command iocb.
  7293. * @sglq: Pointer to the scatter gather queue object.
  7294. *
  7295. * This routine converts the bpl or bde that is in the IOCB
  7296. * to a sgl list for the sli4 hardware. The physical address
  7297. * of the bpl/bde is converted back to a virtual address.
  7298. * If the IOCB contains a BPL then the list of BDE's is
  7299. * converted to sli4_sge's. If the IOCB contains a single
  7300. * BDE then it is converted to a single sli_sge.
  7301. * The IOCB is still in cpu endianess so the contents of
  7302. * the bpl can be used without byte swapping.
  7303. *
  7304. * Returns valid XRI = Success, NO_XRI = Failure.
  7305. **/
  7306. static uint16_t
  7307. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  7308. struct lpfc_sglq *sglq)
  7309. {
  7310. uint16_t xritag = NO_XRI;
  7311. struct ulp_bde64 *bpl = NULL;
  7312. struct ulp_bde64 bde;
  7313. struct sli4_sge *sgl = NULL;
  7314. struct lpfc_dmabuf *dmabuf;
  7315. IOCB_t *icmd;
  7316. int numBdes = 0;
  7317. int i = 0;
  7318. uint32_t offset = 0; /* accumulated offset in the sg request list */
  7319. int inbound = 0; /* number of sg reply entries inbound from firmware */
  7320. if (!piocbq || !sglq)
  7321. return xritag;
  7322. sgl = (struct sli4_sge *)sglq->sgl;
  7323. icmd = &piocbq->iocb;
  7324. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  7325. return sglq->sli4_xritag;
  7326. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7327. numBdes = icmd->un.genreq64.bdl.bdeSize /
  7328. sizeof(struct ulp_bde64);
  7329. /* The addrHigh and addrLow fields within the IOCB
  7330. * have not been byteswapped yet so there is no
  7331. * need to swap them back.
  7332. */
  7333. if (piocbq->context3)
  7334. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7335. else
  7336. return xritag;
  7337. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7338. if (!bpl)
  7339. return xritag;
  7340. for (i = 0; i < numBdes; i++) {
  7341. /* Should already be byte swapped. */
  7342. sgl->addr_hi = bpl->addrHigh;
  7343. sgl->addr_lo = bpl->addrLow;
  7344. sgl->word2 = le32_to_cpu(sgl->word2);
  7345. if ((i+1) == numBdes)
  7346. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7347. else
  7348. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7349. /* swap the size field back to the cpu so we
  7350. * can assign it to the sgl.
  7351. */
  7352. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7353. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7354. /* The offsets in the sgl need to be accumulated
  7355. * separately for the request and reply lists.
  7356. * The request is always first, the reply follows.
  7357. */
  7358. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7359. /* add up the reply sg entries */
  7360. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7361. inbound++;
  7362. /* first inbound? reset the offset */
  7363. if (inbound == 1)
  7364. offset = 0;
  7365. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7366. bf_set(lpfc_sli4_sge_type, sgl,
  7367. LPFC_SGE_TYPE_DATA);
  7368. offset += bde.tus.f.bdeSize;
  7369. }
  7370. sgl->word2 = cpu_to_le32(sgl->word2);
  7371. bpl++;
  7372. sgl++;
  7373. }
  7374. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7375. /* The addrHigh and addrLow fields of the BDE have not
  7376. * been byteswapped yet so they need to be swapped
  7377. * before putting them in the sgl.
  7378. */
  7379. sgl->addr_hi =
  7380. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7381. sgl->addr_lo =
  7382. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7383. sgl->word2 = le32_to_cpu(sgl->word2);
  7384. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7385. sgl->word2 = cpu_to_le32(sgl->word2);
  7386. sgl->sge_len =
  7387. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7388. }
  7389. return sglq->sli4_xritag;
  7390. }
  7391. /**
  7392. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7393. * @phba: Pointer to HBA context object.
  7394. * @piocb: Pointer to command iocb.
  7395. * @wqe: Pointer to the work queue entry.
  7396. *
  7397. * This routine converts the iocb command to its Work Queue Entry
  7398. * equivalent. The wqe pointer should not have any fields set when
  7399. * this routine is called because it will memcpy over them.
  7400. * This routine does not set the CQ_ID or the WQEC bits in the
  7401. * wqe.
  7402. *
  7403. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7404. **/
  7405. static int
  7406. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7407. union lpfc_wqe *wqe)
  7408. {
  7409. uint32_t xmit_len = 0, total_len = 0;
  7410. uint8_t ct = 0;
  7411. uint32_t fip;
  7412. uint32_t abort_tag;
  7413. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7414. uint8_t cmnd;
  7415. uint16_t xritag;
  7416. uint16_t abrt_iotag;
  7417. struct lpfc_iocbq *abrtiocbq;
  7418. struct ulp_bde64 *bpl = NULL;
  7419. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7420. int numBdes, i;
  7421. struct ulp_bde64 bde;
  7422. struct lpfc_nodelist *ndlp;
  7423. uint32_t *pcmd;
  7424. uint32_t if_type;
  7425. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7426. /* The fcp commands will set command type */
  7427. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7428. command_type = FCP_COMMAND;
  7429. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7430. command_type = ELS_COMMAND_FIP;
  7431. else
  7432. command_type = ELS_COMMAND_NON_FIP;
  7433. /* Some of the fields are in the right position already */
  7434. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7435. abort_tag = (uint32_t) iocbq->iotag;
  7436. xritag = iocbq->sli4_xritag;
  7437. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7438. wqe->generic.wqe_com.word10 = 0;
  7439. /* words0-2 bpl convert bde */
  7440. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7441. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7442. sizeof(struct ulp_bde64);
  7443. bpl = (struct ulp_bde64 *)
  7444. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7445. if (!bpl)
  7446. return IOCB_ERROR;
  7447. /* Should already be byte swapped. */
  7448. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7449. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7450. /* swap the size field back to the cpu so we
  7451. * can assign it to the sgl.
  7452. */
  7453. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7454. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7455. total_len = 0;
  7456. for (i = 0; i < numBdes; i++) {
  7457. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7458. total_len += bde.tus.f.bdeSize;
  7459. }
  7460. } else
  7461. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7462. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7463. cmnd = iocbq->iocb.ulpCommand;
  7464. switch (iocbq->iocb.ulpCommand) {
  7465. case CMD_ELS_REQUEST64_CR:
  7466. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7467. ndlp = iocbq->context_un.ndlp;
  7468. else
  7469. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7470. if (!iocbq->iocb.ulpLe) {
  7471. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7472. "2007 Only Limited Edition cmd Format"
  7473. " supported 0x%x\n",
  7474. iocbq->iocb.ulpCommand);
  7475. return IOCB_ERROR;
  7476. }
  7477. wqe->els_req.payload_len = xmit_len;
  7478. /* Els_reguest64 has a TMO */
  7479. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7480. iocbq->iocb.ulpTimeout);
  7481. /* Need a VF for word 4 set the vf bit*/
  7482. bf_set(els_req64_vf, &wqe->els_req, 0);
  7483. /* And a VFID for word 12 */
  7484. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7485. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7486. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7487. iocbq->iocb.ulpContext);
  7488. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7489. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7490. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7491. if (command_type == ELS_COMMAND_FIP)
  7492. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7493. >> LPFC_FIP_ELS_ID_SHIFT);
  7494. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7495. iocbq->context2)->virt);
  7496. if_type = bf_get(lpfc_sli_intf_if_type,
  7497. &phba->sli4_hba.sli_intf);
  7498. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7499. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7500. *pcmd == ELS_CMD_SCR ||
  7501. *pcmd == ELS_CMD_FDISC ||
  7502. *pcmd == ELS_CMD_LOGO ||
  7503. *pcmd == ELS_CMD_PLOGI)) {
  7504. bf_set(els_req64_sp, &wqe->els_req, 1);
  7505. bf_set(els_req64_sid, &wqe->els_req,
  7506. iocbq->vport->fc_myDID);
  7507. if ((*pcmd == ELS_CMD_FLOGI) &&
  7508. !(phba->fc_topology ==
  7509. LPFC_TOPOLOGY_LOOP))
  7510. bf_set(els_req64_sid, &wqe->els_req, 0);
  7511. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7512. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7513. phba->vpi_ids[iocbq->vport->vpi]);
  7514. } else if (pcmd && iocbq->context1) {
  7515. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7516. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7517. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7518. }
  7519. }
  7520. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7521. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7522. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7523. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7524. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7525. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7526. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7527. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7528. wqe->els_req.max_response_payload_len = total_len - xmit_len;
  7529. break;
  7530. case CMD_XMIT_SEQUENCE64_CX:
  7531. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7532. iocbq->iocb.un.ulpWord[3]);
  7533. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7534. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7535. /* The entire sequence is transmitted for this IOCB */
  7536. xmit_len = total_len;
  7537. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7538. if (phba->link_flag & LS_LOOPBACK_MODE)
  7539. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7540. case CMD_XMIT_SEQUENCE64_CR:
  7541. /* word3 iocb=io_tag32 wqe=reserved */
  7542. wqe->xmit_sequence.rsvd3 = 0;
  7543. /* word4 relative_offset memcpy */
  7544. /* word5 r_ctl/df_ctl memcpy */
  7545. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7546. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7547. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7548. LPFC_WQE_IOD_WRITE);
  7549. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7550. LPFC_WQE_LENLOC_WORD12);
  7551. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7552. wqe->xmit_sequence.xmit_len = xmit_len;
  7553. command_type = OTHER_COMMAND;
  7554. break;
  7555. case CMD_XMIT_BCAST64_CN:
  7556. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7557. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7558. /* word4 iocb=rsvd wqe=rsvd */
  7559. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7560. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7561. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7562. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7563. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7564. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7565. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7566. LPFC_WQE_LENLOC_WORD3);
  7567. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7568. break;
  7569. case CMD_FCP_IWRITE64_CR:
  7570. command_type = FCP_COMMAND_DATA_OUT;
  7571. /* word3 iocb=iotag wqe=payload_offset_len */
  7572. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7573. bf_set(payload_offset_len, &wqe->fcp_iwrite,
  7574. xmit_len + sizeof(struct fcp_rsp));
  7575. bf_set(cmd_buff_len, &wqe->fcp_iwrite,
  7576. 0);
  7577. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7578. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7579. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7580. iocbq->iocb.ulpFCP2Rcvy);
  7581. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7582. /* Always open the exchange */
  7583. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7584. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7585. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7586. LPFC_WQE_LENLOC_WORD4);
  7587. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7588. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7589. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7590. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7591. bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
  7592. if (phba->cfg_XLanePriority) {
  7593. bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
  7594. bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
  7595. (phba->cfg_XLanePriority << 1));
  7596. }
  7597. }
  7598. break;
  7599. case CMD_FCP_IREAD64_CR:
  7600. /* word3 iocb=iotag wqe=payload_offset_len */
  7601. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7602. bf_set(payload_offset_len, &wqe->fcp_iread,
  7603. xmit_len + sizeof(struct fcp_rsp));
  7604. bf_set(cmd_buff_len, &wqe->fcp_iread,
  7605. 0);
  7606. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7607. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7608. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7609. iocbq->iocb.ulpFCP2Rcvy);
  7610. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7611. /* Always open the exchange */
  7612. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7613. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7614. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7615. LPFC_WQE_LENLOC_WORD4);
  7616. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7617. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7618. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7619. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7620. bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
  7621. if (phba->cfg_XLanePriority) {
  7622. bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
  7623. bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
  7624. (phba->cfg_XLanePriority << 1));
  7625. }
  7626. }
  7627. break;
  7628. case CMD_FCP_ICMND64_CR:
  7629. /* word3 iocb=iotag wqe=payload_offset_len */
  7630. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7631. bf_set(payload_offset_len, &wqe->fcp_icmd,
  7632. xmit_len + sizeof(struct fcp_rsp));
  7633. bf_set(cmd_buff_len, &wqe->fcp_icmd,
  7634. 0);
  7635. /* word3 iocb=IO_TAG wqe=reserved */
  7636. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7637. /* Always open the exchange */
  7638. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7639. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7640. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7641. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7642. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7643. LPFC_WQE_LENLOC_NONE);
  7644. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7645. bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
  7646. iocbq->iocb.ulpFCP2Rcvy);
  7647. if (iocbq->iocb_flag & LPFC_IO_OAS) {
  7648. bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
  7649. if (phba->cfg_XLanePriority) {
  7650. bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
  7651. bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
  7652. (phba->cfg_XLanePriority << 1));
  7653. }
  7654. }
  7655. break;
  7656. case CMD_GEN_REQUEST64_CR:
  7657. /* For this command calculate the xmit length of the
  7658. * request bde.
  7659. */
  7660. xmit_len = 0;
  7661. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7662. sizeof(struct ulp_bde64);
  7663. for (i = 0; i < numBdes; i++) {
  7664. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7665. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7666. break;
  7667. xmit_len += bde.tus.f.bdeSize;
  7668. }
  7669. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7670. wqe->gen_req.request_payload_len = xmit_len;
  7671. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7672. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7673. /* word6 context tag copied in memcpy */
  7674. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7675. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7676. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7677. "2015 Invalid CT %x command 0x%x\n",
  7678. ct, iocbq->iocb.ulpCommand);
  7679. return IOCB_ERROR;
  7680. }
  7681. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7682. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7683. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7684. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7685. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7686. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7687. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7688. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7689. wqe->gen_req.max_response_payload_len = total_len - xmit_len;
  7690. command_type = OTHER_COMMAND;
  7691. break;
  7692. case CMD_XMIT_ELS_RSP64_CX:
  7693. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7694. /* words0-2 BDE memcpy */
  7695. /* word3 iocb=iotag32 wqe=response_payload_len */
  7696. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7697. /* word4 */
  7698. wqe->xmit_els_rsp.word4 = 0;
  7699. /* word5 iocb=rsvd wge=did */
  7700. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7701. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7702. if_type = bf_get(lpfc_sli_intf_if_type,
  7703. &phba->sli4_hba.sli_intf);
  7704. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7705. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7706. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7707. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7708. iocbq->vport->fc_myDID);
  7709. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7710. bf_set(wqe_els_did,
  7711. &wqe->xmit_els_rsp.wqe_dest, 0);
  7712. }
  7713. }
  7714. }
  7715. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7716. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7717. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7718. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7719. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7720. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7721. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7722. phba->vpi_ids[iocbq->vport->vpi]);
  7723. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7724. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7725. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7726. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7727. LPFC_WQE_LENLOC_WORD3);
  7728. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7729. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7730. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7731. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7732. iocbq->context2)->virt);
  7733. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7734. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7735. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7736. iocbq->vport->fc_myDID);
  7737. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7738. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7739. phba->vpi_ids[phba->pport->vpi]);
  7740. }
  7741. command_type = OTHER_COMMAND;
  7742. break;
  7743. case CMD_CLOSE_XRI_CN:
  7744. case CMD_ABORT_XRI_CN:
  7745. case CMD_ABORT_XRI_CX:
  7746. /* words 0-2 memcpy should be 0 rserved */
  7747. /* port will send abts */
  7748. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7749. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7750. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7751. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7752. } else
  7753. fip = 0;
  7754. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7755. /*
  7756. * The link is down, or the command was ELS_FIP
  7757. * so the fw does not need to send abts
  7758. * on the wire.
  7759. */
  7760. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7761. else
  7762. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7763. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7764. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7765. wqe->abort_cmd.rsrvd5 = 0;
  7766. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7767. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7768. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7769. /*
  7770. * The abort handler will send us CMD_ABORT_XRI_CN or
  7771. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7772. */
  7773. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7774. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7775. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7776. LPFC_WQE_LENLOC_NONE);
  7777. cmnd = CMD_ABORT_XRI_CX;
  7778. command_type = OTHER_COMMAND;
  7779. xritag = 0;
  7780. break;
  7781. case CMD_XMIT_BLS_RSP64_CX:
  7782. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7783. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7784. * we re-construct this WQE here based on information in
  7785. * iocbq from scratch.
  7786. */
  7787. memset(wqe, 0, sizeof(union lpfc_wqe));
  7788. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7789. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7790. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7791. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7792. LPFC_ABTS_UNSOL_INT) {
  7793. /* ABTS sent by initiator to CT exchange, the
  7794. * RX_ID field will be filled with the newly
  7795. * allocated responder XRI.
  7796. */
  7797. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7798. iocbq->sli4_xritag);
  7799. } else {
  7800. /* ABTS sent by responder to CT exchange, the
  7801. * RX_ID field will be filled with the responder
  7802. * RX_ID from ABTS.
  7803. */
  7804. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7805. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7806. }
  7807. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7808. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7809. /* Use CT=VPI */
  7810. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7811. ndlp->nlp_DID);
  7812. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7813. iocbq->iocb.ulpContext);
  7814. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7815. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7816. phba->vpi_ids[phba->pport->vpi]);
  7817. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7818. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7819. LPFC_WQE_LENLOC_NONE);
  7820. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7821. command_type = OTHER_COMMAND;
  7822. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7823. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7824. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7825. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7826. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7827. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7828. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7829. }
  7830. break;
  7831. case CMD_XRI_ABORTED_CX:
  7832. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7833. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7834. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7835. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7836. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7837. default:
  7838. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7839. "2014 Invalid command 0x%x\n",
  7840. iocbq->iocb.ulpCommand);
  7841. return IOCB_ERROR;
  7842. break;
  7843. }
  7844. if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
  7845. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
  7846. else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
  7847. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
  7848. else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
  7849. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
  7850. iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
  7851. LPFC_IO_DIF_INSERT);
  7852. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7853. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7854. wqe->generic.wqe_com.abort_tag = abort_tag;
  7855. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7856. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7857. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7858. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7859. return 0;
  7860. }
  7861. /**
  7862. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7863. * @phba: Pointer to HBA context object.
  7864. * @ring_number: SLI ring number to issue iocb on.
  7865. * @piocb: Pointer to command iocb.
  7866. * @flag: Flag indicating if this command can be put into txq.
  7867. *
  7868. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7869. * an iocb command to an HBA with SLI-4 interface spec.
  7870. *
  7871. * This function is called with hbalock held. The function will return success
  7872. * after it successfully submit the iocb to firmware or after adding to the
  7873. * txq.
  7874. **/
  7875. static int
  7876. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7877. struct lpfc_iocbq *piocb, uint32_t flag)
  7878. {
  7879. struct lpfc_sglq *sglq;
  7880. union lpfc_wqe wqe;
  7881. struct lpfc_queue *wq;
  7882. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7883. if (piocb->sli4_xritag == NO_XRI) {
  7884. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7885. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7886. sglq = NULL;
  7887. else {
  7888. if (!list_empty(&pring->txq)) {
  7889. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7890. __lpfc_sli_ringtx_put(phba,
  7891. pring, piocb);
  7892. return IOCB_SUCCESS;
  7893. } else {
  7894. return IOCB_BUSY;
  7895. }
  7896. } else {
  7897. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7898. if (!sglq) {
  7899. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7900. __lpfc_sli_ringtx_put(phba,
  7901. pring,
  7902. piocb);
  7903. return IOCB_SUCCESS;
  7904. } else
  7905. return IOCB_BUSY;
  7906. }
  7907. }
  7908. }
  7909. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7910. /* These IO's already have an XRI and a mapped sgl. */
  7911. sglq = NULL;
  7912. } else {
  7913. /*
  7914. * This is a continuation of a commandi,(CX) so this
  7915. * sglq is on the active list
  7916. */
  7917. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
  7918. if (!sglq)
  7919. return IOCB_ERROR;
  7920. }
  7921. if (sglq) {
  7922. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7923. piocb->sli4_xritag = sglq->sli4_xritag;
  7924. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7925. return IOCB_ERROR;
  7926. }
  7927. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7928. return IOCB_ERROR;
  7929. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7930. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7931. if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) {
  7932. wq = phba->sli4_hba.fcp_wq[piocb->fcp_wqidx];
  7933. } else {
  7934. wq = phba->sli4_hba.oas_wq;
  7935. }
  7936. if (lpfc_sli4_wq_put(wq, &wqe))
  7937. return IOCB_ERROR;
  7938. } else {
  7939. if (unlikely(!phba->sli4_hba.els_wq))
  7940. return IOCB_ERROR;
  7941. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7942. return IOCB_ERROR;
  7943. }
  7944. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7945. return 0;
  7946. }
  7947. /**
  7948. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7949. *
  7950. * This routine wraps the actual lockless version for issusing IOCB function
  7951. * pointer from the lpfc_hba struct.
  7952. *
  7953. * Return codes:
  7954. * IOCB_ERROR - Error
  7955. * IOCB_SUCCESS - Success
  7956. * IOCB_BUSY - Busy
  7957. **/
  7958. int
  7959. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7960. struct lpfc_iocbq *piocb, uint32_t flag)
  7961. {
  7962. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7963. }
  7964. /**
  7965. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7966. * @phba: The hba struct for which this call is being executed.
  7967. * @dev_grp: The HBA PCI-Device group number.
  7968. *
  7969. * This routine sets up the SLI interface API function jump table in @phba
  7970. * struct.
  7971. * Returns: 0 - success, -ENODEV - failure.
  7972. **/
  7973. int
  7974. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7975. {
  7976. switch (dev_grp) {
  7977. case LPFC_PCI_DEV_LP:
  7978. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7979. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7980. break;
  7981. case LPFC_PCI_DEV_OC:
  7982. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7983. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7984. break;
  7985. default:
  7986. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7987. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7988. dev_grp);
  7989. return -ENODEV;
  7990. break;
  7991. }
  7992. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7993. return 0;
  7994. }
  7995. /**
  7996. * lpfc_sli_calc_ring - Calculates which ring to use
  7997. * @phba: Pointer to HBA context object.
  7998. * @ring_number: Initial ring
  7999. * @piocb: Pointer to command iocb.
  8000. *
  8001. * For SLI4, FCP IO can deferred to one fo many WQs, based on
  8002. * fcp_wqidx, thus we need to calculate the corresponding ring.
  8003. * Since ABORTS must go on the same WQ of the command they are
  8004. * aborting, we use command's fcp_wqidx.
  8005. */
  8006. int
  8007. lpfc_sli_calc_ring(struct lpfc_hba *phba, uint32_t ring_number,
  8008. struct lpfc_iocbq *piocb)
  8009. {
  8010. if (phba->sli_rev < LPFC_SLI_REV4)
  8011. return ring_number;
  8012. if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
  8013. if (!(phba->cfg_fof) ||
  8014. (!(piocb->iocb_flag & LPFC_IO_FOF))) {
  8015. if (unlikely(!phba->sli4_hba.fcp_wq))
  8016. return LPFC_HBA_ERROR;
  8017. /*
  8018. * for abort iocb fcp_wqidx should already
  8019. * be setup based on what work queue we used.
  8020. */
  8021. if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX))
  8022. piocb->fcp_wqidx =
  8023. lpfc_sli4_scmd_to_wqidx_distr(phba,
  8024. piocb->context1);
  8025. ring_number = MAX_SLI3_CONFIGURED_RINGS +
  8026. piocb->fcp_wqidx;
  8027. } else {
  8028. if (unlikely(!phba->sli4_hba.oas_wq))
  8029. return LPFC_HBA_ERROR;
  8030. piocb->fcp_wqidx = 0;
  8031. ring_number = LPFC_FCP_OAS_RING;
  8032. }
  8033. }
  8034. return ring_number;
  8035. }
  8036. /**
  8037. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  8038. * @phba: Pointer to HBA context object.
  8039. * @pring: Pointer to driver SLI ring object.
  8040. * @piocb: Pointer to command iocb.
  8041. * @flag: Flag indicating if this command can be put into txq.
  8042. *
  8043. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  8044. * function. This function gets the hbalock and calls
  8045. * __lpfc_sli_issue_iocb function and will return the error returned
  8046. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  8047. * functions which do not hold hbalock.
  8048. **/
  8049. int
  8050. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  8051. struct lpfc_iocbq *piocb, uint32_t flag)
  8052. {
  8053. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  8054. struct lpfc_sli_ring *pring;
  8055. struct lpfc_queue *fpeq;
  8056. struct lpfc_eqe *eqe;
  8057. unsigned long iflags;
  8058. int rc, idx;
  8059. if (phba->sli_rev == LPFC_SLI_REV4) {
  8060. ring_number = lpfc_sli_calc_ring(phba, ring_number, piocb);
  8061. if (unlikely(ring_number == LPFC_HBA_ERROR))
  8062. return IOCB_ERROR;
  8063. idx = piocb->fcp_wqidx;
  8064. pring = &phba->sli.ring[ring_number];
  8065. spin_lock_irqsave(&pring->ring_lock, iflags);
  8066. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  8067. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  8068. if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) {
  8069. fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
  8070. if (atomic_dec_and_test(&fcp_eq_hdl->
  8071. fcp_eq_in_use)) {
  8072. /* Get associated EQ with this index */
  8073. fpeq = phba->sli4_hba.hba_eq[idx];
  8074. /* Turn off interrupts from this EQ */
  8075. lpfc_sli4_eq_clr_intr(fpeq);
  8076. /*
  8077. * Process all the events on FCP EQ
  8078. */
  8079. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  8080. lpfc_sli4_hba_handle_eqe(phba,
  8081. eqe, idx);
  8082. fpeq->EQ_processed++;
  8083. }
  8084. /* Always clear and re-arm the EQ */
  8085. lpfc_sli4_eq_release(fpeq,
  8086. LPFC_QUEUE_REARM);
  8087. }
  8088. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  8089. }
  8090. } else {
  8091. /* For now, SLI2/3 will still use hbalock */
  8092. spin_lock_irqsave(&phba->hbalock, iflags);
  8093. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  8094. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8095. }
  8096. return rc;
  8097. }
  8098. /**
  8099. * lpfc_extra_ring_setup - Extra ring setup function
  8100. * @phba: Pointer to HBA context object.
  8101. *
  8102. * This function is called while driver attaches with the
  8103. * HBA to setup the extra ring. The extra ring is used
  8104. * only when driver needs to support target mode functionality
  8105. * or IP over FC functionalities.
  8106. *
  8107. * This function is called with no lock held.
  8108. **/
  8109. static int
  8110. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  8111. {
  8112. struct lpfc_sli *psli;
  8113. struct lpfc_sli_ring *pring;
  8114. psli = &phba->sli;
  8115. /* Adjust cmd/rsp ring iocb entries more evenly */
  8116. /* Take some away from the FCP ring */
  8117. pring = &psli->ring[psli->fcp_ring];
  8118. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8119. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8120. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8121. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8122. /* and give them to the extra ring */
  8123. pring = &psli->ring[psli->extra_ring];
  8124. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8125. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8126. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8127. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8128. /* Setup default profile for this ring */
  8129. pring->iotag_max = 4096;
  8130. pring->num_mask = 1;
  8131. pring->prt[0].profile = 0; /* Mask 0 */
  8132. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  8133. pring->prt[0].type = phba->cfg_multi_ring_type;
  8134. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  8135. return 0;
  8136. }
  8137. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  8138. * @phba: Pointer to HBA context object.
  8139. * @iocbq: Pointer to iocb object.
  8140. *
  8141. * The async_event handler calls this routine when it receives
  8142. * an ASYNC_STATUS_CN event from the port. The port generates
  8143. * this event when an Abort Sequence request to an rport fails
  8144. * twice in succession. The abort could be originated by the
  8145. * driver or by the port. The ABTS could have been for an ELS
  8146. * or FCP IO. The port only generates this event when an ABTS
  8147. * fails to complete after one retry.
  8148. */
  8149. static void
  8150. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  8151. struct lpfc_iocbq *iocbq)
  8152. {
  8153. struct lpfc_nodelist *ndlp = NULL;
  8154. uint16_t rpi = 0, vpi = 0;
  8155. struct lpfc_vport *vport = NULL;
  8156. /* The rpi in the ulpContext is vport-sensitive. */
  8157. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  8158. rpi = iocbq->iocb.ulpContext;
  8159. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8160. "3092 Port generated ABTS async event "
  8161. "on vpi %d rpi %d status 0x%x\n",
  8162. vpi, rpi, iocbq->iocb.ulpStatus);
  8163. vport = lpfc_find_vport_by_vpid(phba, vpi);
  8164. if (!vport)
  8165. goto err_exit;
  8166. ndlp = lpfc_findnode_rpi(vport, rpi);
  8167. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  8168. goto err_exit;
  8169. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  8170. lpfc_sli_abts_recover_port(vport, ndlp);
  8171. return;
  8172. err_exit:
  8173. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8174. "3095 Event Context not found, no "
  8175. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  8176. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  8177. vpi, rpi);
  8178. }
  8179. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  8180. * @phba: pointer to HBA context object.
  8181. * @ndlp: nodelist pointer for the impacted rport.
  8182. * @axri: pointer to the wcqe containing the failed exchange.
  8183. *
  8184. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  8185. * port. The port generates this event when an abort exchange request to an
  8186. * rport fails twice in succession with no reply. The abort could be originated
  8187. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  8188. */
  8189. void
  8190. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  8191. struct lpfc_nodelist *ndlp,
  8192. struct sli4_wcqe_xri_aborted *axri)
  8193. {
  8194. struct lpfc_vport *vport;
  8195. uint32_t ext_status = 0;
  8196. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  8197. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8198. "3115 Node Context not found, driver "
  8199. "ignoring abts err event\n");
  8200. return;
  8201. }
  8202. vport = ndlp->vport;
  8203. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  8204. "3116 Port generated FCP XRI ABORT event on "
  8205. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  8206. ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
  8207. bf_get(lpfc_wcqe_xa_xri, axri),
  8208. bf_get(lpfc_wcqe_xa_status, axri),
  8209. axri->parameter);
  8210. /*
  8211. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  8212. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  8213. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  8214. */
  8215. ext_status = axri->parameter & IOERR_PARAM_MASK;
  8216. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  8217. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  8218. lpfc_sli_abts_recover_port(vport, ndlp);
  8219. }
  8220. /**
  8221. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  8222. * @phba: Pointer to HBA context object.
  8223. * @pring: Pointer to driver SLI ring object.
  8224. * @iocbq: Pointer to iocb object.
  8225. *
  8226. * This function is called by the slow ring event handler
  8227. * function when there is an ASYNC event iocb in the ring.
  8228. * This function is called with no lock held.
  8229. * Currently this function handles only temperature related
  8230. * ASYNC events. The function decodes the temperature sensor
  8231. * event message and posts events for the management applications.
  8232. **/
  8233. static void
  8234. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  8235. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  8236. {
  8237. IOCB_t *icmd;
  8238. uint16_t evt_code;
  8239. struct temp_event temp_event_data;
  8240. struct Scsi_Host *shost;
  8241. uint32_t *iocb_w;
  8242. icmd = &iocbq->iocb;
  8243. evt_code = icmd->un.asyncstat.evt_code;
  8244. switch (evt_code) {
  8245. case ASYNC_TEMP_WARN:
  8246. case ASYNC_TEMP_SAFE:
  8247. temp_event_data.data = (uint32_t) icmd->ulpContext;
  8248. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  8249. if (evt_code == ASYNC_TEMP_WARN) {
  8250. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  8251. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  8252. "0347 Adapter is very hot, please take "
  8253. "corrective action. temperature : %d Celsius\n",
  8254. (uint32_t) icmd->ulpContext);
  8255. } else {
  8256. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  8257. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  8258. "0340 Adapter temperature is OK now. "
  8259. "temperature : %d Celsius\n",
  8260. (uint32_t) icmd->ulpContext);
  8261. }
  8262. /* Send temperature change event to applications */
  8263. shost = lpfc_shost_from_vport(phba->pport);
  8264. fc_host_post_vendor_event(shost, fc_get_event_number(),
  8265. sizeof(temp_event_data), (char *) &temp_event_data,
  8266. LPFC_NL_VENDOR_ID);
  8267. break;
  8268. case ASYNC_STATUS_CN:
  8269. lpfc_sli_abts_err_handler(phba, iocbq);
  8270. break;
  8271. default:
  8272. iocb_w = (uint32_t *) icmd;
  8273. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8274. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  8275. " evt_code 0x%x\n"
  8276. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  8277. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  8278. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  8279. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  8280. pring->ringno, icmd->un.asyncstat.evt_code,
  8281. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  8282. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  8283. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  8284. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  8285. break;
  8286. }
  8287. }
  8288. /**
  8289. * lpfc_sli_setup - SLI ring setup function
  8290. * @phba: Pointer to HBA context object.
  8291. *
  8292. * lpfc_sli_setup sets up rings of the SLI interface with
  8293. * number of iocbs per ring and iotags. This function is
  8294. * called while driver attach to the HBA and before the
  8295. * interrupts are enabled. So there is no need for locking.
  8296. *
  8297. * This function always returns 0.
  8298. **/
  8299. int
  8300. lpfc_sli_setup(struct lpfc_hba *phba)
  8301. {
  8302. int i, totiocbsize = 0;
  8303. struct lpfc_sli *psli = &phba->sli;
  8304. struct lpfc_sli_ring *pring;
  8305. psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
  8306. if (phba->sli_rev == LPFC_SLI_REV4)
  8307. psli->num_rings += phba->cfg_fcp_io_channel;
  8308. psli->sli_flag = 0;
  8309. psli->fcp_ring = LPFC_FCP_RING;
  8310. psli->next_ring = LPFC_FCP_NEXT_RING;
  8311. psli->extra_ring = LPFC_EXTRA_RING;
  8312. psli->iocbq_lookup = NULL;
  8313. psli->iocbq_lookup_len = 0;
  8314. psli->last_iotag = 0;
  8315. for (i = 0; i < psli->num_rings; i++) {
  8316. pring = &psli->ring[i];
  8317. switch (i) {
  8318. case LPFC_FCP_RING: /* ring 0 - FCP */
  8319. /* numCiocb and numRiocb are used in config_port */
  8320. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  8321. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  8322. pring->sli.sli3.numCiocb +=
  8323. SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8324. pring->sli.sli3.numRiocb +=
  8325. SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8326. pring->sli.sli3.numCiocb +=
  8327. SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8328. pring->sli.sli3.numRiocb +=
  8329. SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8330. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8331. SLI3_IOCB_CMD_SIZE :
  8332. SLI2_IOCB_CMD_SIZE;
  8333. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8334. SLI3_IOCB_RSP_SIZE :
  8335. SLI2_IOCB_RSP_SIZE;
  8336. pring->iotag_ctr = 0;
  8337. pring->iotag_max =
  8338. (phba->cfg_hba_queue_depth * 2);
  8339. pring->fast_iotag = pring->iotag_max;
  8340. pring->num_mask = 0;
  8341. break;
  8342. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  8343. /* numCiocb and numRiocb are used in config_port */
  8344. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  8345. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  8346. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8347. SLI3_IOCB_CMD_SIZE :
  8348. SLI2_IOCB_CMD_SIZE;
  8349. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8350. SLI3_IOCB_RSP_SIZE :
  8351. SLI2_IOCB_RSP_SIZE;
  8352. pring->iotag_max = phba->cfg_hba_queue_depth;
  8353. pring->num_mask = 0;
  8354. break;
  8355. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  8356. /* numCiocb and numRiocb are used in config_port */
  8357. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  8358. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  8359. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8360. SLI3_IOCB_CMD_SIZE :
  8361. SLI2_IOCB_CMD_SIZE;
  8362. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8363. SLI3_IOCB_RSP_SIZE :
  8364. SLI2_IOCB_RSP_SIZE;
  8365. pring->fast_iotag = 0;
  8366. pring->iotag_ctr = 0;
  8367. pring->iotag_max = 4096;
  8368. pring->lpfc_sli_rcv_async_status =
  8369. lpfc_sli_async_event_handler;
  8370. pring->num_mask = LPFC_MAX_RING_MASK;
  8371. pring->prt[0].profile = 0; /* Mask 0 */
  8372. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  8373. pring->prt[0].type = FC_TYPE_ELS;
  8374. pring->prt[0].lpfc_sli_rcv_unsol_event =
  8375. lpfc_els_unsol_event;
  8376. pring->prt[1].profile = 0; /* Mask 1 */
  8377. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  8378. pring->prt[1].type = FC_TYPE_ELS;
  8379. pring->prt[1].lpfc_sli_rcv_unsol_event =
  8380. lpfc_els_unsol_event;
  8381. pring->prt[2].profile = 0; /* Mask 2 */
  8382. /* NameServer Inquiry */
  8383. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  8384. /* NameServer */
  8385. pring->prt[2].type = FC_TYPE_CT;
  8386. pring->prt[2].lpfc_sli_rcv_unsol_event =
  8387. lpfc_ct_unsol_event;
  8388. pring->prt[3].profile = 0; /* Mask 3 */
  8389. /* NameServer response */
  8390. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8391. /* NameServer */
  8392. pring->prt[3].type = FC_TYPE_CT;
  8393. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8394. lpfc_ct_unsol_event;
  8395. break;
  8396. }
  8397. totiocbsize += (pring->sli.sli3.numCiocb *
  8398. pring->sli.sli3.sizeCiocb) +
  8399. (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
  8400. }
  8401. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8402. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8403. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8404. "SLI2 SLIM Data: x%x x%lx\n",
  8405. phba->brd_no, totiocbsize,
  8406. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8407. }
  8408. if (phba->cfg_multi_ring_support == 2)
  8409. lpfc_extra_ring_setup(phba);
  8410. return 0;
  8411. }
  8412. /**
  8413. * lpfc_sli_queue_setup - Queue initialization function
  8414. * @phba: Pointer to HBA context object.
  8415. *
  8416. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8417. * ring. This function also initializes ring indices of each ring.
  8418. * This function is called during the initialization of the SLI
  8419. * interface of an HBA.
  8420. * This function is called with no lock held and always returns
  8421. * 1.
  8422. **/
  8423. int
  8424. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8425. {
  8426. struct lpfc_sli *psli;
  8427. struct lpfc_sli_ring *pring;
  8428. int i;
  8429. psli = &phba->sli;
  8430. spin_lock_irq(&phba->hbalock);
  8431. INIT_LIST_HEAD(&psli->mboxq);
  8432. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8433. /* Initialize list headers for txq and txcmplq as double linked lists */
  8434. for (i = 0; i < psli->num_rings; i++) {
  8435. pring = &psli->ring[i];
  8436. pring->ringno = i;
  8437. pring->sli.sli3.next_cmdidx = 0;
  8438. pring->sli.sli3.local_getidx = 0;
  8439. pring->sli.sli3.cmdidx = 0;
  8440. pring->flag = 0;
  8441. INIT_LIST_HEAD(&pring->txq);
  8442. INIT_LIST_HEAD(&pring->txcmplq);
  8443. INIT_LIST_HEAD(&pring->iocb_continueq);
  8444. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8445. INIT_LIST_HEAD(&pring->postbufq);
  8446. spin_lock_init(&pring->ring_lock);
  8447. }
  8448. spin_unlock_irq(&phba->hbalock);
  8449. return 1;
  8450. }
  8451. /**
  8452. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8453. * @phba: Pointer to HBA context object.
  8454. *
  8455. * This routine flushes the mailbox command subsystem. It will unconditionally
  8456. * flush all the mailbox commands in the three possible stages in the mailbox
  8457. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8458. * command; and completed mailbox command queue. It is caller's responsibility
  8459. * to make sure that the driver is in the proper state to flush the mailbox
  8460. * command sub-system. Namely, the posting of mailbox commands into the
  8461. * pending mailbox command queue from the various clients must be stopped;
  8462. * either the HBA is in a state that it will never works on the outstanding
  8463. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8464. * mailbox command has been completed.
  8465. **/
  8466. static void
  8467. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8468. {
  8469. LIST_HEAD(completions);
  8470. struct lpfc_sli *psli = &phba->sli;
  8471. LPFC_MBOXQ_t *pmb;
  8472. unsigned long iflag;
  8473. /* Flush all the mailbox commands in the mbox system */
  8474. spin_lock_irqsave(&phba->hbalock, iflag);
  8475. /* The pending mailbox command queue */
  8476. list_splice_init(&phba->sli.mboxq, &completions);
  8477. /* The outstanding active mailbox command */
  8478. if (psli->mbox_active) {
  8479. list_add_tail(&psli->mbox_active->list, &completions);
  8480. psli->mbox_active = NULL;
  8481. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8482. }
  8483. /* The completed mailbox command queue */
  8484. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8485. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8486. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8487. while (!list_empty(&completions)) {
  8488. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8489. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8490. if (pmb->mbox_cmpl)
  8491. pmb->mbox_cmpl(phba, pmb);
  8492. }
  8493. }
  8494. /**
  8495. * lpfc_sli_host_down - Vport cleanup function
  8496. * @vport: Pointer to virtual port object.
  8497. *
  8498. * lpfc_sli_host_down is called to clean up the resources
  8499. * associated with a vport before destroying virtual
  8500. * port data structures.
  8501. * This function does following operations:
  8502. * - Free discovery resources associated with this virtual
  8503. * port.
  8504. * - Free iocbs associated with this virtual port in
  8505. * the txq.
  8506. * - Send abort for all iocb commands associated with this
  8507. * vport in txcmplq.
  8508. *
  8509. * This function is called with no lock held and always returns 1.
  8510. **/
  8511. int
  8512. lpfc_sli_host_down(struct lpfc_vport *vport)
  8513. {
  8514. LIST_HEAD(completions);
  8515. struct lpfc_hba *phba = vport->phba;
  8516. struct lpfc_sli *psli = &phba->sli;
  8517. struct lpfc_sli_ring *pring;
  8518. struct lpfc_iocbq *iocb, *next_iocb;
  8519. int i;
  8520. unsigned long flags = 0;
  8521. uint16_t prev_pring_flag;
  8522. lpfc_cleanup_discovery_resources(vport);
  8523. spin_lock_irqsave(&phba->hbalock, flags);
  8524. for (i = 0; i < psli->num_rings; i++) {
  8525. pring = &psli->ring[i];
  8526. prev_pring_flag = pring->flag;
  8527. /* Only slow rings */
  8528. if (pring->ringno == LPFC_ELS_RING) {
  8529. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8530. /* Set the lpfc data pending flag */
  8531. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8532. }
  8533. /*
  8534. * Error everything on the txq since these iocbs have not been
  8535. * given to the FW yet.
  8536. */
  8537. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8538. if (iocb->vport != vport)
  8539. continue;
  8540. list_move_tail(&iocb->list, &completions);
  8541. }
  8542. /* Next issue ABTS for everything on the txcmplq */
  8543. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8544. list) {
  8545. if (iocb->vport != vport)
  8546. continue;
  8547. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8548. }
  8549. pring->flag = prev_pring_flag;
  8550. }
  8551. spin_unlock_irqrestore(&phba->hbalock, flags);
  8552. /* Cancel all the IOCBs from the completions list */
  8553. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8554. IOERR_SLI_DOWN);
  8555. return 1;
  8556. }
  8557. /**
  8558. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8559. * @phba: Pointer to HBA context object.
  8560. *
  8561. * This function cleans up all iocb, buffers, mailbox commands
  8562. * while shutting down the HBA. This function is called with no
  8563. * lock held and always returns 1.
  8564. * This function does the following to cleanup driver resources:
  8565. * - Free discovery resources for each virtual port
  8566. * - Cleanup any pending fabric iocbs
  8567. * - Iterate through the iocb txq and free each entry
  8568. * in the list.
  8569. * - Free up any buffer posted to the HBA
  8570. * - Free mailbox commands in the mailbox queue.
  8571. **/
  8572. int
  8573. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8574. {
  8575. LIST_HEAD(completions);
  8576. struct lpfc_sli *psli = &phba->sli;
  8577. struct lpfc_sli_ring *pring;
  8578. struct lpfc_dmabuf *buf_ptr;
  8579. unsigned long flags = 0;
  8580. int i;
  8581. /* Shutdown the mailbox command sub-system */
  8582. lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
  8583. lpfc_hba_down_prep(phba);
  8584. lpfc_fabric_abort_hba(phba);
  8585. spin_lock_irqsave(&phba->hbalock, flags);
  8586. for (i = 0; i < psli->num_rings; i++) {
  8587. pring = &psli->ring[i];
  8588. /* Only slow rings */
  8589. if (pring->ringno == LPFC_ELS_RING) {
  8590. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8591. /* Set the lpfc data pending flag */
  8592. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8593. }
  8594. /*
  8595. * Error everything on the txq since these iocbs have not been
  8596. * given to the FW yet.
  8597. */
  8598. list_splice_init(&pring->txq, &completions);
  8599. }
  8600. spin_unlock_irqrestore(&phba->hbalock, flags);
  8601. /* Cancel all the IOCBs from the completions list */
  8602. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8603. IOERR_SLI_DOWN);
  8604. spin_lock_irqsave(&phba->hbalock, flags);
  8605. list_splice_init(&phba->elsbuf, &completions);
  8606. phba->elsbuf_cnt = 0;
  8607. phba->elsbuf_prev_cnt = 0;
  8608. spin_unlock_irqrestore(&phba->hbalock, flags);
  8609. while (!list_empty(&completions)) {
  8610. list_remove_head(&completions, buf_ptr,
  8611. struct lpfc_dmabuf, list);
  8612. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8613. kfree(buf_ptr);
  8614. }
  8615. /* Return any active mbox cmds */
  8616. del_timer_sync(&psli->mbox_tmo);
  8617. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8618. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8619. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8620. return 1;
  8621. }
  8622. /**
  8623. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8624. * @srcp: Source memory pointer.
  8625. * @destp: Destination memory pointer.
  8626. * @cnt: Number of words required to be copied.
  8627. *
  8628. * This function is used for copying data between driver memory
  8629. * and the SLI memory. This function also changes the endianness
  8630. * of each word if native endianness is different from SLI
  8631. * endianness. This function can be called with or without
  8632. * lock.
  8633. **/
  8634. void
  8635. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8636. {
  8637. uint32_t *src = srcp;
  8638. uint32_t *dest = destp;
  8639. uint32_t ldata;
  8640. int i;
  8641. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8642. ldata = *src;
  8643. ldata = le32_to_cpu(ldata);
  8644. *dest = ldata;
  8645. src++;
  8646. dest++;
  8647. }
  8648. }
  8649. /**
  8650. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8651. * @srcp: Source memory pointer.
  8652. * @destp: Destination memory pointer.
  8653. * @cnt: Number of words required to be copied.
  8654. *
  8655. * This function is used for copying data between a data structure
  8656. * with big endian representation to local endianness.
  8657. * This function can be called with or without lock.
  8658. **/
  8659. void
  8660. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8661. {
  8662. uint32_t *src = srcp;
  8663. uint32_t *dest = destp;
  8664. uint32_t ldata;
  8665. int i;
  8666. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8667. ldata = *src;
  8668. ldata = be32_to_cpu(ldata);
  8669. *dest = ldata;
  8670. src++;
  8671. dest++;
  8672. }
  8673. }
  8674. /**
  8675. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8676. * @phba: Pointer to HBA context object.
  8677. * @pring: Pointer to driver SLI ring object.
  8678. * @mp: Pointer to driver buffer object.
  8679. *
  8680. * This function is called with no lock held.
  8681. * It always return zero after adding the buffer to the postbufq
  8682. * buffer list.
  8683. **/
  8684. int
  8685. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8686. struct lpfc_dmabuf *mp)
  8687. {
  8688. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8689. later */
  8690. spin_lock_irq(&phba->hbalock);
  8691. list_add_tail(&mp->list, &pring->postbufq);
  8692. pring->postbufq_cnt++;
  8693. spin_unlock_irq(&phba->hbalock);
  8694. return 0;
  8695. }
  8696. /**
  8697. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8698. * @phba: Pointer to HBA context object.
  8699. *
  8700. * When HBQ is enabled, buffers are searched based on tags. This function
  8701. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8702. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8703. * does not conflict with tags of buffer posted for unsolicited events.
  8704. * The function returns the allocated tag. The function is called with
  8705. * no locks held.
  8706. **/
  8707. uint32_t
  8708. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8709. {
  8710. spin_lock_irq(&phba->hbalock);
  8711. phba->buffer_tag_count++;
  8712. /*
  8713. * Always set the QUE_BUFTAG_BIT to distiguish between
  8714. * a tag assigned by HBQ.
  8715. */
  8716. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8717. spin_unlock_irq(&phba->hbalock);
  8718. return phba->buffer_tag_count;
  8719. }
  8720. /**
  8721. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8722. * @phba: Pointer to HBA context object.
  8723. * @pring: Pointer to driver SLI ring object.
  8724. * @tag: Buffer tag.
  8725. *
  8726. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8727. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8728. * iocb is posted to the response ring with the tag of the buffer.
  8729. * This function searches the pring->postbufq list using the tag
  8730. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8731. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8732. * buffer is returned to the caller else NULL is returned.
  8733. * This function is called with no lock held.
  8734. **/
  8735. struct lpfc_dmabuf *
  8736. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8737. uint32_t tag)
  8738. {
  8739. struct lpfc_dmabuf *mp, *next_mp;
  8740. struct list_head *slp = &pring->postbufq;
  8741. /* Search postbufq, from the beginning, looking for a match on tag */
  8742. spin_lock_irq(&phba->hbalock);
  8743. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8744. if (mp->buffer_tag == tag) {
  8745. list_del_init(&mp->list);
  8746. pring->postbufq_cnt--;
  8747. spin_unlock_irq(&phba->hbalock);
  8748. return mp;
  8749. }
  8750. }
  8751. spin_unlock_irq(&phba->hbalock);
  8752. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8753. "0402 Cannot find virtual addr for buffer tag on "
  8754. "ring %d Data x%lx x%p x%p x%x\n",
  8755. pring->ringno, (unsigned long) tag,
  8756. slp->next, slp->prev, pring->postbufq_cnt);
  8757. return NULL;
  8758. }
  8759. /**
  8760. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8761. * @phba: Pointer to HBA context object.
  8762. * @pring: Pointer to driver SLI ring object.
  8763. * @phys: DMA address of the buffer.
  8764. *
  8765. * This function searches the buffer list using the dma_address
  8766. * of unsolicited event to find the driver's lpfc_dmabuf object
  8767. * corresponding to the dma_address. The function returns the
  8768. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8769. * This function is called by the ct and els unsolicited event
  8770. * handlers to get the buffer associated with the unsolicited
  8771. * event.
  8772. *
  8773. * This function is called with no lock held.
  8774. **/
  8775. struct lpfc_dmabuf *
  8776. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8777. dma_addr_t phys)
  8778. {
  8779. struct lpfc_dmabuf *mp, *next_mp;
  8780. struct list_head *slp = &pring->postbufq;
  8781. /* Search postbufq, from the beginning, looking for a match on phys */
  8782. spin_lock_irq(&phba->hbalock);
  8783. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8784. if (mp->phys == phys) {
  8785. list_del_init(&mp->list);
  8786. pring->postbufq_cnt--;
  8787. spin_unlock_irq(&phba->hbalock);
  8788. return mp;
  8789. }
  8790. }
  8791. spin_unlock_irq(&phba->hbalock);
  8792. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8793. "0410 Cannot find virtual addr for mapped buf on "
  8794. "ring %d Data x%llx x%p x%p x%x\n",
  8795. pring->ringno, (unsigned long long)phys,
  8796. slp->next, slp->prev, pring->postbufq_cnt);
  8797. return NULL;
  8798. }
  8799. /**
  8800. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8801. * @phba: Pointer to HBA context object.
  8802. * @cmdiocb: Pointer to driver command iocb object.
  8803. * @rspiocb: Pointer to driver response iocb object.
  8804. *
  8805. * This function is the completion handler for the abort iocbs for
  8806. * ELS commands. This function is called from the ELS ring event
  8807. * handler with no lock held. This function frees memory resources
  8808. * associated with the abort iocb.
  8809. **/
  8810. static void
  8811. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8812. struct lpfc_iocbq *rspiocb)
  8813. {
  8814. IOCB_t *irsp = &rspiocb->iocb;
  8815. uint16_t abort_iotag, abort_context;
  8816. struct lpfc_iocbq *abort_iocb = NULL;
  8817. if (irsp->ulpStatus) {
  8818. /*
  8819. * Assume that the port already completed and returned, or
  8820. * will return the iocb. Just Log the message.
  8821. */
  8822. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8823. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8824. spin_lock_irq(&phba->hbalock);
  8825. if (phba->sli_rev < LPFC_SLI_REV4) {
  8826. if (abort_iotag != 0 &&
  8827. abort_iotag <= phba->sli.last_iotag)
  8828. abort_iocb =
  8829. phba->sli.iocbq_lookup[abort_iotag];
  8830. } else
  8831. /* For sli4 the abort_tag is the XRI,
  8832. * so the abort routine puts the iotag of the iocb
  8833. * being aborted in the context field of the abort
  8834. * IOCB.
  8835. */
  8836. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8837. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8838. "0327 Cannot abort els iocb %p "
  8839. "with tag %x context %x, abort status %x, "
  8840. "abort code %x\n",
  8841. abort_iocb, abort_iotag, abort_context,
  8842. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8843. spin_unlock_irq(&phba->hbalock);
  8844. }
  8845. lpfc_sli_release_iocbq(phba, cmdiocb);
  8846. return;
  8847. }
  8848. /**
  8849. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8850. * @phba: Pointer to HBA context object.
  8851. * @cmdiocb: Pointer to driver command iocb object.
  8852. * @rspiocb: Pointer to driver response iocb object.
  8853. *
  8854. * The function is called from SLI ring event handler with no
  8855. * lock held. This function is the completion handler for ELS commands
  8856. * which are aborted. The function frees memory resources used for
  8857. * the aborted ELS commands.
  8858. **/
  8859. static void
  8860. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8861. struct lpfc_iocbq *rspiocb)
  8862. {
  8863. IOCB_t *irsp = &rspiocb->iocb;
  8864. /* ELS cmd tag <ulpIoTag> completes */
  8865. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8866. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8867. "x%x x%x x%x\n",
  8868. irsp->ulpIoTag, irsp->ulpStatus,
  8869. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8870. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8871. lpfc_ct_free_iocb(phba, cmdiocb);
  8872. else
  8873. lpfc_els_free_iocb(phba, cmdiocb);
  8874. return;
  8875. }
  8876. /**
  8877. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8878. * @phba: Pointer to HBA context object.
  8879. * @pring: Pointer to driver SLI ring object.
  8880. * @cmdiocb: Pointer to driver command iocb object.
  8881. *
  8882. * This function issues an abort iocb for the provided command iocb down to
  8883. * the port. Other than the case the outstanding command iocb is an abort
  8884. * request, this function issues abort out unconditionally. This function is
  8885. * called with hbalock held. The function returns 0 when it fails due to
  8886. * memory allocation failure or when the command iocb is an abort request.
  8887. **/
  8888. static int
  8889. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8890. struct lpfc_iocbq *cmdiocb)
  8891. {
  8892. struct lpfc_vport *vport = cmdiocb->vport;
  8893. struct lpfc_iocbq *abtsiocbp;
  8894. IOCB_t *icmd = NULL;
  8895. IOCB_t *iabt = NULL;
  8896. int ring_number;
  8897. int retval;
  8898. unsigned long iflags;
  8899. /*
  8900. * There are certain command types we don't want to abort. And we
  8901. * don't want to abort commands that are already in the process of
  8902. * being aborted.
  8903. */
  8904. icmd = &cmdiocb->iocb;
  8905. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8906. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8907. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8908. return 0;
  8909. /* issue ABTS for this IOCB based on iotag */
  8910. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8911. if (abtsiocbp == NULL)
  8912. return 0;
  8913. /* This signals the response to set the correct status
  8914. * before calling the completion handler
  8915. */
  8916. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8917. iabt = &abtsiocbp->iocb;
  8918. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8919. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8920. if (phba->sli_rev == LPFC_SLI_REV4) {
  8921. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8922. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8923. }
  8924. else
  8925. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8926. iabt->ulpLe = 1;
  8927. iabt->ulpClass = icmd->ulpClass;
  8928. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8929. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8930. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8931. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8932. if (cmdiocb->iocb_flag & LPFC_IO_FOF)
  8933. abtsiocbp->iocb_flag |= LPFC_IO_FOF;
  8934. if (phba->link_state >= LPFC_LINK_UP)
  8935. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8936. else
  8937. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8938. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8939. abtsiocbp->vport = vport;
  8940. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8941. "0339 Abort xri x%x, original iotag x%x, "
  8942. "abort cmd iotag x%x\n",
  8943. iabt->un.acxri.abortIoTag,
  8944. iabt->un.acxri.abortContextTag,
  8945. abtsiocbp->iotag);
  8946. if (phba->sli_rev == LPFC_SLI_REV4) {
  8947. ring_number =
  8948. lpfc_sli_calc_ring(phba, pring->ringno, abtsiocbp);
  8949. if (unlikely(ring_number == LPFC_HBA_ERROR))
  8950. return 0;
  8951. pring = &phba->sli.ring[ring_number];
  8952. /* Note: both hbalock and ring_lock need to be set here */
  8953. spin_lock_irqsave(&pring->ring_lock, iflags);
  8954. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8955. abtsiocbp, 0);
  8956. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  8957. } else {
  8958. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8959. abtsiocbp, 0);
  8960. }
  8961. if (retval)
  8962. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8963. /*
  8964. * Caller to this routine should check for IOCB_ERROR
  8965. * and handle it properly. This routine no longer removes
  8966. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8967. */
  8968. return retval;
  8969. }
  8970. /**
  8971. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8972. * @phba: Pointer to HBA context object.
  8973. * @pring: Pointer to driver SLI ring object.
  8974. * @cmdiocb: Pointer to driver command iocb object.
  8975. *
  8976. * This function issues an abort iocb for the provided command iocb. In case
  8977. * of unloading, the abort iocb will not be issued to commands on the ELS
  8978. * ring. Instead, the callback function shall be changed to those commands
  8979. * so that nothing happens when them finishes. This function is called with
  8980. * hbalock held. The function returns 0 when the command iocb is an abort
  8981. * request.
  8982. **/
  8983. int
  8984. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8985. struct lpfc_iocbq *cmdiocb)
  8986. {
  8987. struct lpfc_vport *vport = cmdiocb->vport;
  8988. int retval = IOCB_ERROR;
  8989. IOCB_t *icmd = NULL;
  8990. /*
  8991. * There are certain command types we don't want to abort. And we
  8992. * don't want to abort commands that are already in the process of
  8993. * being aborted.
  8994. */
  8995. icmd = &cmdiocb->iocb;
  8996. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8997. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8998. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8999. return 0;
  9000. /*
  9001. * If we're unloading, don't abort iocb on the ELS ring, but change
  9002. * the callback so that nothing happens when it finishes.
  9003. */
  9004. if ((vport->load_flag & FC_UNLOADING) &&
  9005. (pring->ringno == LPFC_ELS_RING)) {
  9006. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  9007. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  9008. else
  9009. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  9010. goto abort_iotag_exit;
  9011. }
  9012. /* Now, we try to issue the abort to the cmdiocb out */
  9013. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  9014. abort_iotag_exit:
  9015. /*
  9016. * Caller to this routine should check for IOCB_ERROR
  9017. * and handle it properly. This routine no longer removes
  9018. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  9019. */
  9020. return retval;
  9021. }
  9022. /**
  9023. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  9024. * @phba: pointer to lpfc HBA data structure.
  9025. *
  9026. * This routine will abort all pending and outstanding iocbs to an HBA.
  9027. **/
  9028. void
  9029. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  9030. {
  9031. struct lpfc_sli *psli = &phba->sli;
  9032. struct lpfc_sli_ring *pring;
  9033. int i;
  9034. for (i = 0; i < psli->num_rings; i++) {
  9035. pring = &psli->ring[i];
  9036. lpfc_sli_abort_iocb_ring(phba, pring);
  9037. }
  9038. }
  9039. /**
  9040. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  9041. * @iocbq: Pointer to driver iocb object.
  9042. * @vport: Pointer to driver virtual port object.
  9043. * @tgt_id: SCSI ID of the target.
  9044. * @lun_id: LUN ID of the scsi device.
  9045. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  9046. *
  9047. * This function acts as an iocb filter for functions which abort or count
  9048. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  9049. * 0 if the filtering criteria is met for the given iocb and will return
  9050. * 1 if the filtering criteria is not met.
  9051. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  9052. * given iocb is for the SCSI device specified by vport, tgt_id and
  9053. * lun_id parameter.
  9054. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  9055. * given iocb is for the SCSI target specified by vport and tgt_id
  9056. * parameters.
  9057. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  9058. * given iocb is for the SCSI host associated with the given vport.
  9059. * This function is called with no locks held.
  9060. **/
  9061. static int
  9062. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  9063. uint16_t tgt_id, uint64_t lun_id,
  9064. lpfc_ctx_cmd ctx_cmd)
  9065. {
  9066. struct lpfc_scsi_buf *lpfc_cmd;
  9067. int rc = 1;
  9068. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  9069. return rc;
  9070. if (iocbq->vport != vport)
  9071. return rc;
  9072. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  9073. if (lpfc_cmd->pCmd == NULL)
  9074. return rc;
  9075. switch (ctx_cmd) {
  9076. case LPFC_CTX_LUN:
  9077. if ((lpfc_cmd->rdata->pnode) &&
  9078. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  9079. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  9080. rc = 0;
  9081. break;
  9082. case LPFC_CTX_TGT:
  9083. if ((lpfc_cmd->rdata->pnode) &&
  9084. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  9085. rc = 0;
  9086. break;
  9087. case LPFC_CTX_HOST:
  9088. rc = 0;
  9089. break;
  9090. default:
  9091. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  9092. __func__, ctx_cmd);
  9093. break;
  9094. }
  9095. return rc;
  9096. }
  9097. /**
  9098. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  9099. * @vport: Pointer to virtual port.
  9100. * @tgt_id: SCSI ID of the target.
  9101. * @lun_id: LUN ID of the scsi device.
  9102. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9103. *
  9104. * This function returns number of FCP commands pending for the vport.
  9105. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  9106. * commands pending on the vport associated with SCSI device specified
  9107. * by tgt_id and lun_id parameters.
  9108. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  9109. * commands pending on the vport associated with SCSI target specified
  9110. * by tgt_id parameter.
  9111. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  9112. * commands pending on the vport.
  9113. * This function returns the number of iocbs which satisfy the filter.
  9114. * This function is called without any lock held.
  9115. **/
  9116. int
  9117. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  9118. lpfc_ctx_cmd ctx_cmd)
  9119. {
  9120. struct lpfc_hba *phba = vport->phba;
  9121. struct lpfc_iocbq *iocbq;
  9122. int sum, i;
  9123. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  9124. iocbq = phba->sli.iocbq_lookup[i];
  9125. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  9126. ctx_cmd) == 0)
  9127. sum++;
  9128. }
  9129. return sum;
  9130. }
  9131. /**
  9132. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  9133. * @phba: Pointer to HBA context object
  9134. * @cmdiocb: Pointer to command iocb object.
  9135. * @rspiocb: Pointer to response iocb object.
  9136. *
  9137. * This function is called when an aborted FCP iocb completes. This
  9138. * function is called by the ring event handler with no lock held.
  9139. * This function frees the iocb.
  9140. **/
  9141. void
  9142. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  9143. struct lpfc_iocbq *rspiocb)
  9144. {
  9145. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9146. "3096 ABORT_XRI_CN completing on rpi x%x "
  9147. "original iotag x%x, abort cmd iotag x%x "
  9148. "status 0x%x, reason 0x%x\n",
  9149. cmdiocb->iocb.un.acxri.abortContextTag,
  9150. cmdiocb->iocb.un.acxri.abortIoTag,
  9151. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  9152. rspiocb->iocb.un.ulpWord[4]);
  9153. lpfc_sli_release_iocbq(phba, cmdiocb);
  9154. return;
  9155. }
  9156. /**
  9157. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  9158. * @vport: Pointer to virtual port.
  9159. * @pring: Pointer to driver SLI ring object.
  9160. * @tgt_id: SCSI ID of the target.
  9161. * @lun_id: LUN ID of the scsi device.
  9162. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9163. *
  9164. * This function sends an abort command for every SCSI command
  9165. * associated with the given virtual port pending on the ring
  9166. * filtered by lpfc_sli_validate_fcp_iocb function.
  9167. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  9168. * FCP iocbs associated with lun specified by tgt_id and lun_id
  9169. * parameters
  9170. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  9171. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  9172. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  9173. * FCP iocbs associated with virtual port.
  9174. * This function returns number of iocbs it failed to abort.
  9175. * This function is called with no locks held.
  9176. **/
  9177. int
  9178. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  9179. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  9180. {
  9181. struct lpfc_hba *phba = vport->phba;
  9182. struct lpfc_iocbq *iocbq;
  9183. struct lpfc_iocbq *abtsiocb;
  9184. IOCB_t *cmd = NULL;
  9185. int errcnt = 0, ret_val = 0;
  9186. int i;
  9187. for (i = 1; i <= phba->sli.last_iotag; i++) {
  9188. iocbq = phba->sli.iocbq_lookup[i];
  9189. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  9190. abort_cmd) != 0)
  9191. continue;
  9192. /*
  9193. * If the iocbq is already being aborted, don't take a second
  9194. * action, but do count it.
  9195. */
  9196. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  9197. continue;
  9198. /* issue ABTS for this IOCB based on iotag */
  9199. abtsiocb = lpfc_sli_get_iocbq(phba);
  9200. if (abtsiocb == NULL) {
  9201. errcnt++;
  9202. continue;
  9203. }
  9204. /* indicate the IO is being aborted by the driver. */
  9205. iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
  9206. cmd = &iocbq->iocb;
  9207. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  9208. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  9209. if (phba->sli_rev == LPFC_SLI_REV4)
  9210. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  9211. else
  9212. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  9213. abtsiocb->iocb.ulpLe = 1;
  9214. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  9215. abtsiocb->vport = vport;
  9216. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  9217. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  9218. if (iocbq->iocb_flag & LPFC_IO_FCP)
  9219. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  9220. if (iocbq->iocb_flag & LPFC_IO_FOF)
  9221. abtsiocb->iocb_flag |= LPFC_IO_FOF;
  9222. if (lpfc_is_link_up(phba))
  9223. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  9224. else
  9225. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  9226. /* Setup callback routine and issue the command. */
  9227. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  9228. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  9229. abtsiocb, 0);
  9230. if (ret_val == IOCB_ERROR) {
  9231. lpfc_sli_release_iocbq(phba, abtsiocb);
  9232. errcnt++;
  9233. continue;
  9234. }
  9235. }
  9236. return errcnt;
  9237. }
  9238. /**
  9239. * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
  9240. * @vport: Pointer to virtual port.
  9241. * @pring: Pointer to driver SLI ring object.
  9242. * @tgt_id: SCSI ID of the target.
  9243. * @lun_id: LUN ID of the scsi device.
  9244. * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  9245. *
  9246. * This function sends an abort command for every SCSI command
  9247. * associated with the given virtual port pending on the ring
  9248. * filtered by lpfc_sli_validate_fcp_iocb function.
  9249. * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
  9250. * FCP iocbs associated with lun specified by tgt_id and lun_id
  9251. * parameters
  9252. * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
  9253. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  9254. * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
  9255. * FCP iocbs associated with virtual port.
  9256. * This function returns number of iocbs it aborted .
  9257. * This function is called with no locks held right after a taskmgmt
  9258. * command is sent.
  9259. **/
  9260. int
  9261. lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  9262. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
  9263. {
  9264. struct lpfc_hba *phba = vport->phba;
  9265. struct lpfc_scsi_buf *lpfc_cmd;
  9266. struct lpfc_iocbq *abtsiocbq;
  9267. struct lpfc_nodelist *ndlp;
  9268. struct lpfc_iocbq *iocbq;
  9269. IOCB_t *icmd;
  9270. int sum, i, ret_val;
  9271. unsigned long iflags;
  9272. struct lpfc_sli_ring *pring_s4;
  9273. uint32_t ring_number;
  9274. spin_lock_irq(&phba->hbalock);
  9275. /* all I/Os are in process of being flushed */
  9276. if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
  9277. spin_unlock_irq(&phba->hbalock);
  9278. return 0;
  9279. }
  9280. sum = 0;
  9281. for (i = 1; i <= phba->sli.last_iotag; i++) {
  9282. iocbq = phba->sli.iocbq_lookup[i];
  9283. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  9284. cmd) != 0)
  9285. continue;
  9286. /*
  9287. * If the iocbq is already being aborted, don't take a second
  9288. * action, but do count it.
  9289. */
  9290. if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  9291. continue;
  9292. /* issue ABTS for this IOCB based on iotag */
  9293. abtsiocbq = __lpfc_sli_get_iocbq(phba);
  9294. if (abtsiocbq == NULL)
  9295. continue;
  9296. icmd = &iocbq->iocb;
  9297. abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  9298. abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
  9299. if (phba->sli_rev == LPFC_SLI_REV4)
  9300. abtsiocbq->iocb.un.acxri.abortIoTag =
  9301. iocbq->sli4_xritag;
  9302. else
  9303. abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
  9304. abtsiocbq->iocb.ulpLe = 1;
  9305. abtsiocbq->iocb.ulpClass = icmd->ulpClass;
  9306. abtsiocbq->vport = vport;
  9307. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  9308. abtsiocbq->fcp_wqidx = iocbq->fcp_wqidx;
  9309. if (iocbq->iocb_flag & LPFC_IO_FCP)
  9310. abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
  9311. if (iocbq->iocb_flag & LPFC_IO_FOF)
  9312. abtsiocbq->iocb_flag |= LPFC_IO_FOF;
  9313. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  9314. ndlp = lpfc_cmd->rdata->pnode;
  9315. if (lpfc_is_link_up(phba) &&
  9316. (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
  9317. abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  9318. else
  9319. abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  9320. /* Setup callback routine and issue the command. */
  9321. abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  9322. /*
  9323. * Indicate the IO is being aborted by the driver and set
  9324. * the caller's flag into the aborted IO.
  9325. */
  9326. iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
  9327. if (phba->sli_rev == LPFC_SLI_REV4) {
  9328. ring_number = MAX_SLI3_CONFIGURED_RINGS +
  9329. iocbq->fcp_wqidx;
  9330. pring_s4 = &phba->sli.ring[ring_number];
  9331. /* Note: both hbalock and ring_lock must be set here */
  9332. spin_lock_irqsave(&pring_s4->ring_lock, iflags);
  9333. ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
  9334. abtsiocbq, 0);
  9335. spin_unlock_irqrestore(&pring_s4->ring_lock, iflags);
  9336. } else {
  9337. ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
  9338. abtsiocbq, 0);
  9339. }
  9340. if (ret_val == IOCB_ERROR)
  9341. __lpfc_sli_release_iocbq(phba, abtsiocbq);
  9342. else
  9343. sum++;
  9344. }
  9345. spin_unlock_irq(&phba->hbalock);
  9346. return sum;
  9347. }
  9348. /**
  9349. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  9350. * @phba: Pointer to HBA context object.
  9351. * @cmdiocbq: Pointer to command iocb.
  9352. * @rspiocbq: Pointer to response iocb.
  9353. *
  9354. * This function is the completion handler for iocbs issued using
  9355. * lpfc_sli_issue_iocb_wait function. This function is called by the
  9356. * ring event handler function without any lock held. This function
  9357. * can be called from both worker thread context and interrupt
  9358. * context. This function also can be called from other thread which
  9359. * cleans up the SLI layer objects.
  9360. * This function copy the contents of the response iocb to the
  9361. * response iocb memory object provided by the caller of
  9362. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  9363. * sleeps for the iocb completion.
  9364. **/
  9365. static void
  9366. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  9367. struct lpfc_iocbq *cmdiocbq,
  9368. struct lpfc_iocbq *rspiocbq)
  9369. {
  9370. wait_queue_head_t *pdone_q;
  9371. unsigned long iflags;
  9372. struct lpfc_scsi_buf *lpfc_cmd;
  9373. spin_lock_irqsave(&phba->hbalock, iflags);
  9374. if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
  9375. /*
  9376. * A time out has occurred for the iocb. If a time out
  9377. * completion handler has been supplied, call it. Otherwise,
  9378. * just free the iocbq.
  9379. */
  9380. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9381. cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
  9382. cmdiocbq->wait_iocb_cmpl = NULL;
  9383. if (cmdiocbq->iocb_cmpl)
  9384. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
  9385. else
  9386. lpfc_sli_release_iocbq(phba, cmdiocbq);
  9387. return;
  9388. }
  9389. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  9390. if (cmdiocbq->context2 && rspiocbq)
  9391. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  9392. &rspiocbq->iocb, sizeof(IOCB_t));
  9393. /* Set the exchange busy flag for task management commands */
  9394. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  9395. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  9396. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  9397. cur_iocbq);
  9398. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  9399. }
  9400. pdone_q = cmdiocbq->context_un.wait_queue;
  9401. if (pdone_q)
  9402. wake_up(pdone_q);
  9403. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9404. return;
  9405. }
  9406. /**
  9407. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  9408. * @phba: Pointer to HBA context object..
  9409. * @piocbq: Pointer to command iocb.
  9410. * @flag: Flag to test.
  9411. *
  9412. * This routine grabs the hbalock and then test the iocb_flag to
  9413. * see if the passed in flag is set.
  9414. * Returns:
  9415. * 1 if flag is set.
  9416. * 0 if flag is not set.
  9417. **/
  9418. static int
  9419. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  9420. struct lpfc_iocbq *piocbq, uint32_t flag)
  9421. {
  9422. unsigned long iflags;
  9423. int ret;
  9424. spin_lock_irqsave(&phba->hbalock, iflags);
  9425. ret = piocbq->iocb_flag & flag;
  9426. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9427. return ret;
  9428. }
  9429. /**
  9430. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  9431. * @phba: Pointer to HBA context object..
  9432. * @pring: Pointer to sli ring.
  9433. * @piocb: Pointer to command iocb.
  9434. * @prspiocbq: Pointer to response iocb.
  9435. * @timeout: Timeout in number of seconds.
  9436. *
  9437. * This function issues the iocb to firmware and waits for the
  9438. * iocb to complete. The iocb_cmpl field of the shall be used
  9439. * to handle iocbs which time out. If the field is NULL, the
  9440. * function shall free the iocbq structure. If more clean up is
  9441. * needed, the caller is expected to provide a completion function
  9442. * that will provide the needed clean up. If the iocb command is
  9443. * not completed within timeout seconds, the function will either
  9444. * free the iocbq structure (if iocb_cmpl == NULL) or execute the
  9445. * completion function set in the iocb_cmpl field and then return
  9446. * a status of IOCB_TIMEDOUT. The caller should not free the iocb
  9447. * resources if this function returns IOCB_TIMEDOUT.
  9448. * The function waits for the iocb completion using an
  9449. * non-interruptible wait.
  9450. * This function will sleep while waiting for iocb completion.
  9451. * So, this function should not be called from any context which
  9452. * does not allow sleeping. Due to the same reason, this function
  9453. * cannot be called with interrupt disabled.
  9454. * This function assumes that the iocb completions occur while
  9455. * this function sleep. So, this function cannot be called from
  9456. * the thread which process iocb completion for this ring.
  9457. * This function clears the iocb_flag of the iocb object before
  9458. * issuing the iocb and the iocb completion handler sets this
  9459. * flag and wakes this thread when the iocb completes.
  9460. * The contents of the response iocb will be copied to prspiocbq
  9461. * by the completion handler when the command completes.
  9462. * This function returns IOCB_SUCCESS when success.
  9463. * This function is called with no lock held.
  9464. **/
  9465. int
  9466. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  9467. uint32_t ring_number,
  9468. struct lpfc_iocbq *piocb,
  9469. struct lpfc_iocbq *prspiocbq,
  9470. uint32_t timeout)
  9471. {
  9472. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9473. long timeleft, timeout_req = 0;
  9474. int retval = IOCB_SUCCESS;
  9475. uint32_t creg_val;
  9476. struct lpfc_iocbq *iocb;
  9477. int txq_cnt = 0;
  9478. int txcmplq_cnt = 0;
  9479. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9480. unsigned long iflags;
  9481. bool iocb_completed = true;
  9482. /*
  9483. * If the caller has provided a response iocbq buffer, then context2
  9484. * is NULL or its an error.
  9485. */
  9486. if (prspiocbq) {
  9487. if (piocb->context2)
  9488. return IOCB_ERROR;
  9489. piocb->context2 = prspiocbq;
  9490. }
  9491. piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
  9492. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  9493. piocb->context_un.wait_queue = &done_q;
  9494. piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
  9495. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9496. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9497. return IOCB_ERROR;
  9498. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  9499. writel(creg_val, phba->HCregaddr);
  9500. readl(phba->HCregaddr); /* flush */
  9501. }
  9502. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  9503. SLI_IOCB_RET_IOCB);
  9504. if (retval == IOCB_SUCCESS) {
  9505. timeout_req = msecs_to_jiffies(timeout * 1000);
  9506. timeleft = wait_event_timeout(done_q,
  9507. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  9508. timeout_req);
  9509. spin_lock_irqsave(&phba->hbalock, iflags);
  9510. if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
  9511. /*
  9512. * IOCB timed out. Inform the wake iocb wait
  9513. * completion function and set local status
  9514. */
  9515. iocb_completed = false;
  9516. piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
  9517. }
  9518. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9519. if (iocb_completed) {
  9520. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9521. "0331 IOCB wake signaled\n");
  9522. /* Note: we are not indicating if the IOCB has a success
  9523. * status or not - that's for the caller to check.
  9524. * IOCB_SUCCESS means just that the command was sent and
  9525. * completed. Not that it completed successfully.
  9526. * */
  9527. } else if (timeleft == 0) {
  9528. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9529. "0338 IOCB wait timeout error - no "
  9530. "wake response Data x%x\n", timeout);
  9531. retval = IOCB_TIMEDOUT;
  9532. } else {
  9533. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9534. "0330 IOCB wake NOT set, "
  9535. "Data x%x x%lx\n",
  9536. timeout, (timeleft / jiffies));
  9537. retval = IOCB_TIMEDOUT;
  9538. }
  9539. } else if (retval == IOCB_BUSY) {
  9540. if (phba->cfg_log_verbose & LOG_SLI) {
  9541. list_for_each_entry(iocb, &pring->txq, list) {
  9542. txq_cnt++;
  9543. }
  9544. list_for_each_entry(iocb, &pring->txcmplq, list) {
  9545. txcmplq_cnt++;
  9546. }
  9547. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9548. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9549. phba->iocb_cnt, txq_cnt, txcmplq_cnt);
  9550. }
  9551. return retval;
  9552. } else {
  9553. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9554. "0332 IOCB wait issue failed, Data x%x\n",
  9555. retval);
  9556. retval = IOCB_ERROR;
  9557. }
  9558. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9559. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9560. return IOCB_ERROR;
  9561. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9562. writel(creg_val, phba->HCregaddr);
  9563. readl(phba->HCregaddr); /* flush */
  9564. }
  9565. if (prspiocbq)
  9566. piocb->context2 = NULL;
  9567. piocb->context_un.wait_queue = NULL;
  9568. piocb->iocb_cmpl = NULL;
  9569. return retval;
  9570. }
  9571. /**
  9572. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9573. * @phba: Pointer to HBA context object.
  9574. * @pmboxq: Pointer to driver mailbox object.
  9575. * @timeout: Timeout in number of seconds.
  9576. *
  9577. * This function issues the mailbox to firmware and waits for the
  9578. * mailbox command to complete. If the mailbox command is not
  9579. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9580. * The function waits for the mailbox completion using an
  9581. * interruptible wait. If the thread is woken up due to a
  9582. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9583. * should not free the mailbox resources, if this function returns
  9584. * MBX_TIMEOUT.
  9585. * This function will sleep while waiting for mailbox completion.
  9586. * So, this function should not be called from any context which
  9587. * does not allow sleeping. Due to the same reason, this function
  9588. * cannot be called with interrupt disabled.
  9589. * This function assumes that the mailbox completion occurs while
  9590. * this function sleep. So, this function cannot be called from
  9591. * the worker thread which processes mailbox completion.
  9592. * This function is called in the context of HBA management
  9593. * applications.
  9594. * This function returns MBX_SUCCESS when successful.
  9595. * This function is called with no lock held.
  9596. **/
  9597. int
  9598. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9599. uint32_t timeout)
  9600. {
  9601. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9602. MAILBOX_t *mb = NULL;
  9603. int retval;
  9604. unsigned long flag;
  9605. /* The caller might set context1 for extended buffer */
  9606. if (pmboxq->context1)
  9607. mb = (MAILBOX_t *)pmboxq->context1;
  9608. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9609. /* setup wake call as IOCB callback */
  9610. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9611. /* setup context field to pass wait_queue pointer to wake function */
  9612. pmboxq->context1 = &done_q;
  9613. /* now issue the command */
  9614. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9615. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9616. wait_event_interruptible_timeout(done_q,
  9617. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9618. msecs_to_jiffies(timeout * 1000));
  9619. spin_lock_irqsave(&phba->hbalock, flag);
  9620. /* restore the possible extended buffer for free resource */
  9621. pmboxq->context1 = (uint8_t *)mb;
  9622. /*
  9623. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9624. * else do not free the resources.
  9625. */
  9626. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9627. retval = MBX_SUCCESS;
  9628. } else {
  9629. retval = MBX_TIMEOUT;
  9630. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9631. }
  9632. spin_unlock_irqrestore(&phba->hbalock, flag);
  9633. } else {
  9634. /* restore the possible extended buffer for free resource */
  9635. pmboxq->context1 = (uint8_t *)mb;
  9636. }
  9637. return retval;
  9638. }
  9639. /**
  9640. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9641. * @phba: Pointer to HBA context.
  9642. *
  9643. * This function is called to shutdown the driver's mailbox sub-system.
  9644. * It first marks the mailbox sub-system is in a block state to prevent
  9645. * the asynchronous mailbox command from issued off the pending mailbox
  9646. * command queue. If the mailbox command sub-system shutdown is due to
  9647. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9648. * the mailbox sub-system flush routine to forcefully bring down the
  9649. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9650. * as with offline or HBA function reset), this routine will wait for the
  9651. * outstanding mailbox command to complete before invoking the mailbox
  9652. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9653. **/
  9654. void
  9655. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
  9656. {
  9657. struct lpfc_sli *psli = &phba->sli;
  9658. unsigned long timeout;
  9659. if (mbx_action == LPFC_MBX_NO_WAIT) {
  9660. /* delay 100ms for port state */
  9661. msleep(100);
  9662. lpfc_sli_mbox_sys_flush(phba);
  9663. return;
  9664. }
  9665. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9666. spin_lock_irq(&phba->hbalock);
  9667. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9668. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9669. /* Determine how long we might wait for the active mailbox
  9670. * command to be gracefully completed by firmware.
  9671. */
  9672. if (phba->sli.mbox_active)
  9673. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9674. phba->sli.mbox_active) *
  9675. 1000) + jiffies;
  9676. spin_unlock_irq(&phba->hbalock);
  9677. while (phba->sli.mbox_active) {
  9678. /* Check active mailbox complete status every 2ms */
  9679. msleep(2);
  9680. if (time_after(jiffies, timeout))
  9681. /* Timeout, let the mailbox flush routine to
  9682. * forcefully release active mailbox command
  9683. */
  9684. break;
  9685. }
  9686. } else
  9687. spin_unlock_irq(&phba->hbalock);
  9688. lpfc_sli_mbox_sys_flush(phba);
  9689. }
  9690. /**
  9691. * lpfc_sli_eratt_read - read sli-3 error attention events
  9692. * @phba: Pointer to HBA context.
  9693. *
  9694. * This function is called to read the SLI3 device error attention registers
  9695. * for possible error attention events. The caller must hold the hostlock
  9696. * with spin_lock_irq().
  9697. *
  9698. * This function returns 1 when there is Error Attention in the Host Attention
  9699. * Register and returns 0 otherwise.
  9700. **/
  9701. static int
  9702. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9703. {
  9704. uint32_t ha_copy;
  9705. /* Read chip Host Attention (HA) register */
  9706. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9707. goto unplug_err;
  9708. if (ha_copy & HA_ERATT) {
  9709. /* Read host status register to retrieve error event */
  9710. if (lpfc_sli_read_hs(phba))
  9711. goto unplug_err;
  9712. /* Check if there is a deferred error condition is active */
  9713. if ((HS_FFER1 & phba->work_hs) &&
  9714. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9715. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9716. phba->hba_flag |= DEFER_ERATT;
  9717. /* Clear all interrupt enable conditions */
  9718. writel(0, phba->HCregaddr);
  9719. readl(phba->HCregaddr);
  9720. }
  9721. /* Set the driver HA work bitmap */
  9722. phba->work_ha |= HA_ERATT;
  9723. /* Indicate polling handles this ERATT */
  9724. phba->hba_flag |= HBA_ERATT_HANDLED;
  9725. return 1;
  9726. }
  9727. return 0;
  9728. unplug_err:
  9729. /* Set the driver HS work bitmap */
  9730. phba->work_hs |= UNPLUG_ERR;
  9731. /* Set the driver HA work bitmap */
  9732. phba->work_ha |= HA_ERATT;
  9733. /* Indicate polling handles this ERATT */
  9734. phba->hba_flag |= HBA_ERATT_HANDLED;
  9735. return 1;
  9736. }
  9737. /**
  9738. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9739. * @phba: Pointer to HBA context.
  9740. *
  9741. * This function is called to read the SLI4 device error attention registers
  9742. * for possible error attention events. The caller must hold the hostlock
  9743. * with spin_lock_irq().
  9744. *
  9745. * This function returns 1 when there is Error Attention in the Host Attention
  9746. * Register and returns 0 otherwise.
  9747. **/
  9748. static int
  9749. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9750. {
  9751. uint32_t uerr_sta_hi, uerr_sta_lo;
  9752. uint32_t if_type, portsmphr;
  9753. struct lpfc_register portstat_reg;
  9754. /*
  9755. * For now, use the SLI4 device internal unrecoverable error
  9756. * registers for error attention. This can be changed later.
  9757. */
  9758. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9759. switch (if_type) {
  9760. case LPFC_SLI_INTF_IF_TYPE_0:
  9761. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9762. &uerr_sta_lo) ||
  9763. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9764. &uerr_sta_hi)) {
  9765. phba->work_hs |= UNPLUG_ERR;
  9766. phba->work_ha |= HA_ERATT;
  9767. phba->hba_flag |= HBA_ERATT_HANDLED;
  9768. return 1;
  9769. }
  9770. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9771. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9772. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9773. "1423 HBA Unrecoverable error: "
  9774. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9775. "ue_mask_lo_reg=0x%x, "
  9776. "ue_mask_hi_reg=0x%x\n",
  9777. uerr_sta_lo, uerr_sta_hi,
  9778. phba->sli4_hba.ue_mask_lo,
  9779. phba->sli4_hba.ue_mask_hi);
  9780. phba->work_status[0] = uerr_sta_lo;
  9781. phba->work_status[1] = uerr_sta_hi;
  9782. phba->work_ha |= HA_ERATT;
  9783. phba->hba_flag |= HBA_ERATT_HANDLED;
  9784. return 1;
  9785. }
  9786. break;
  9787. case LPFC_SLI_INTF_IF_TYPE_2:
  9788. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9789. &portstat_reg.word0) ||
  9790. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9791. &portsmphr)){
  9792. phba->work_hs |= UNPLUG_ERR;
  9793. phba->work_ha |= HA_ERATT;
  9794. phba->hba_flag |= HBA_ERATT_HANDLED;
  9795. return 1;
  9796. }
  9797. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9798. phba->work_status[0] =
  9799. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9800. phba->work_status[1] =
  9801. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9802. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9803. "2885 Port Status Event: "
  9804. "port status reg 0x%x, "
  9805. "port smphr reg 0x%x, "
  9806. "error 1=0x%x, error 2=0x%x\n",
  9807. portstat_reg.word0,
  9808. portsmphr,
  9809. phba->work_status[0],
  9810. phba->work_status[1]);
  9811. phba->work_ha |= HA_ERATT;
  9812. phba->hba_flag |= HBA_ERATT_HANDLED;
  9813. return 1;
  9814. }
  9815. break;
  9816. case LPFC_SLI_INTF_IF_TYPE_1:
  9817. default:
  9818. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9819. "2886 HBA Error Attention on unsupported "
  9820. "if type %d.", if_type);
  9821. return 1;
  9822. }
  9823. return 0;
  9824. }
  9825. /**
  9826. * lpfc_sli_check_eratt - check error attention events
  9827. * @phba: Pointer to HBA context.
  9828. *
  9829. * This function is called from timer soft interrupt context to check HBA's
  9830. * error attention register bit for error attention events.
  9831. *
  9832. * This function returns 1 when there is Error Attention in the Host Attention
  9833. * Register and returns 0 otherwise.
  9834. **/
  9835. int
  9836. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9837. {
  9838. uint32_t ha_copy;
  9839. /* If somebody is waiting to handle an eratt, don't process it
  9840. * here. The brdkill function will do this.
  9841. */
  9842. if (phba->link_flag & LS_IGNORE_ERATT)
  9843. return 0;
  9844. /* Check if interrupt handler handles this ERATT */
  9845. spin_lock_irq(&phba->hbalock);
  9846. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9847. /* Interrupt handler has handled ERATT */
  9848. spin_unlock_irq(&phba->hbalock);
  9849. return 0;
  9850. }
  9851. /*
  9852. * If there is deferred error attention, do not check for error
  9853. * attention
  9854. */
  9855. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9856. spin_unlock_irq(&phba->hbalock);
  9857. return 0;
  9858. }
  9859. /* If PCI channel is offline, don't process it */
  9860. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9861. spin_unlock_irq(&phba->hbalock);
  9862. return 0;
  9863. }
  9864. switch (phba->sli_rev) {
  9865. case LPFC_SLI_REV2:
  9866. case LPFC_SLI_REV3:
  9867. /* Read chip Host Attention (HA) register */
  9868. ha_copy = lpfc_sli_eratt_read(phba);
  9869. break;
  9870. case LPFC_SLI_REV4:
  9871. /* Read device Uncoverable Error (UERR) registers */
  9872. ha_copy = lpfc_sli4_eratt_read(phba);
  9873. break;
  9874. default:
  9875. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9876. "0299 Invalid SLI revision (%d)\n",
  9877. phba->sli_rev);
  9878. ha_copy = 0;
  9879. break;
  9880. }
  9881. spin_unlock_irq(&phba->hbalock);
  9882. return ha_copy;
  9883. }
  9884. /**
  9885. * lpfc_intr_state_check - Check device state for interrupt handling
  9886. * @phba: Pointer to HBA context.
  9887. *
  9888. * This inline routine checks whether a device or its PCI slot is in a state
  9889. * that the interrupt should be handled.
  9890. *
  9891. * This function returns 0 if the device or the PCI slot is in a state that
  9892. * interrupt should be handled, otherwise -EIO.
  9893. */
  9894. static inline int
  9895. lpfc_intr_state_check(struct lpfc_hba *phba)
  9896. {
  9897. /* If the pci channel is offline, ignore all the interrupts */
  9898. if (unlikely(pci_channel_offline(phba->pcidev)))
  9899. return -EIO;
  9900. /* Update device level interrupt statistics */
  9901. phba->sli.slistat.sli_intr++;
  9902. /* Ignore all interrupts during initialization. */
  9903. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9904. return -EIO;
  9905. return 0;
  9906. }
  9907. /**
  9908. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9909. * @irq: Interrupt number.
  9910. * @dev_id: The device context pointer.
  9911. *
  9912. * This function is directly called from the PCI layer as an interrupt
  9913. * service routine when device with SLI-3 interface spec is enabled with
  9914. * MSI-X multi-message interrupt mode and there are slow-path events in
  9915. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9916. * interrupt mode, this function is called as part of the device-level
  9917. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9918. * is undergoing initialization, the interrupt handler will not process
  9919. * the interrupt. The link attention and ELS ring attention events are
  9920. * handled by the worker thread. The interrupt handler signals the worker
  9921. * thread and returns for these events. This function is called without
  9922. * any lock held. It gets the hbalock to access and update SLI data
  9923. * structures.
  9924. *
  9925. * This function returns IRQ_HANDLED when interrupt is handled else it
  9926. * returns IRQ_NONE.
  9927. **/
  9928. irqreturn_t
  9929. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9930. {
  9931. struct lpfc_hba *phba;
  9932. uint32_t ha_copy, hc_copy;
  9933. uint32_t work_ha_copy;
  9934. unsigned long status;
  9935. unsigned long iflag;
  9936. uint32_t control;
  9937. MAILBOX_t *mbox, *pmbox;
  9938. struct lpfc_vport *vport;
  9939. struct lpfc_nodelist *ndlp;
  9940. struct lpfc_dmabuf *mp;
  9941. LPFC_MBOXQ_t *pmb;
  9942. int rc;
  9943. /*
  9944. * Get the driver's phba structure from the dev_id and
  9945. * assume the HBA is not interrupting.
  9946. */
  9947. phba = (struct lpfc_hba *)dev_id;
  9948. if (unlikely(!phba))
  9949. return IRQ_NONE;
  9950. /*
  9951. * Stuff needs to be attented to when this function is invoked as an
  9952. * individual interrupt handler in MSI-X multi-message interrupt mode
  9953. */
  9954. if (phba->intr_type == MSIX) {
  9955. /* Check device state for handling interrupt */
  9956. if (lpfc_intr_state_check(phba))
  9957. return IRQ_NONE;
  9958. /* Need to read HA REG for slow-path events */
  9959. spin_lock_irqsave(&phba->hbalock, iflag);
  9960. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9961. goto unplug_error;
  9962. /* If somebody is waiting to handle an eratt don't process it
  9963. * here. The brdkill function will do this.
  9964. */
  9965. if (phba->link_flag & LS_IGNORE_ERATT)
  9966. ha_copy &= ~HA_ERATT;
  9967. /* Check the need for handling ERATT in interrupt handler */
  9968. if (ha_copy & HA_ERATT) {
  9969. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9970. /* ERATT polling has handled ERATT */
  9971. ha_copy &= ~HA_ERATT;
  9972. else
  9973. /* Indicate interrupt handler handles ERATT */
  9974. phba->hba_flag |= HBA_ERATT_HANDLED;
  9975. }
  9976. /*
  9977. * If there is deferred error attention, do not check for any
  9978. * interrupt.
  9979. */
  9980. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9981. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9982. return IRQ_NONE;
  9983. }
  9984. /* Clear up only attention source related to slow-path */
  9985. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9986. goto unplug_error;
  9987. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9988. HC_LAINT_ENA | HC_ERINT_ENA),
  9989. phba->HCregaddr);
  9990. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9991. phba->HAregaddr);
  9992. writel(hc_copy, phba->HCregaddr);
  9993. readl(phba->HAregaddr); /* flush */
  9994. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9995. } else
  9996. ha_copy = phba->ha_copy;
  9997. work_ha_copy = ha_copy & phba->work_ha_mask;
  9998. if (work_ha_copy) {
  9999. if (work_ha_copy & HA_LATT) {
  10000. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  10001. /*
  10002. * Turn off Link Attention interrupts
  10003. * until CLEAR_LA done
  10004. */
  10005. spin_lock_irqsave(&phba->hbalock, iflag);
  10006. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  10007. if (lpfc_readl(phba->HCregaddr, &control))
  10008. goto unplug_error;
  10009. control &= ~HC_LAINT_ENA;
  10010. writel(control, phba->HCregaddr);
  10011. readl(phba->HCregaddr); /* flush */
  10012. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10013. }
  10014. else
  10015. work_ha_copy &= ~HA_LATT;
  10016. }
  10017. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  10018. /*
  10019. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  10020. * the only slow ring.
  10021. */
  10022. status = (work_ha_copy &
  10023. (HA_RXMASK << (4*LPFC_ELS_RING)));
  10024. status >>= (4*LPFC_ELS_RING);
  10025. if (status & HA_RXMASK) {
  10026. spin_lock_irqsave(&phba->hbalock, iflag);
  10027. if (lpfc_readl(phba->HCregaddr, &control))
  10028. goto unplug_error;
  10029. lpfc_debugfs_slow_ring_trc(phba,
  10030. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  10031. control, status,
  10032. (uint32_t)phba->sli.slistat.sli_intr);
  10033. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  10034. lpfc_debugfs_slow_ring_trc(phba,
  10035. "ISR Disable ring:"
  10036. "pwork:x%x hawork:x%x wait:x%x",
  10037. phba->work_ha, work_ha_copy,
  10038. (uint32_t)((unsigned long)
  10039. &phba->work_waitq));
  10040. control &=
  10041. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  10042. writel(control, phba->HCregaddr);
  10043. readl(phba->HCregaddr); /* flush */
  10044. }
  10045. else {
  10046. lpfc_debugfs_slow_ring_trc(phba,
  10047. "ISR slow ring: pwork:"
  10048. "x%x hawork:x%x wait:x%x",
  10049. phba->work_ha, work_ha_copy,
  10050. (uint32_t)((unsigned long)
  10051. &phba->work_waitq));
  10052. }
  10053. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10054. }
  10055. }
  10056. spin_lock_irqsave(&phba->hbalock, iflag);
  10057. if (work_ha_copy & HA_ERATT) {
  10058. if (lpfc_sli_read_hs(phba))
  10059. goto unplug_error;
  10060. /*
  10061. * Check if there is a deferred error condition
  10062. * is active
  10063. */
  10064. if ((HS_FFER1 & phba->work_hs) &&
  10065. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  10066. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  10067. phba->work_hs)) {
  10068. phba->hba_flag |= DEFER_ERATT;
  10069. /* Clear all interrupt enable conditions */
  10070. writel(0, phba->HCregaddr);
  10071. readl(phba->HCregaddr);
  10072. }
  10073. }
  10074. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  10075. pmb = phba->sli.mbox_active;
  10076. pmbox = &pmb->u.mb;
  10077. mbox = phba->mbox;
  10078. vport = pmb->vport;
  10079. /* First check out the status word */
  10080. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  10081. if (pmbox->mbxOwner != OWN_HOST) {
  10082. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10083. /*
  10084. * Stray Mailbox Interrupt, mbxCommand <cmd>
  10085. * mbxStatus <status>
  10086. */
  10087. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10088. LOG_SLI,
  10089. "(%d):0304 Stray Mailbox "
  10090. "Interrupt mbxCommand x%x "
  10091. "mbxStatus x%x\n",
  10092. (vport ? vport->vpi : 0),
  10093. pmbox->mbxCommand,
  10094. pmbox->mbxStatus);
  10095. /* clear mailbox attention bit */
  10096. work_ha_copy &= ~HA_MBATT;
  10097. } else {
  10098. phba->sli.mbox_active = NULL;
  10099. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10100. phba->last_completion_time = jiffies;
  10101. del_timer(&phba->sli.mbox_tmo);
  10102. if (pmb->mbox_cmpl) {
  10103. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  10104. MAILBOX_CMD_SIZE);
  10105. if (pmb->out_ext_byte_len &&
  10106. pmb->context2)
  10107. lpfc_sli_pcimem_bcopy(
  10108. phba->mbox_ext,
  10109. pmb->context2,
  10110. pmb->out_ext_byte_len);
  10111. }
  10112. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10113. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10114. lpfc_debugfs_disc_trc(vport,
  10115. LPFC_DISC_TRC_MBOX_VPORT,
  10116. "MBOX dflt rpi: : "
  10117. "status:x%x rpi:x%x",
  10118. (uint32_t)pmbox->mbxStatus,
  10119. pmbox->un.varWords[0], 0);
  10120. if (!pmbox->mbxStatus) {
  10121. mp = (struct lpfc_dmabuf *)
  10122. (pmb->context1);
  10123. ndlp = (struct lpfc_nodelist *)
  10124. pmb->context2;
  10125. /* Reg_LOGIN of dflt RPI was
  10126. * successful. new lets get
  10127. * rid of the RPI using the
  10128. * same mbox buffer.
  10129. */
  10130. lpfc_unreg_login(phba,
  10131. vport->vpi,
  10132. pmbox->un.varWords[0],
  10133. pmb);
  10134. pmb->mbox_cmpl =
  10135. lpfc_mbx_cmpl_dflt_rpi;
  10136. pmb->context1 = mp;
  10137. pmb->context2 = ndlp;
  10138. pmb->vport = vport;
  10139. rc = lpfc_sli_issue_mbox(phba,
  10140. pmb,
  10141. MBX_NOWAIT);
  10142. if (rc != MBX_BUSY)
  10143. lpfc_printf_log(phba,
  10144. KERN_ERR,
  10145. LOG_MBOX | LOG_SLI,
  10146. "0350 rc should have"
  10147. "been MBX_BUSY\n");
  10148. if (rc != MBX_NOT_FINISHED)
  10149. goto send_current_mbox;
  10150. }
  10151. }
  10152. spin_lock_irqsave(
  10153. &phba->pport->work_port_lock,
  10154. iflag);
  10155. phba->pport->work_port_events &=
  10156. ~WORKER_MBOX_TMO;
  10157. spin_unlock_irqrestore(
  10158. &phba->pport->work_port_lock,
  10159. iflag);
  10160. lpfc_mbox_cmpl_put(phba, pmb);
  10161. }
  10162. } else
  10163. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10164. if ((work_ha_copy & HA_MBATT) &&
  10165. (phba->sli.mbox_active == NULL)) {
  10166. send_current_mbox:
  10167. /* Process next mailbox command if there is one */
  10168. do {
  10169. rc = lpfc_sli_issue_mbox(phba, NULL,
  10170. MBX_NOWAIT);
  10171. } while (rc == MBX_NOT_FINISHED);
  10172. if (rc != MBX_SUCCESS)
  10173. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10174. LOG_SLI, "0349 rc should be "
  10175. "MBX_SUCCESS\n");
  10176. }
  10177. spin_lock_irqsave(&phba->hbalock, iflag);
  10178. phba->work_ha |= work_ha_copy;
  10179. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10180. lpfc_worker_wake_up(phba);
  10181. }
  10182. return IRQ_HANDLED;
  10183. unplug_error:
  10184. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10185. return IRQ_HANDLED;
  10186. } /* lpfc_sli_sp_intr_handler */
  10187. /**
  10188. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  10189. * @irq: Interrupt number.
  10190. * @dev_id: The device context pointer.
  10191. *
  10192. * This function is directly called from the PCI layer as an interrupt
  10193. * service routine when device with SLI-3 interface spec is enabled with
  10194. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10195. * ring event in the HBA. However, when the device is enabled with either
  10196. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10197. * device-level interrupt handler. When the PCI slot is in error recovery
  10198. * or the HBA is undergoing initialization, the interrupt handler will not
  10199. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10200. * the intrrupt context. This function is called without any lock held.
  10201. * It gets the hbalock to access and update SLI data structures.
  10202. *
  10203. * This function returns IRQ_HANDLED when interrupt is handled else it
  10204. * returns IRQ_NONE.
  10205. **/
  10206. irqreturn_t
  10207. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  10208. {
  10209. struct lpfc_hba *phba;
  10210. uint32_t ha_copy;
  10211. unsigned long status;
  10212. unsigned long iflag;
  10213. /* Get the driver's phba structure from the dev_id and
  10214. * assume the HBA is not interrupting.
  10215. */
  10216. phba = (struct lpfc_hba *) dev_id;
  10217. if (unlikely(!phba))
  10218. return IRQ_NONE;
  10219. /*
  10220. * Stuff needs to be attented to when this function is invoked as an
  10221. * individual interrupt handler in MSI-X multi-message interrupt mode
  10222. */
  10223. if (phba->intr_type == MSIX) {
  10224. /* Check device state for handling interrupt */
  10225. if (lpfc_intr_state_check(phba))
  10226. return IRQ_NONE;
  10227. /* Need to read HA REG for FCP ring and other ring events */
  10228. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  10229. return IRQ_HANDLED;
  10230. /* Clear up only attention source related to fast-path */
  10231. spin_lock_irqsave(&phba->hbalock, iflag);
  10232. /*
  10233. * If there is deferred error attention, do not check for
  10234. * any interrupt.
  10235. */
  10236. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10237. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10238. return IRQ_NONE;
  10239. }
  10240. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  10241. phba->HAregaddr);
  10242. readl(phba->HAregaddr); /* flush */
  10243. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10244. } else
  10245. ha_copy = phba->ha_copy;
  10246. /*
  10247. * Process all events on FCP ring. Take the optimized path for FCP IO.
  10248. */
  10249. ha_copy &= ~(phba->work_ha_mask);
  10250. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  10251. status >>= (4*LPFC_FCP_RING);
  10252. if (status & HA_RXMASK)
  10253. lpfc_sli_handle_fast_ring_event(phba,
  10254. &phba->sli.ring[LPFC_FCP_RING],
  10255. status);
  10256. if (phba->cfg_multi_ring_support == 2) {
  10257. /*
  10258. * Process all events on extra ring. Take the optimized path
  10259. * for extra ring IO.
  10260. */
  10261. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  10262. status >>= (4*LPFC_EXTRA_RING);
  10263. if (status & HA_RXMASK) {
  10264. lpfc_sli_handle_fast_ring_event(phba,
  10265. &phba->sli.ring[LPFC_EXTRA_RING],
  10266. status);
  10267. }
  10268. }
  10269. return IRQ_HANDLED;
  10270. } /* lpfc_sli_fp_intr_handler */
  10271. /**
  10272. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  10273. * @irq: Interrupt number.
  10274. * @dev_id: The device context pointer.
  10275. *
  10276. * This function is the HBA device-level interrupt handler to device with
  10277. * SLI-3 interface spec, called from the PCI layer when either MSI or
  10278. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  10279. * requires driver attention. This function invokes the slow-path interrupt
  10280. * attention handling function and fast-path interrupt attention handling
  10281. * function in turn to process the relevant HBA attention events. This
  10282. * function is called without any lock held. It gets the hbalock to access
  10283. * and update SLI data structures.
  10284. *
  10285. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10286. * returns IRQ_NONE.
  10287. **/
  10288. irqreturn_t
  10289. lpfc_sli_intr_handler(int irq, void *dev_id)
  10290. {
  10291. struct lpfc_hba *phba;
  10292. irqreturn_t sp_irq_rc, fp_irq_rc;
  10293. unsigned long status1, status2;
  10294. uint32_t hc_copy;
  10295. /*
  10296. * Get the driver's phba structure from the dev_id and
  10297. * assume the HBA is not interrupting.
  10298. */
  10299. phba = (struct lpfc_hba *) dev_id;
  10300. if (unlikely(!phba))
  10301. return IRQ_NONE;
  10302. /* Check device state for handling interrupt */
  10303. if (lpfc_intr_state_check(phba))
  10304. return IRQ_NONE;
  10305. spin_lock(&phba->hbalock);
  10306. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  10307. spin_unlock(&phba->hbalock);
  10308. return IRQ_HANDLED;
  10309. }
  10310. if (unlikely(!phba->ha_copy)) {
  10311. spin_unlock(&phba->hbalock);
  10312. return IRQ_NONE;
  10313. } else if (phba->ha_copy & HA_ERATT) {
  10314. if (phba->hba_flag & HBA_ERATT_HANDLED)
  10315. /* ERATT polling has handled ERATT */
  10316. phba->ha_copy &= ~HA_ERATT;
  10317. else
  10318. /* Indicate interrupt handler handles ERATT */
  10319. phba->hba_flag |= HBA_ERATT_HANDLED;
  10320. }
  10321. /*
  10322. * If there is deferred error attention, do not check for any interrupt.
  10323. */
  10324. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  10325. spin_unlock(&phba->hbalock);
  10326. return IRQ_NONE;
  10327. }
  10328. /* Clear attention sources except link and error attentions */
  10329. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  10330. spin_unlock(&phba->hbalock);
  10331. return IRQ_HANDLED;
  10332. }
  10333. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  10334. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  10335. phba->HCregaddr);
  10336. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  10337. writel(hc_copy, phba->HCregaddr);
  10338. readl(phba->HAregaddr); /* flush */
  10339. spin_unlock(&phba->hbalock);
  10340. /*
  10341. * Invokes slow-path host attention interrupt handling as appropriate.
  10342. */
  10343. /* status of events with mailbox and link attention */
  10344. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  10345. /* status of events with ELS ring */
  10346. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  10347. status2 >>= (4*LPFC_ELS_RING);
  10348. if (status1 || (status2 & HA_RXMASK))
  10349. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  10350. else
  10351. sp_irq_rc = IRQ_NONE;
  10352. /*
  10353. * Invoke fast-path host attention interrupt handling as appropriate.
  10354. */
  10355. /* status of events with FCP ring */
  10356. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  10357. status1 >>= (4*LPFC_FCP_RING);
  10358. /* status of events with extra ring */
  10359. if (phba->cfg_multi_ring_support == 2) {
  10360. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  10361. status2 >>= (4*LPFC_EXTRA_RING);
  10362. } else
  10363. status2 = 0;
  10364. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  10365. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  10366. else
  10367. fp_irq_rc = IRQ_NONE;
  10368. /* Return device-level interrupt handling status */
  10369. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  10370. } /* lpfc_sli_intr_handler */
  10371. /**
  10372. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  10373. * @phba: pointer to lpfc hba data structure.
  10374. *
  10375. * This routine is invoked by the worker thread to process all the pending
  10376. * SLI4 FCP abort XRI events.
  10377. **/
  10378. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  10379. {
  10380. struct lpfc_cq_event *cq_event;
  10381. /* First, declare the fcp xri abort event has been handled */
  10382. spin_lock_irq(&phba->hbalock);
  10383. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  10384. spin_unlock_irq(&phba->hbalock);
  10385. /* Now, handle all the fcp xri abort events */
  10386. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  10387. /* Get the first event from the head of the event queue */
  10388. spin_lock_irq(&phba->hbalock);
  10389. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  10390. cq_event, struct lpfc_cq_event, list);
  10391. spin_unlock_irq(&phba->hbalock);
  10392. /* Notify aborted XRI for FCP work queue */
  10393. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10394. /* Free the event processed back to the free pool */
  10395. lpfc_sli4_cq_event_release(phba, cq_event);
  10396. }
  10397. }
  10398. /**
  10399. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  10400. * @phba: pointer to lpfc hba data structure.
  10401. *
  10402. * This routine is invoked by the worker thread to process all the pending
  10403. * SLI4 els abort xri events.
  10404. **/
  10405. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  10406. {
  10407. struct lpfc_cq_event *cq_event;
  10408. /* First, declare the els xri abort event has been handled */
  10409. spin_lock_irq(&phba->hbalock);
  10410. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  10411. spin_unlock_irq(&phba->hbalock);
  10412. /* Now, handle all the els xri abort events */
  10413. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  10414. /* Get the first event from the head of the event queue */
  10415. spin_lock_irq(&phba->hbalock);
  10416. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  10417. cq_event, struct lpfc_cq_event, list);
  10418. spin_unlock_irq(&phba->hbalock);
  10419. /* Notify aborted XRI for ELS work queue */
  10420. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10421. /* Free the event processed back to the free pool */
  10422. lpfc_sli4_cq_event_release(phba, cq_event);
  10423. }
  10424. }
  10425. /**
  10426. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  10427. * @phba: pointer to lpfc hba data structure
  10428. * @pIocbIn: pointer to the rspiocbq
  10429. * @pIocbOut: pointer to the cmdiocbq
  10430. * @wcqe: pointer to the complete wcqe
  10431. *
  10432. * This routine transfers the fields of a command iocbq to a response iocbq
  10433. * by copying all the IOCB fields from command iocbq and transferring the
  10434. * completion status information from the complete wcqe.
  10435. **/
  10436. static void
  10437. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  10438. struct lpfc_iocbq *pIocbIn,
  10439. struct lpfc_iocbq *pIocbOut,
  10440. struct lpfc_wcqe_complete *wcqe)
  10441. {
  10442. int numBdes, i;
  10443. unsigned long iflags;
  10444. uint32_t status, max_response;
  10445. struct lpfc_dmabuf *dmabuf;
  10446. struct ulp_bde64 *bpl, bde;
  10447. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  10448. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  10449. sizeof(struct lpfc_iocbq) - offset);
  10450. /* Map WCQE parameters into irspiocb parameters */
  10451. status = bf_get(lpfc_wcqe_c_status, wcqe);
  10452. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  10453. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  10454. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  10455. pIocbIn->iocb.un.fcpi.fcpi_parm =
  10456. pIocbOut->iocb.un.fcpi.fcpi_parm -
  10457. wcqe->total_data_placed;
  10458. else
  10459. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10460. else {
  10461. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10462. switch (pIocbOut->iocb.ulpCommand) {
  10463. case CMD_ELS_REQUEST64_CR:
  10464. dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
  10465. bpl = (struct ulp_bde64 *)dmabuf->virt;
  10466. bde.tus.w = le32_to_cpu(bpl[1].tus.w);
  10467. max_response = bde.tus.f.bdeSize;
  10468. break;
  10469. case CMD_GEN_REQUEST64_CR:
  10470. max_response = 0;
  10471. if (!pIocbOut->context3)
  10472. break;
  10473. numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
  10474. sizeof(struct ulp_bde64);
  10475. dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
  10476. bpl = (struct ulp_bde64 *)dmabuf->virt;
  10477. for (i = 0; i < numBdes; i++) {
  10478. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  10479. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  10480. max_response += bde.tus.f.bdeSize;
  10481. }
  10482. break;
  10483. default:
  10484. max_response = wcqe->total_data_placed;
  10485. break;
  10486. }
  10487. if (max_response < wcqe->total_data_placed)
  10488. pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
  10489. else
  10490. pIocbIn->iocb.un.genreq64.bdl.bdeSize =
  10491. wcqe->total_data_placed;
  10492. }
  10493. /* Convert BG errors for completion status */
  10494. if (status == CQE_STATUS_DI_ERROR) {
  10495. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  10496. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  10497. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  10498. else
  10499. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  10500. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  10501. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  10502. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10503. BGS_GUARD_ERR_MASK;
  10504. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  10505. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10506. BGS_APPTAG_ERR_MASK;
  10507. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  10508. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10509. BGS_REFTAG_ERR_MASK;
  10510. /* Check to see if there was any good data before the error */
  10511. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  10512. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10513. BGS_HI_WATER_MARK_PRESENT_MASK;
  10514. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  10515. wcqe->total_data_placed;
  10516. }
  10517. /*
  10518. * Set ALL the error bits to indicate we don't know what
  10519. * type of error it is.
  10520. */
  10521. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  10522. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10523. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  10524. BGS_GUARD_ERR_MASK);
  10525. }
  10526. /* Pick up HBA exchange busy condition */
  10527. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  10528. spin_lock_irqsave(&phba->hbalock, iflags);
  10529. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  10530. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10531. }
  10532. }
  10533. /**
  10534. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  10535. * @phba: Pointer to HBA context object.
  10536. * @wcqe: Pointer to work-queue completion queue entry.
  10537. *
  10538. * This routine handles an ELS work-queue completion event and construct
  10539. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  10540. * discovery engine to handle.
  10541. *
  10542. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  10543. **/
  10544. static struct lpfc_iocbq *
  10545. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  10546. struct lpfc_iocbq *irspiocbq)
  10547. {
  10548. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  10549. struct lpfc_iocbq *cmdiocbq;
  10550. struct lpfc_wcqe_complete *wcqe;
  10551. unsigned long iflags;
  10552. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  10553. spin_lock_irqsave(&pring->ring_lock, iflags);
  10554. pring->stats.iocb_event++;
  10555. /* Look up the ELS command IOCB and create pseudo response IOCB */
  10556. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10557. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10558. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10559. if (unlikely(!cmdiocbq)) {
  10560. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10561. "0386 ELS complete with no corresponding "
  10562. "cmdiocb: iotag (%d)\n",
  10563. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10564. lpfc_sli_release_iocbq(phba, irspiocbq);
  10565. return NULL;
  10566. }
  10567. /* Fake the irspiocbq and copy necessary response information */
  10568. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  10569. return irspiocbq;
  10570. }
  10571. /**
  10572. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  10573. * @phba: Pointer to HBA context object.
  10574. * @cqe: Pointer to mailbox completion queue entry.
  10575. *
  10576. * This routine process a mailbox completion queue entry with asynchrous
  10577. * event.
  10578. *
  10579. * Return: true if work posted to worker thread, otherwise false.
  10580. **/
  10581. static bool
  10582. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10583. {
  10584. struct lpfc_cq_event *cq_event;
  10585. unsigned long iflags;
  10586. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10587. "0392 Async Event: word0:x%x, word1:x%x, "
  10588. "word2:x%x, word3:x%x\n", mcqe->word0,
  10589. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10590. /* Allocate a new internal CQ_EVENT entry */
  10591. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10592. if (!cq_event) {
  10593. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10594. "0394 Failed to allocate CQ_EVENT entry\n");
  10595. return false;
  10596. }
  10597. /* Move the CQE into an asynchronous event entry */
  10598. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10599. spin_lock_irqsave(&phba->hbalock, iflags);
  10600. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10601. /* Set the async event flag */
  10602. phba->hba_flag |= ASYNC_EVENT;
  10603. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10604. return true;
  10605. }
  10606. /**
  10607. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10608. * @phba: Pointer to HBA context object.
  10609. * @cqe: Pointer to mailbox completion queue entry.
  10610. *
  10611. * This routine process a mailbox completion queue entry with mailbox
  10612. * completion event.
  10613. *
  10614. * Return: true if work posted to worker thread, otherwise false.
  10615. **/
  10616. static bool
  10617. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10618. {
  10619. uint32_t mcqe_status;
  10620. MAILBOX_t *mbox, *pmbox;
  10621. struct lpfc_mqe *mqe;
  10622. struct lpfc_vport *vport;
  10623. struct lpfc_nodelist *ndlp;
  10624. struct lpfc_dmabuf *mp;
  10625. unsigned long iflags;
  10626. LPFC_MBOXQ_t *pmb;
  10627. bool workposted = false;
  10628. int rc;
  10629. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10630. if (!bf_get(lpfc_trailer_completed, mcqe))
  10631. goto out_no_mqe_complete;
  10632. /* Get the reference to the active mbox command */
  10633. spin_lock_irqsave(&phba->hbalock, iflags);
  10634. pmb = phba->sli.mbox_active;
  10635. if (unlikely(!pmb)) {
  10636. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10637. "1832 No pending MBOX command to handle\n");
  10638. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10639. goto out_no_mqe_complete;
  10640. }
  10641. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10642. mqe = &pmb->u.mqe;
  10643. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10644. mbox = phba->mbox;
  10645. vport = pmb->vport;
  10646. /* Reset heartbeat timer */
  10647. phba->last_completion_time = jiffies;
  10648. del_timer(&phba->sli.mbox_tmo);
  10649. /* Move mbox data to caller's mailbox region, do endian swapping */
  10650. if (pmb->mbox_cmpl && mbox)
  10651. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10652. /*
  10653. * For mcqe errors, conditionally move a modified error code to
  10654. * the mbox so that the error will not be missed.
  10655. */
  10656. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10657. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10658. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10659. bf_set(lpfc_mqe_status, mqe,
  10660. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10661. }
  10662. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10663. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10664. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10665. "MBOX dflt rpi: status:x%x rpi:x%x",
  10666. mcqe_status,
  10667. pmbox->un.varWords[0], 0);
  10668. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10669. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10670. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10671. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10672. * RID of the PPI using the same mbox buffer.
  10673. */
  10674. lpfc_unreg_login(phba, vport->vpi,
  10675. pmbox->un.varWords[0], pmb);
  10676. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10677. pmb->context1 = mp;
  10678. pmb->context2 = ndlp;
  10679. pmb->vport = vport;
  10680. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10681. if (rc != MBX_BUSY)
  10682. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10683. LOG_SLI, "0385 rc should "
  10684. "have been MBX_BUSY\n");
  10685. if (rc != MBX_NOT_FINISHED)
  10686. goto send_current_mbox;
  10687. }
  10688. }
  10689. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10690. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10691. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10692. /* There is mailbox completion work to do */
  10693. spin_lock_irqsave(&phba->hbalock, iflags);
  10694. __lpfc_mbox_cmpl_put(phba, pmb);
  10695. phba->work_ha |= HA_MBATT;
  10696. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10697. workposted = true;
  10698. send_current_mbox:
  10699. spin_lock_irqsave(&phba->hbalock, iflags);
  10700. /* Release the mailbox command posting token */
  10701. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10702. /* Setting active mailbox pointer need to be in sync to flag clear */
  10703. phba->sli.mbox_active = NULL;
  10704. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10705. /* Wake up worker thread to post the next pending mailbox command */
  10706. lpfc_worker_wake_up(phba);
  10707. out_no_mqe_complete:
  10708. if (bf_get(lpfc_trailer_consumed, mcqe))
  10709. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10710. return workposted;
  10711. }
  10712. /**
  10713. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10714. * @phba: Pointer to HBA context object.
  10715. * @cqe: Pointer to mailbox completion queue entry.
  10716. *
  10717. * This routine process a mailbox completion queue entry, it invokes the
  10718. * proper mailbox complete handling or asynchrous event handling routine
  10719. * according to the MCQE's async bit.
  10720. *
  10721. * Return: true if work posted to worker thread, otherwise false.
  10722. **/
  10723. static bool
  10724. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10725. {
  10726. struct lpfc_mcqe mcqe;
  10727. bool workposted;
  10728. /* Copy the mailbox MCQE and convert endian order as needed */
  10729. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10730. /* Invoke the proper event handling routine */
  10731. if (!bf_get(lpfc_trailer_async, &mcqe))
  10732. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10733. else
  10734. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10735. return workposted;
  10736. }
  10737. /**
  10738. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10739. * @phba: Pointer to HBA context object.
  10740. * @cq: Pointer to associated CQ
  10741. * @wcqe: Pointer to work-queue completion queue entry.
  10742. *
  10743. * This routine handles an ELS work-queue completion event.
  10744. *
  10745. * Return: true if work posted to worker thread, otherwise false.
  10746. **/
  10747. static bool
  10748. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10749. struct lpfc_wcqe_complete *wcqe)
  10750. {
  10751. struct lpfc_iocbq *irspiocbq;
  10752. unsigned long iflags;
  10753. struct lpfc_sli_ring *pring = cq->pring;
  10754. int txq_cnt = 0;
  10755. int txcmplq_cnt = 0;
  10756. int fcp_txcmplq_cnt = 0;
  10757. /* Get an irspiocbq for later ELS response processing use */
  10758. irspiocbq = lpfc_sli_get_iocbq(phba);
  10759. if (!irspiocbq) {
  10760. if (!list_empty(&pring->txq))
  10761. txq_cnt++;
  10762. if (!list_empty(&pring->txcmplq))
  10763. txcmplq_cnt++;
  10764. if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
  10765. fcp_txcmplq_cnt++;
  10766. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10767. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10768. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10769. txq_cnt, phba->iocb_cnt,
  10770. fcp_txcmplq_cnt,
  10771. txcmplq_cnt);
  10772. return false;
  10773. }
  10774. /* Save off the slow-path queue event for work thread to process */
  10775. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10776. spin_lock_irqsave(&phba->hbalock, iflags);
  10777. list_add_tail(&irspiocbq->cq_event.list,
  10778. &phba->sli4_hba.sp_queue_event);
  10779. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10780. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10781. return true;
  10782. }
  10783. /**
  10784. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10785. * @phba: Pointer to HBA context object.
  10786. * @wcqe: Pointer to work-queue completion queue entry.
  10787. *
  10788. * This routine handles slow-path WQ entry comsumed event by invoking the
  10789. * proper WQ release routine to the slow-path WQ.
  10790. **/
  10791. static void
  10792. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10793. struct lpfc_wcqe_release *wcqe)
  10794. {
  10795. /* sanity check on queue memory */
  10796. if (unlikely(!phba->sli4_hba.els_wq))
  10797. return;
  10798. /* Check for the slow-path ELS work queue */
  10799. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10800. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10801. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10802. else
  10803. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10804. "2579 Slow-path wqe consume event carries "
  10805. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10806. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10807. phba->sli4_hba.els_wq->queue_id);
  10808. }
  10809. /**
  10810. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10811. * @phba: Pointer to HBA context object.
  10812. * @cq: Pointer to a WQ completion queue.
  10813. * @wcqe: Pointer to work-queue completion queue entry.
  10814. *
  10815. * This routine handles an XRI abort event.
  10816. *
  10817. * Return: true if work posted to worker thread, otherwise false.
  10818. **/
  10819. static bool
  10820. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10821. struct lpfc_queue *cq,
  10822. struct sli4_wcqe_xri_aborted *wcqe)
  10823. {
  10824. bool workposted = false;
  10825. struct lpfc_cq_event *cq_event;
  10826. unsigned long iflags;
  10827. /* Allocate a new internal CQ_EVENT entry */
  10828. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10829. if (!cq_event) {
  10830. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10831. "0602 Failed to allocate CQ_EVENT entry\n");
  10832. return false;
  10833. }
  10834. /* Move the CQE into the proper xri abort event list */
  10835. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10836. switch (cq->subtype) {
  10837. case LPFC_FCP:
  10838. spin_lock_irqsave(&phba->hbalock, iflags);
  10839. list_add_tail(&cq_event->list,
  10840. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10841. /* Set the fcp xri abort event flag */
  10842. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10843. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10844. workposted = true;
  10845. break;
  10846. case LPFC_ELS:
  10847. spin_lock_irqsave(&phba->hbalock, iflags);
  10848. list_add_tail(&cq_event->list,
  10849. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10850. /* Set the els xri abort event flag */
  10851. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10852. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10853. workposted = true;
  10854. break;
  10855. default:
  10856. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10857. "0603 Invalid work queue CQE subtype (x%x)\n",
  10858. cq->subtype);
  10859. workposted = false;
  10860. break;
  10861. }
  10862. return workposted;
  10863. }
  10864. /**
  10865. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10866. * @phba: Pointer to HBA context object.
  10867. * @rcqe: Pointer to receive-queue completion queue entry.
  10868. *
  10869. * This routine process a receive-queue completion queue entry.
  10870. *
  10871. * Return: true if work posted to worker thread, otherwise false.
  10872. **/
  10873. static bool
  10874. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10875. {
  10876. bool workposted = false;
  10877. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10878. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10879. struct hbq_dmabuf *dma_buf;
  10880. uint32_t status, rq_id;
  10881. unsigned long iflags;
  10882. /* sanity check on queue memory */
  10883. if (unlikely(!hrq) || unlikely(!drq))
  10884. return workposted;
  10885. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10886. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10887. else
  10888. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10889. if (rq_id != hrq->queue_id)
  10890. goto out;
  10891. status = bf_get(lpfc_rcqe_status, rcqe);
  10892. switch (status) {
  10893. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10894. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10895. "2537 Receive Frame Truncated!!\n");
  10896. hrq->RQ_buf_trunc++;
  10897. case FC_STATUS_RQ_SUCCESS:
  10898. lpfc_sli4_rq_release(hrq, drq);
  10899. spin_lock_irqsave(&phba->hbalock, iflags);
  10900. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10901. if (!dma_buf) {
  10902. hrq->RQ_no_buf_found++;
  10903. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10904. goto out;
  10905. }
  10906. hrq->RQ_rcv_buf++;
  10907. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10908. /* save off the frame for the word thread to process */
  10909. list_add_tail(&dma_buf->cq_event.list,
  10910. &phba->sli4_hba.sp_queue_event);
  10911. /* Frame received */
  10912. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10913. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10914. workposted = true;
  10915. break;
  10916. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10917. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10918. hrq->RQ_no_posted_buf++;
  10919. /* Post more buffers if possible */
  10920. spin_lock_irqsave(&phba->hbalock, iflags);
  10921. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10922. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10923. workposted = true;
  10924. break;
  10925. }
  10926. out:
  10927. return workposted;
  10928. }
  10929. /**
  10930. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10931. * @phba: Pointer to HBA context object.
  10932. * @cq: Pointer to the completion queue.
  10933. * @wcqe: Pointer to a completion queue entry.
  10934. *
  10935. * This routine process a slow-path work-queue or receive queue completion queue
  10936. * entry.
  10937. *
  10938. * Return: true if work posted to worker thread, otherwise false.
  10939. **/
  10940. static bool
  10941. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10942. struct lpfc_cqe *cqe)
  10943. {
  10944. struct lpfc_cqe cqevt;
  10945. bool workposted = false;
  10946. /* Copy the work queue CQE and convert endian order if needed */
  10947. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10948. /* Check and process for different type of WCQE and dispatch */
  10949. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10950. case CQE_CODE_COMPL_WQE:
  10951. /* Process the WQ/RQ complete event */
  10952. phba->last_completion_time = jiffies;
  10953. workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
  10954. (struct lpfc_wcqe_complete *)&cqevt);
  10955. break;
  10956. case CQE_CODE_RELEASE_WQE:
  10957. /* Process the WQ release event */
  10958. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10959. (struct lpfc_wcqe_release *)&cqevt);
  10960. break;
  10961. case CQE_CODE_XRI_ABORTED:
  10962. /* Process the WQ XRI abort event */
  10963. phba->last_completion_time = jiffies;
  10964. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10965. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10966. break;
  10967. case CQE_CODE_RECEIVE:
  10968. case CQE_CODE_RECEIVE_V1:
  10969. /* Process the RQ event */
  10970. phba->last_completion_time = jiffies;
  10971. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10972. (struct lpfc_rcqe *)&cqevt);
  10973. break;
  10974. default:
  10975. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10976. "0388 Not a valid WCQE code: x%x\n",
  10977. bf_get(lpfc_cqe_code, &cqevt));
  10978. break;
  10979. }
  10980. return workposted;
  10981. }
  10982. /**
  10983. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10984. * @phba: Pointer to HBA context object.
  10985. * @eqe: Pointer to fast-path event queue entry.
  10986. *
  10987. * This routine process a event queue entry from the slow-path event queue.
  10988. * It will check the MajorCode and MinorCode to determine this is for a
  10989. * completion event on a completion queue, if not, an error shall be logged
  10990. * and just return. Otherwise, it will get to the corresponding completion
  10991. * queue and process all the entries on that completion queue, rearm the
  10992. * completion queue, and then return.
  10993. *
  10994. **/
  10995. static void
  10996. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10997. struct lpfc_queue *speq)
  10998. {
  10999. struct lpfc_queue *cq = NULL, *childq;
  11000. struct lpfc_cqe *cqe;
  11001. bool workposted = false;
  11002. int ecount = 0;
  11003. uint16_t cqid;
  11004. /* Get the reference to the corresponding CQ */
  11005. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11006. list_for_each_entry(childq, &speq->child_list, list) {
  11007. if (childq->queue_id == cqid) {
  11008. cq = childq;
  11009. break;
  11010. }
  11011. }
  11012. if (unlikely(!cq)) {
  11013. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11014. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11015. "0365 Slow-path CQ identifier "
  11016. "(%d) does not exist\n", cqid);
  11017. return;
  11018. }
  11019. /* Process all the entries to the CQ */
  11020. switch (cq->type) {
  11021. case LPFC_MCQ:
  11022. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11023. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  11024. if (!(++ecount % cq->entry_repost))
  11025. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11026. cq->CQ_mbox++;
  11027. }
  11028. break;
  11029. case LPFC_WCQ:
  11030. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11031. if (cq->subtype == LPFC_FCP)
  11032. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  11033. cqe);
  11034. else
  11035. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  11036. cqe);
  11037. if (!(++ecount % cq->entry_repost))
  11038. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11039. }
  11040. /* Track the max number of CQEs processed in 1 EQ */
  11041. if (ecount > cq->CQ_max_cqe)
  11042. cq->CQ_max_cqe = ecount;
  11043. break;
  11044. default:
  11045. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11046. "0370 Invalid completion queue type (%d)\n",
  11047. cq->type);
  11048. return;
  11049. }
  11050. /* Catch the no cq entry condition, log an error */
  11051. if (unlikely(ecount == 0))
  11052. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11053. "0371 No entry from the CQ: identifier "
  11054. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  11055. /* In any case, flash and re-arm the RCQ */
  11056. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11057. /* wake up worker thread if there are works to be done */
  11058. if (workposted)
  11059. lpfc_worker_wake_up(phba);
  11060. }
  11061. /**
  11062. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  11063. * @phba: Pointer to HBA context object.
  11064. * @cq: Pointer to associated CQ
  11065. * @wcqe: Pointer to work-queue completion queue entry.
  11066. *
  11067. * This routine process a fast-path work queue completion entry from fast-path
  11068. * event queue for FCP command response completion.
  11069. **/
  11070. static void
  11071. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11072. struct lpfc_wcqe_complete *wcqe)
  11073. {
  11074. struct lpfc_sli_ring *pring = cq->pring;
  11075. struct lpfc_iocbq *cmdiocbq;
  11076. struct lpfc_iocbq irspiocbq;
  11077. unsigned long iflags;
  11078. /* Check for response status */
  11079. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  11080. /* If resource errors reported from HBA, reduce queue
  11081. * depth of the SCSI device.
  11082. */
  11083. if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
  11084. IOSTAT_LOCAL_REJECT)) &&
  11085. ((wcqe->parameter & IOERR_PARAM_MASK) ==
  11086. IOERR_NO_RESOURCES))
  11087. phba->lpfc_rampdown_queue_depth(phba);
  11088. /* Log the error status */
  11089. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11090. "0373 FCP complete error: status=x%x, "
  11091. "hw_status=x%x, total_data_specified=%d, "
  11092. "parameter=x%x, word3=x%x\n",
  11093. bf_get(lpfc_wcqe_c_status, wcqe),
  11094. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  11095. wcqe->total_data_placed, wcqe->parameter,
  11096. wcqe->word3);
  11097. }
  11098. /* Look up the FCP command IOCB and create pseudo response IOCB */
  11099. spin_lock_irqsave(&pring->ring_lock, iflags);
  11100. pring->stats.iocb_event++;
  11101. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  11102. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11103. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  11104. if (unlikely(!cmdiocbq)) {
  11105. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11106. "0374 FCP complete with no corresponding "
  11107. "cmdiocb: iotag (%d)\n",
  11108. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11109. return;
  11110. }
  11111. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  11112. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11113. "0375 FCP cmdiocb not callback function "
  11114. "iotag: (%d)\n",
  11115. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  11116. return;
  11117. }
  11118. /* Fake the irspiocb and copy necessary response information */
  11119. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  11120. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  11121. spin_lock_irqsave(&phba->hbalock, iflags);
  11122. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  11123. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11124. }
  11125. /* Pass the cmd_iocb and the rsp state to the upper layer */
  11126. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  11127. }
  11128. /**
  11129. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  11130. * @phba: Pointer to HBA context object.
  11131. * @cq: Pointer to completion queue.
  11132. * @wcqe: Pointer to work-queue completion queue entry.
  11133. *
  11134. * This routine handles an fast-path WQ entry comsumed event by invoking the
  11135. * proper WQ release routine to the slow-path WQ.
  11136. **/
  11137. static void
  11138. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11139. struct lpfc_wcqe_release *wcqe)
  11140. {
  11141. struct lpfc_queue *childwq;
  11142. bool wqid_matched = false;
  11143. uint16_t fcp_wqid;
  11144. /* Check for fast-path FCP work queue release */
  11145. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  11146. list_for_each_entry(childwq, &cq->child_list, list) {
  11147. if (childwq->queue_id == fcp_wqid) {
  11148. lpfc_sli4_wq_release(childwq,
  11149. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  11150. wqid_matched = true;
  11151. break;
  11152. }
  11153. }
  11154. /* Report warning log message if no match found */
  11155. if (wqid_matched != true)
  11156. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11157. "2580 Fast-path wqe consume event carries "
  11158. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  11159. }
  11160. /**
  11161. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  11162. * @cq: Pointer to the completion queue.
  11163. * @eqe: Pointer to fast-path completion queue entry.
  11164. *
  11165. * This routine process a fast-path work queue completion entry from fast-path
  11166. * event queue for FCP command response completion.
  11167. **/
  11168. static int
  11169. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11170. struct lpfc_cqe *cqe)
  11171. {
  11172. struct lpfc_wcqe_release wcqe;
  11173. bool workposted = false;
  11174. /* Copy the work queue CQE and convert endian order if needed */
  11175. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  11176. /* Check and process for different type of WCQE and dispatch */
  11177. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  11178. case CQE_CODE_COMPL_WQE:
  11179. cq->CQ_wq++;
  11180. /* Process the WQ complete event */
  11181. phba->last_completion_time = jiffies;
  11182. lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
  11183. (struct lpfc_wcqe_complete *)&wcqe);
  11184. break;
  11185. case CQE_CODE_RELEASE_WQE:
  11186. cq->CQ_release_wqe++;
  11187. /* Process the WQ release event */
  11188. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  11189. (struct lpfc_wcqe_release *)&wcqe);
  11190. break;
  11191. case CQE_CODE_XRI_ABORTED:
  11192. cq->CQ_xri_aborted++;
  11193. /* Process the WQ XRI abort event */
  11194. phba->last_completion_time = jiffies;
  11195. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  11196. (struct sli4_wcqe_xri_aborted *)&wcqe);
  11197. break;
  11198. default:
  11199. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11200. "0144 Not a valid WCQE code: x%x\n",
  11201. bf_get(lpfc_wcqe_c_code, &wcqe));
  11202. break;
  11203. }
  11204. return workposted;
  11205. }
  11206. /**
  11207. * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
  11208. * @phba: Pointer to HBA context object.
  11209. * @eqe: Pointer to fast-path event queue entry.
  11210. *
  11211. * This routine process a event queue entry from the fast-path event queue.
  11212. * It will check the MajorCode and MinorCode to determine this is for a
  11213. * completion event on a completion queue, if not, an error shall be logged
  11214. * and just return. Otherwise, it will get to the corresponding completion
  11215. * queue and process all the entries on the completion queue, rearm the
  11216. * completion queue, and then return.
  11217. **/
  11218. static void
  11219. lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  11220. uint32_t qidx)
  11221. {
  11222. struct lpfc_queue *cq;
  11223. struct lpfc_cqe *cqe;
  11224. bool workposted = false;
  11225. uint16_t cqid;
  11226. int ecount = 0;
  11227. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  11228. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11229. "0366 Not a valid completion "
  11230. "event: majorcode=x%x, minorcode=x%x\n",
  11231. bf_get_le32(lpfc_eqe_major_code, eqe),
  11232. bf_get_le32(lpfc_eqe_minor_code, eqe));
  11233. return;
  11234. }
  11235. /* Get the reference to the corresponding CQ */
  11236. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11237. /* Check if this is a Slow path event */
  11238. if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
  11239. lpfc_sli4_sp_handle_eqe(phba, eqe,
  11240. phba->sli4_hba.hba_eq[qidx]);
  11241. return;
  11242. }
  11243. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  11244. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11245. "3146 Fast-path completion queues "
  11246. "does not exist\n");
  11247. return;
  11248. }
  11249. cq = phba->sli4_hba.fcp_cq[qidx];
  11250. if (unlikely(!cq)) {
  11251. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11252. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11253. "0367 Fast-path completion queue "
  11254. "(%d) does not exist\n", qidx);
  11255. return;
  11256. }
  11257. if (unlikely(cqid != cq->queue_id)) {
  11258. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11259. "0368 Miss-matched fast-path completion "
  11260. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  11261. cqid, cq->queue_id);
  11262. return;
  11263. }
  11264. /* Process all the entries to the CQ */
  11265. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11266. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  11267. if (!(++ecount % cq->entry_repost))
  11268. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11269. }
  11270. /* Track the max number of CQEs processed in 1 EQ */
  11271. if (ecount > cq->CQ_max_cqe)
  11272. cq->CQ_max_cqe = ecount;
  11273. /* Catch the no cq entry condition */
  11274. if (unlikely(ecount == 0))
  11275. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11276. "0369 No entry from fast-path completion "
  11277. "queue fcpcqid=%d\n", cq->queue_id);
  11278. /* In any case, flash and re-arm the CQ */
  11279. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11280. /* wake up worker thread if there are works to be done */
  11281. if (workposted)
  11282. lpfc_worker_wake_up(phba);
  11283. }
  11284. static void
  11285. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11286. {
  11287. struct lpfc_eqe *eqe;
  11288. /* walk all the EQ entries and drop on the floor */
  11289. while ((eqe = lpfc_sli4_eq_get(eq)))
  11290. ;
  11291. /* Clear and re-arm the EQ */
  11292. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  11293. }
  11294. /**
  11295. * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
  11296. * entry
  11297. * @phba: Pointer to HBA context object.
  11298. * @eqe: Pointer to fast-path event queue entry.
  11299. *
  11300. * This routine process a event queue entry from the Flash Optimized Fabric
  11301. * event queue. It will check the MajorCode and MinorCode to determine this
  11302. * is for a completion event on a completion queue, if not, an error shall be
  11303. * logged and just return. Otherwise, it will get to the corresponding
  11304. * completion queue and process all the entries on the completion queue, rearm
  11305. * the completion queue, and then return.
  11306. **/
  11307. static void
  11308. lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  11309. {
  11310. struct lpfc_queue *cq;
  11311. struct lpfc_cqe *cqe;
  11312. bool workposted = false;
  11313. uint16_t cqid;
  11314. int ecount = 0;
  11315. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  11316. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11317. "9147 Not a valid completion "
  11318. "event: majorcode=x%x, minorcode=x%x\n",
  11319. bf_get_le32(lpfc_eqe_major_code, eqe),
  11320. bf_get_le32(lpfc_eqe_minor_code, eqe));
  11321. return;
  11322. }
  11323. /* Get the reference to the corresponding CQ */
  11324. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  11325. /* Next check for OAS */
  11326. cq = phba->sli4_hba.oas_cq;
  11327. if (unlikely(!cq)) {
  11328. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  11329. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11330. "9148 OAS completion queue "
  11331. "does not exist\n");
  11332. return;
  11333. }
  11334. if (unlikely(cqid != cq->queue_id)) {
  11335. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11336. "9149 Miss-matched fast-path compl "
  11337. "queue id: eqcqid=%d, fcpcqid=%d\n",
  11338. cqid, cq->queue_id);
  11339. return;
  11340. }
  11341. /* Process all the entries to the OAS CQ */
  11342. while ((cqe = lpfc_sli4_cq_get(cq))) {
  11343. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  11344. if (!(++ecount % cq->entry_repost))
  11345. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  11346. }
  11347. /* Track the max number of CQEs processed in 1 EQ */
  11348. if (ecount > cq->CQ_max_cqe)
  11349. cq->CQ_max_cqe = ecount;
  11350. /* Catch the no cq entry condition */
  11351. if (unlikely(ecount == 0))
  11352. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11353. "9153 No entry from fast-path completion "
  11354. "queue fcpcqid=%d\n", cq->queue_id);
  11355. /* In any case, flash and re-arm the CQ */
  11356. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  11357. /* wake up worker thread if there are works to be done */
  11358. if (workposted)
  11359. lpfc_worker_wake_up(phba);
  11360. }
  11361. /**
  11362. * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
  11363. * @irq: Interrupt number.
  11364. * @dev_id: The device context pointer.
  11365. *
  11366. * This function is directly called from the PCI layer as an interrupt
  11367. * service routine when device with SLI-4 interface spec is enabled with
  11368. * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
  11369. * IOCB ring event in the HBA. However, when the device is enabled with either
  11370. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  11371. * device-level interrupt handler. When the PCI slot is in error recovery
  11372. * or the HBA is undergoing initialization, the interrupt handler will not
  11373. * process the interrupt. The Flash Optimized Fabric ring event are handled in
  11374. * the intrrupt context. This function is called without any lock held.
  11375. * It gets the hbalock to access and update SLI data structures. Note that,
  11376. * the EQ to CQ are one-to-one map such that the EQ index is
  11377. * equal to that of CQ index.
  11378. *
  11379. * This function returns IRQ_HANDLED when interrupt is handled else it
  11380. * returns IRQ_NONE.
  11381. **/
  11382. irqreturn_t
  11383. lpfc_sli4_fof_intr_handler(int irq, void *dev_id)
  11384. {
  11385. struct lpfc_hba *phba;
  11386. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  11387. struct lpfc_queue *eq;
  11388. struct lpfc_eqe *eqe;
  11389. unsigned long iflag;
  11390. int ecount = 0;
  11391. /* Get the driver's phba structure from the dev_id */
  11392. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  11393. phba = fcp_eq_hdl->phba;
  11394. if (unlikely(!phba))
  11395. return IRQ_NONE;
  11396. /* Get to the EQ struct associated with this vector */
  11397. eq = phba->sli4_hba.fof_eq;
  11398. if (unlikely(!eq))
  11399. return IRQ_NONE;
  11400. /* Check device state for handling interrupt */
  11401. if (unlikely(lpfc_intr_state_check(phba))) {
  11402. eq->EQ_badstate++;
  11403. /* Check again for link_state with lock held */
  11404. spin_lock_irqsave(&phba->hbalock, iflag);
  11405. if (phba->link_state < LPFC_LINK_DOWN)
  11406. /* Flush, clear interrupt, and rearm the EQ */
  11407. lpfc_sli4_eq_flush(phba, eq);
  11408. spin_unlock_irqrestore(&phba->hbalock, iflag);
  11409. return IRQ_NONE;
  11410. }
  11411. /*
  11412. * Process all the event on FCP fast-path EQ
  11413. */
  11414. while ((eqe = lpfc_sli4_eq_get(eq))) {
  11415. lpfc_sli4_fof_handle_eqe(phba, eqe);
  11416. if (!(++ecount % eq->entry_repost))
  11417. lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM);
  11418. eq->EQ_processed++;
  11419. }
  11420. /* Track the max number of EQEs processed in 1 intr */
  11421. if (ecount > eq->EQ_max_eqe)
  11422. eq->EQ_max_eqe = ecount;
  11423. if (unlikely(ecount == 0)) {
  11424. eq->EQ_no_entry++;
  11425. if (phba->intr_type == MSIX)
  11426. /* MSI-X treated interrupt served as no EQ share INT */
  11427. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11428. "9145 MSI-X interrupt with no EQE\n");
  11429. else {
  11430. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11431. "9146 ISR interrupt with no EQE\n");
  11432. /* Non MSI-X treated on interrupt as EQ share INT */
  11433. return IRQ_NONE;
  11434. }
  11435. }
  11436. /* Always clear and re-arm the fast-path EQ */
  11437. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  11438. return IRQ_HANDLED;
  11439. }
  11440. /**
  11441. * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
  11442. * @irq: Interrupt number.
  11443. * @dev_id: The device context pointer.
  11444. *
  11445. * This function is directly called from the PCI layer as an interrupt
  11446. * service routine when device with SLI-4 interface spec is enabled with
  11447. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  11448. * ring event in the HBA. However, when the device is enabled with either
  11449. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  11450. * device-level interrupt handler. When the PCI slot is in error recovery
  11451. * or the HBA is undergoing initialization, the interrupt handler will not
  11452. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  11453. * the intrrupt context. This function is called without any lock held.
  11454. * It gets the hbalock to access and update SLI data structures. Note that,
  11455. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  11456. * equal to that of FCP CQ index.
  11457. *
  11458. * The link attention and ELS ring attention events are handled
  11459. * by the worker thread. The interrupt handler signals the worker thread
  11460. * and returns for these events. This function is called without any lock
  11461. * held. It gets the hbalock to access and update SLI data structures.
  11462. *
  11463. * This function returns IRQ_HANDLED when interrupt is handled else it
  11464. * returns IRQ_NONE.
  11465. **/
  11466. irqreturn_t
  11467. lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
  11468. {
  11469. struct lpfc_hba *phba;
  11470. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  11471. struct lpfc_queue *fpeq;
  11472. struct lpfc_eqe *eqe;
  11473. unsigned long iflag;
  11474. int ecount = 0;
  11475. int fcp_eqidx;
  11476. /* Get the driver's phba structure from the dev_id */
  11477. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  11478. phba = fcp_eq_hdl->phba;
  11479. fcp_eqidx = fcp_eq_hdl->idx;
  11480. if (unlikely(!phba))
  11481. return IRQ_NONE;
  11482. if (unlikely(!phba->sli4_hba.hba_eq))
  11483. return IRQ_NONE;
  11484. /* Get to the EQ struct associated with this vector */
  11485. fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11486. if (unlikely(!fpeq))
  11487. return IRQ_NONE;
  11488. if (lpfc_fcp_look_ahead) {
  11489. if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
  11490. lpfc_sli4_eq_clr_intr(fpeq);
  11491. else {
  11492. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11493. return IRQ_NONE;
  11494. }
  11495. }
  11496. /* Check device state for handling interrupt */
  11497. if (unlikely(lpfc_intr_state_check(phba))) {
  11498. fpeq->EQ_badstate++;
  11499. /* Check again for link_state with lock held */
  11500. spin_lock_irqsave(&phba->hbalock, iflag);
  11501. if (phba->link_state < LPFC_LINK_DOWN)
  11502. /* Flush, clear interrupt, and rearm the EQ */
  11503. lpfc_sli4_eq_flush(phba, fpeq);
  11504. spin_unlock_irqrestore(&phba->hbalock, iflag);
  11505. if (lpfc_fcp_look_ahead)
  11506. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11507. return IRQ_NONE;
  11508. }
  11509. /*
  11510. * Process all the event on FCP fast-path EQ
  11511. */
  11512. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  11513. if (eqe == NULL)
  11514. break;
  11515. lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
  11516. if (!(++ecount % fpeq->entry_repost))
  11517. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  11518. fpeq->EQ_processed++;
  11519. }
  11520. /* Track the max number of EQEs processed in 1 intr */
  11521. if (ecount > fpeq->EQ_max_eqe)
  11522. fpeq->EQ_max_eqe = ecount;
  11523. /* Always clear and re-arm the fast-path EQ */
  11524. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  11525. if (unlikely(ecount == 0)) {
  11526. fpeq->EQ_no_entry++;
  11527. if (lpfc_fcp_look_ahead) {
  11528. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11529. return IRQ_NONE;
  11530. }
  11531. if (phba->intr_type == MSIX)
  11532. /* MSI-X treated interrupt served as no EQ share INT */
  11533. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  11534. "0358 MSI-X interrupt with no EQE\n");
  11535. else
  11536. /* Non MSI-X treated on interrupt as EQ share INT */
  11537. return IRQ_NONE;
  11538. }
  11539. if (lpfc_fcp_look_ahead)
  11540. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  11541. return IRQ_HANDLED;
  11542. } /* lpfc_sli4_fp_intr_handler */
  11543. /**
  11544. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  11545. * @irq: Interrupt number.
  11546. * @dev_id: The device context pointer.
  11547. *
  11548. * This function is the device-level interrupt handler to device with SLI-4
  11549. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  11550. * interrupt mode is enabled and there is an event in the HBA which requires
  11551. * driver attention. This function invokes the slow-path interrupt attention
  11552. * handling function and fast-path interrupt attention handling function in
  11553. * turn to process the relevant HBA attention events. This function is called
  11554. * without any lock held. It gets the hbalock to access and update SLI data
  11555. * structures.
  11556. *
  11557. * This function returns IRQ_HANDLED when interrupt is handled, else it
  11558. * returns IRQ_NONE.
  11559. **/
  11560. irqreturn_t
  11561. lpfc_sli4_intr_handler(int irq, void *dev_id)
  11562. {
  11563. struct lpfc_hba *phba;
  11564. irqreturn_t hba_irq_rc;
  11565. bool hba_handled = false;
  11566. int fcp_eqidx;
  11567. /* Get the driver's phba structure from the dev_id */
  11568. phba = (struct lpfc_hba *)dev_id;
  11569. if (unlikely(!phba))
  11570. return IRQ_NONE;
  11571. /*
  11572. * Invoke fast-path host attention interrupt handling as appropriate.
  11573. */
  11574. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  11575. hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
  11576. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  11577. if (hba_irq_rc == IRQ_HANDLED)
  11578. hba_handled |= true;
  11579. }
  11580. if (phba->cfg_fof) {
  11581. hba_irq_rc = lpfc_sli4_fof_intr_handler(irq,
  11582. &phba->sli4_hba.fcp_eq_hdl[0]);
  11583. if (hba_irq_rc == IRQ_HANDLED)
  11584. hba_handled |= true;
  11585. }
  11586. return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
  11587. } /* lpfc_sli4_intr_handler */
  11588. /**
  11589. * lpfc_sli4_queue_free - free a queue structure and associated memory
  11590. * @queue: The queue structure to free.
  11591. *
  11592. * This function frees a queue structure and the DMAable memory used for
  11593. * the host resident queue. This function must be called after destroying the
  11594. * queue on the HBA.
  11595. **/
  11596. void
  11597. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  11598. {
  11599. struct lpfc_dmabuf *dmabuf;
  11600. if (!queue)
  11601. return;
  11602. while (!list_empty(&queue->page_list)) {
  11603. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  11604. list);
  11605. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  11606. dmabuf->virt, dmabuf->phys);
  11607. kfree(dmabuf);
  11608. }
  11609. kfree(queue);
  11610. return;
  11611. }
  11612. /**
  11613. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  11614. * @phba: The HBA that this queue is being created on.
  11615. * @entry_size: The size of each queue entry for this queue.
  11616. * @entry count: The number of entries that this queue will handle.
  11617. *
  11618. * This function allocates a queue structure and the DMAable memory used for
  11619. * the host resident queue. This function must be called before creating the
  11620. * queue on the HBA.
  11621. **/
  11622. struct lpfc_queue *
  11623. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  11624. uint32_t entry_count)
  11625. {
  11626. struct lpfc_queue *queue;
  11627. struct lpfc_dmabuf *dmabuf;
  11628. int x, total_qe_count;
  11629. void *dma_pointer;
  11630. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11631. if (!phba->sli4_hba.pc_sli4_params.supported)
  11632. hw_page_size = SLI4_PAGE_SIZE;
  11633. queue = kzalloc(sizeof(struct lpfc_queue) +
  11634. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  11635. if (!queue)
  11636. return NULL;
  11637. queue->page_count = (ALIGN(entry_size * entry_count,
  11638. hw_page_size))/hw_page_size;
  11639. INIT_LIST_HEAD(&queue->list);
  11640. INIT_LIST_HEAD(&queue->page_list);
  11641. INIT_LIST_HEAD(&queue->child_list);
  11642. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  11643. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  11644. if (!dmabuf)
  11645. goto out_fail;
  11646. dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
  11647. hw_page_size, &dmabuf->phys,
  11648. GFP_KERNEL);
  11649. if (!dmabuf->virt) {
  11650. kfree(dmabuf);
  11651. goto out_fail;
  11652. }
  11653. dmabuf->buffer_tag = x;
  11654. list_add_tail(&dmabuf->list, &queue->page_list);
  11655. /* initialize queue's entry array */
  11656. dma_pointer = dmabuf->virt;
  11657. for (; total_qe_count < entry_count &&
  11658. dma_pointer < (hw_page_size + dmabuf->virt);
  11659. total_qe_count++, dma_pointer += entry_size) {
  11660. queue->qe[total_qe_count].address = dma_pointer;
  11661. }
  11662. }
  11663. queue->entry_size = entry_size;
  11664. queue->entry_count = entry_count;
  11665. /*
  11666. * entry_repost is calculated based on the number of entries in the
  11667. * queue. This works out except for RQs. If buffers are NOT initially
  11668. * posted for every RQE, entry_repost should be adjusted accordingly.
  11669. */
  11670. queue->entry_repost = (entry_count >> 3);
  11671. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  11672. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  11673. queue->phba = phba;
  11674. return queue;
  11675. out_fail:
  11676. lpfc_sli4_queue_free(queue);
  11677. return NULL;
  11678. }
  11679. /**
  11680. * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
  11681. * @phba: HBA structure that indicates port to create a queue on.
  11682. * @pci_barset: PCI BAR set flag.
  11683. *
  11684. * This function shall perform iomap of the specified PCI BAR address to host
  11685. * memory address if not already done so and return it. The returned host
  11686. * memory address can be NULL.
  11687. */
  11688. static void __iomem *
  11689. lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
  11690. {
  11691. if (!phba->pcidev)
  11692. return NULL;
  11693. switch (pci_barset) {
  11694. case WQ_PCI_BAR_0_AND_1:
  11695. return phba->pci_bar0_memmap_p;
  11696. case WQ_PCI_BAR_2_AND_3:
  11697. return phba->pci_bar2_memmap_p;
  11698. case WQ_PCI_BAR_4_AND_5:
  11699. return phba->pci_bar4_memmap_p;
  11700. default:
  11701. break;
  11702. }
  11703. return NULL;
  11704. }
  11705. /**
  11706. * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
  11707. * @phba: HBA structure that indicates port to create a queue on.
  11708. * @startq: The starting FCP EQ to modify
  11709. *
  11710. * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
  11711. *
  11712. * The @phba struct is used to send mailbox command to HBA. The @startq
  11713. * is used to get the starting FCP EQ to change.
  11714. * This function is asynchronous and will wait for the mailbox
  11715. * command to finish before continuing.
  11716. *
  11717. * On success this function will return a zero. If unable to allocate enough
  11718. * memory this function will return -ENOMEM. If the queue create mailbox command
  11719. * fails this function will return -ENXIO.
  11720. **/
  11721. int
  11722. lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint32_t startq)
  11723. {
  11724. struct lpfc_mbx_modify_eq_delay *eq_delay;
  11725. LPFC_MBOXQ_t *mbox;
  11726. struct lpfc_queue *eq;
  11727. int cnt, rc, length, status = 0;
  11728. uint32_t shdr_status, shdr_add_status;
  11729. uint32_t result;
  11730. int fcp_eqidx;
  11731. union lpfc_sli4_cfg_shdr *shdr;
  11732. uint16_t dmult;
  11733. if (startq >= phba->cfg_fcp_io_channel)
  11734. return 0;
  11735. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11736. if (!mbox)
  11737. return -ENOMEM;
  11738. length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
  11739. sizeof(struct lpfc_sli4_cfg_mhdr));
  11740. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11741. LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
  11742. length, LPFC_SLI4_MBX_EMBED);
  11743. eq_delay = &mbox->u.mqe.un.eq_delay;
  11744. /* Calculate delay multiper from maximum interrupt per second */
  11745. result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
  11746. if (result > LPFC_DMULT_CONST)
  11747. dmult = 0;
  11748. else
  11749. dmult = LPFC_DMULT_CONST/result - 1;
  11750. cnt = 0;
  11751. for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
  11752. fcp_eqidx++) {
  11753. eq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11754. if (!eq)
  11755. continue;
  11756. eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
  11757. eq_delay->u.request.eq[cnt].phase = 0;
  11758. eq_delay->u.request.eq[cnt].delay_multi = dmult;
  11759. cnt++;
  11760. if (cnt >= LPFC_MAX_EQ_DELAY)
  11761. break;
  11762. }
  11763. eq_delay->u.request.num_eq = cnt;
  11764. mbox->vport = phba->pport;
  11765. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11766. mbox->context1 = NULL;
  11767. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11768. shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
  11769. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11770. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11771. if (shdr_status || shdr_add_status || rc) {
  11772. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11773. "2512 MODIFY_EQ_DELAY mailbox failed with "
  11774. "status x%x add_status x%x, mbx status x%x\n",
  11775. shdr_status, shdr_add_status, rc);
  11776. status = -ENXIO;
  11777. }
  11778. mempool_free(mbox, phba->mbox_mem_pool);
  11779. return status;
  11780. }
  11781. /**
  11782. * lpfc_eq_create - Create an Event Queue on the HBA
  11783. * @phba: HBA structure that indicates port to create a queue on.
  11784. * @eq: The queue structure to use to create the event queue.
  11785. * @imax: The maximum interrupt per second limit.
  11786. *
  11787. * This function creates an event queue, as detailed in @eq, on a port,
  11788. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  11789. *
  11790. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  11791. * is used to get the entry count and entry size that are necessary to
  11792. * determine the number of pages to allocate and use for this queue. This
  11793. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  11794. * event queue. This function is asynchronous and will wait for the mailbox
  11795. * command to finish before continuing.
  11796. *
  11797. * On success this function will return a zero. If unable to allocate enough
  11798. * memory this function will return -ENOMEM. If the queue create mailbox command
  11799. * fails this function will return -ENXIO.
  11800. **/
  11801. int
  11802. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
  11803. {
  11804. struct lpfc_mbx_eq_create *eq_create;
  11805. LPFC_MBOXQ_t *mbox;
  11806. int rc, length, status = 0;
  11807. struct lpfc_dmabuf *dmabuf;
  11808. uint32_t shdr_status, shdr_add_status;
  11809. union lpfc_sli4_cfg_shdr *shdr;
  11810. uint16_t dmult;
  11811. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11812. /* sanity check on queue memory */
  11813. if (!eq)
  11814. return -ENODEV;
  11815. if (!phba->sli4_hba.pc_sli4_params.supported)
  11816. hw_page_size = SLI4_PAGE_SIZE;
  11817. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11818. if (!mbox)
  11819. return -ENOMEM;
  11820. length = (sizeof(struct lpfc_mbx_eq_create) -
  11821. sizeof(struct lpfc_sli4_cfg_mhdr));
  11822. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11823. LPFC_MBOX_OPCODE_EQ_CREATE,
  11824. length, LPFC_SLI4_MBX_EMBED);
  11825. eq_create = &mbox->u.mqe.un.eq_create;
  11826. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11827. eq->page_count);
  11828. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11829. LPFC_EQE_SIZE);
  11830. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11831. /* don't setup delay multiplier using EQ_CREATE */
  11832. dmult = 0;
  11833. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11834. dmult);
  11835. switch (eq->entry_count) {
  11836. default:
  11837. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11838. "0360 Unsupported EQ count. (%d)\n",
  11839. eq->entry_count);
  11840. if (eq->entry_count < 256)
  11841. return -EINVAL;
  11842. /* otherwise default to smallest count (drop through) */
  11843. case 256:
  11844. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11845. LPFC_EQ_CNT_256);
  11846. break;
  11847. case 512:
  11848. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11849. LPFC_EQ_CNT_512);
  11850. break;
  11851. case 1024:
  11852. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11853. LPFC_EQ_CNT_1024);
  11854. break;
  11855. case 2048:
  11856. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11857. LPFC_EQ_CNT_2048);
  11858. break;
  11859. case 4096:
  11860. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11861. LPFC_EQ_CNT_4096);
  11862. break;
  11863. }
  11864. list_for_each_entry(dmabuf, &eq->page_list, list) {
  11865. memset(dmabuf->virt, 0, hw_page_size);
  11866. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11867. putPaddrLow(dmabuf->phys);
  11868. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11869. putPaddrHigh(dmabuf->phys);
  11870. }
  11871. mbox->vport = phba->pport;
  11872. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11873. mbox->context1 = NULL;
  11874. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11875. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  11876. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11877. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11878. if (shdr_status || shdr_add_status || rc) {
  11879. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11880. "2500 EQ_CREATE mailbox failed with "
  11881. "status x%x add_status x%x, mbx status x%x\n",
  11882. shdr_status, shdr_add_status, rc);
  11883. status = -ENXIO;
  11884. }
  11885. eq->type = LPFC_EQ;
  11886. eq->subtype = LPFC_NONE;
  11887. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  11888. if (eq->queue_id == 0xFFFF)
  11889. status = -ENXIO;
  11890. eq->host_index = 0;
  11891. eq->hba_index = 0;
  11892. mempool_free(mbox, phba->mbox_mem_pool);
  11893. return status;
  11894. }
  11895. /**
  11896. * lpfc_cq_create - Create a Completion Queue on the HBA
  11897. * @phba: HBA structure that indicates port to create a queue on.
  11898. * @cq: The queue structure to use to create the completion queue.
  11899. * @eq: The event queue to bind this completion queue to.
  11900. *
  11901. * This function creates a completion queue, as detailed in @wq, on a port,
  11902. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  11903. *
  11904. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11905. * is used to get the entry count and entry size that are necessary to
  11906. * determine the number of pages to allocate and use for this queue. The @eq
  11907. * is used to indicate which event queue to bind this completion queue to. This
  11908. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  11909. * completion queue. This function is asynchronous and will wait for the mailbox
  11910. * command to finish before continuing.
  11911. *
  11912. * On success this function will return a zero. If unable to allocate enough
  11913. * memory this function will return -ENOMEM. If the queue create mailbox command
  11914. * fails this function will return -ENXIO.
  11915. **/
  11916. int
  11917. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11918. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  11919. {
  11920. struct lpfc_mbx_cq_create *cq_create;
  11921. struct lpfc_dmabuf *dmabuf;
  11922. LPFC_MBOXQ_t *mbox;
  11923. int rc, length, status = 0;
  11924. uint32_t shdr_status, shdr_add_status;
  11925. union lpfc_sli4_cfg_shdr *shdr;
  11926. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11927. /* sanity check on queue memory */
  11928. if (!cq || !eq)
  11929. return -ENODEV;
  11930. if (!phba->sli4_hba.pc_sli4_params.supported)
  11931. hw_page_size = SLI4_PAGE_SIZE;
  11932. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11933. if (!mbox)
  11934. return -ENOMEM;
  11935. length = (sizeof(struct lpfc_mbx_cq_create) -
  11936. sizeof(struct lpfc_sli4_cfg_mhdr));
  11937. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11938. LPFC_MBOX_OPCODE_CQ_CREATE,
  11939. length, LPFC_SLI4_MBX_EMBED);
  11940. cq_create = &mbox->u.mqe.un.cq_create;
  11941. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  11942. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  11943. cq->page_count);
  11944. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  11945. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  11946. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11947. phba->sli4_hba.pc_sli4_params.cqv);
  11948. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  11949. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  11950. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  11951. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  11952. eq->queue_id);
  11953. } else {
  11954. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  11955. eq->queue_id);
  11956. }
  11957. switch (cq->entry_count) {
  11958. default:
  11959. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11960. "0361 Unsupported CQ count. (%d)\n",
  11961. cq->entry_count);
  11962. if (cq->entry_count < 256) {
  11963. status = -EINVAL;
  11964. goto out;
  11965. }
  11966. /* otherwise default to smallest count (drop through) */
  11967. case 256:
  11968. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11969. LPFC_CQ_CNT_256);
  11970. break;
  11971. case 512:
  11972. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11973. LPFC_CQ_CNT_512);
  11974. break;
  11975. case 1024:
  11976. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11977. LPFC_CQ_CNT_1024);
  11978. break;
  11979. }
  11980. list_for_each_entry(dmabuf, &cq->page_list, list) {
  11981. memset(dmabuf->virt, 0, hw_page_size);
  11982. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11983. putPaddrLow(dmabuf->phys);
  11984. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11985. putPaddrHigh(dmabuf->phys);
  11986. }
  11987. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11988. /* The IOCTL status is embedded in the mailbox subheader. */
  11989. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11990. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11991. if (shdr_status || shdr_add_status || rc) {
  11992. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11993. "2501 CQ_CREATE mailbox failed with "
  11994. "status x%x add_status x%x, mbx status x%x\n",
  11995. shdr_status, shdr_add_status, rc);
  11996. status = -ENXIO;
  11997. goto out;
  11998. }
  11999. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  12000. if (cq->queue_id == 0xFFFF) {
  12001. status = -ENXIO;
  12002. goto out;
  12003. }
  12004. /* link the cq onto the parent eq child list */
  12005. list_add_tail(&cq->list, &eq->child_list);
  12006. /* Set up completion queue's type and subtype */
  12007. cq->type = type;
  12008. cq->subtype = subtype;
  12009. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  12010. cq->assoc_qid = eq->queue_id;
  12011. cq->host_index = 0;
  12012. cq->hba_index = 0;
  12013. out:
  12014. mempool_free(mbox, phba->mbox_mem_pool);
  12015. return status;
  12016. }
  12017. /**
  12018. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  12019. * @phba: HBA structure that indicates port to create a queue on.
  12020. * @mq: The queue structure to use to create the mailbox queue.
  12021. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  12022. * @cq: The completion queue to associate with this cq.
  12023. *
  12024. * This function provides failback (fb) functionality when the
  12025. * mq_create_ext fails on older FW generations. It's purpose is identical
  12026. * to mq_create_ext otherwise.
  12027. *
  12028. * This routine cannot fail as all attributes were previously accessed and
  12029. * initialized in mq_create_ext.
  12030. **/
  12031. static void
  12032. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  12033. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  12034. {
  12035. struct lpfc_mbx_mq_create *mq_create;
  12036. struct lpfc_dmabuf *dmabuf;
  12037. int length;
  12038. length = (sizeof(struct lpfc_mbx_mq_create) -
  12039. sizeof(struct lpfc_sli4_cfg_mhdr));
  12040. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12041. LPFC_MBOX_OPCODE_MQ_CREATE,
  12042. length, LPFC_SLI4_MBX_EMBED);
  12043. mq_create = &mbox->u.mqe.un.mq_create;
  12044. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  12045. mq->page_count);
  12046. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  12047. cq->queue_id);
  12048. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  12049. switch (mq->entry_count) {
  12050. case 16:
  12051. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12052. LPFC_MQ_RING_SIZE_16);
  12053. break;
  12054. case 32:
  12055. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12056. LPFC_MQ_RING_SIZE_32);
  12057. break;
  12058. case 64:
  12059. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12060. LPFC_MQ_RING_SIZE_64);
  12061. break;
  12062. case 128:
  12063. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  12064. LPFC_MQ_RING_SIZE_128);
  12065. break;
  12066. }
  12067. list_for_each_entry(dmabuf, &mq->page_list, list) {
  12068. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12069. putPaddrLow(dmabuf->phys);
  12070. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12071. putPaddrHigh(dmabuf->phys);
  12072. }
  12073. }
  12074. /**
  12075. * lpfc_mq_create - Create a mailbox Queue on the HBA
  12076. * @phba: HBA structure that indicates port to create a queue on.
  12077. * @mq: The queue structure to use to create the mailbox queue.
  12078. * @cq: The completion queue to associate with this cq.
  12079. * @subtype: The queue's subtype.
  12080. *
  12081. * This function creates a mailbox queue, as detailed in @mq, on a port,
  12082. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  12083. *
  12084. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  12085. * is used to get the entry count and entry size that are necessary to
  12086. * determine the number of pages to allocate and use for this queue. This
  12087. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  12088. * mailbox queue. This function is asynchronous and will wait for the mailbox
  12089. * command to finish before continuing.
  12090. *
  12091. * On success this function will return a zero. If unable to allocate enough
  12092. * memory this function will return -ENOMEM. If the queue create mailbox command
  12093. * fails this function will return -ENXIO.
  12094. **/
  12095. int32_t
  12096. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  12097. struct lpfc_queue *cq, uint32_t subtype)
  12098. {
  12099. struct lpfc_mbx_mq_create *mq_create;
  12100. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  12101. struct lpfc_dmabuf *dmabuf;
  12102. LPFC_MBOXQ_t *mbox;
  12103. int rc, length, status = 0;
  12104. uint32_t shdr_status, shdr_add_status;
  12105. union lpfc_sli4_cfg_shdr *shdr;
  12106. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12107. /* sanity check on queue memory */
  12108. if (!mq || !cq)
  12109. return -ENODEV;
  12110. if (!phba->sli4_hba.pc_sli4_params.supported)
  12111. hw_page_size = SLI4_PAGE_SIZE;
  12112. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12113. if (!mbox)
  12114. return -ENOMEM;
  12115. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  12116. sizeof(struct lpfc_sli4_cfg_mhdr));
  12117. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12118. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  12119. length, LPFC_SLI4_MBX_EMBED);
  12120. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  12121. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  12122. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  12123. &mq_create_ext->u.request, mq->page_count);
  12124. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  12125. &mq_create_ext->u.request, 1);
  12126. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  12127. &mq_create_ext->u.request, 1);
  12128. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  12129. &mq_create_ext->u.request, 1);
  12130. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  12131. &mq_create_ext->u.request, 1);
  12132. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  12133. &mq_create_ext->u.request, 1);
  12134. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  12135. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12136. phba->sli4_hba.pc_sli4_params.mqv);
  12137. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  12138. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  12139. cq->queue_id);
  12140. else
  12141. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  12142. cq->queue_id);
  12143. switch (mq->entry_count) {
  12144. default:
  12145. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12146. "0362 Unsupported MQ count. (%d)\n",
  12147. mq->entry_count);
  12148. if (mq->entry_count < 16) {
  12149. status = -EINVAL;
  12150. goto out;
  12151. }
  12152. /* otherwise default to smallest count (drop through) */
  12153. case 16:
  12154. bf_set(lpfc_mq_context_ring_size,
  12155. &mq_create_ext->u.request.context,
  12156. LPFC_MQ_RING_SIZE_16);
  12157. break;
  12158. case 32:
  12159. bf_set(lpfc_mq_context_ring_size,
  12160. &mq_create_ext->u.request.context,
  12161. LPFC_MQ_RING_SIZE_32);
  12162. break;
  12163. case 64:
  12164. bf_set(lpfc_mq_context_ring_size,
  12165. &mq_create_ext->u.request.context,
  12166. LPFC_MQ_RING_SIZE_64);
  12167. break;
  12168. case 128:
  12169. bf_set(lpfc_mq_context_ring_size,
  12170. &mq_create_ext->u.request.context,
  12171. LPFC_MQ_RING_SIZE_128);
  12172. break;
  12173. }
  12174. list_for_each_entry(dmabuf, &mq->page_list, list) {
  12175. memset(dmabuf->virt, 0, hw_page_size);
  12176. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  12177. putPaddrLow(dmabuf->phys);
  12178. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  12179. putPaddrHigh(dmabuf->phys);
  12180. }
  12181. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12182. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  12183. &mq_create_ext->u.response);
  12184. if (rc != MBX_SUCCESS) {
  12185. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12186. "2795 MQ_CREATE_EXT failed with "
  12187. "status x%x. Failback to MQ_CREATE.\n",
  12188. rc);
  12189. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  12190. mq_create = &mbox->u.mqe.un.mq_create;
  12191. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12192. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  12193. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  12194. &mq_create->u.response);
  12195. }
  12196. /* The IOCTL status is embedded in the mailbox subheader. */
  12197. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12198. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12199. if (shdr_status || shdr_add_status || rc) {
  12200. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12201. "2502 MQ_CREATE mailbox failed with "
  12202. "status x%x add_status x%x, mbx status x%x\n",
  12203. shdr_status, shdr_add_status, rc);
  12204. status = -ENXIO;
  12205. goto out;
  12206. }
  12207. if (mq->queue_id == 0xFFFF) {
  12208. status = -ENXIO;
  12209. goto out;
  12210. }
  12211. mq->type = LPFC_MQ;
  12212. mq->assoc_qid = cq->queue_id;
  12213. mq->subtype = subtype;
  12214. mq->host_index = 0;
  12215. mq->hba_index = 0;
  12216. /* link the mq onto the parent cq child list */
  12217. list_add_tail(&mq->list, &cq->child_list);
  12218. out:
  12219. mempool_free(mbox, phba->mbox_mem_pool);
  12220. return status;
  12221. }
  12222. /**
  12223. * lpfc_wq_create - Create a Work Queue on the HBA
  12224. * @phba: HBA structure that indicates port to create a queue on.
  12225. * @wq: The queue structure to use to create the work queue.
  12226. * @cq: The completion queue to bind this work queue to.
  12227. * @subtype: The subtype of the work queue indicating its functionality.
  12228. *
  12229. * This function creates a work queue, as detailed in @wq, on a port, described
  12230. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  12231. *
  12232. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  12233. * is used to get the entry count and entry size that are necessary to
  12234. * determine the number of pages to allocate and use for this queue. The @cq
  12235. * is used to indicate which completion queue to bind this work queue to. This
  12236. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  12237. * work queue. This function is asynchronous and will wait for the mailbox
  12238. * command to finish before continuing.
  12239. *
  12240. * On success this function will return a zero. If unable to allocate enough
  12241. * memory this function will return -ENOMEM. If the queue create mailbox command
  12242. * fails this function will return -ENXIO.
  12243. **/
  12244. int
  12245. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  12246. struct lpfc_queue *cq, uint32_t subtype)
  12247. {
  12248. struct lpfc_mbx_wq_create *wq_create;
  12249. struct lpfc_dmabuf *dmabuf;
  12250. LPFC_MBOXQ_t *mbox;
  12251. int rc, length, status = 0;
  12252. uint32_t shdr_status, shdr_add_status;
  12253. union lpfc_sli4_cfg_shdr *shdr;
  12254. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12255. struct dma_address *page;
  12256. void __iomem *bar_memmap_p;
  12257. uint32_t db_offset;
  12258. uint16_t pci_barset;
  12259. /* sanity check on queue memory */
  12260. if (!wq || !cq)
  12261. return -ENODEV;
  12262. if (!phba->sli4_hba.pc_sli4_params.supported)
  12263. hw_page_size = SLI4_PAGE_SIZE;
  12264. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12265. if (!mbox)
  12266. return -ENOMEM;
  12267. length = (sizeof(struct lpfc_mbx_wq_create) -
  12268. sizeof(struct lpfc_sli4_cfg_mhdr));
  12269. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12270. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  12271. length, LPFC_SLI4_MBX_EMBED);
  12272. wq_create = &mbox->u.mqe.un.wq_create;
  12273. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  12274. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  12275. wq->page_count);
  12276. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  12277. cq->queue_id);
  12278. /* wqv is the earliest version supported, NOT the latest */
  12279. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12280. phba->sli4_hba.pc_sli4_params.wqv);
  12281. switch (phba->sli4_hba.pc_sli4_params.wqv) {
  12282. case LPFC_Q_CREATE_VERSION_0:
  12283. switch (wq->entry_size) {
  12284. default:
  12285. case 64:
  12286. /* Nothing to do, version 0 ONLY supports 64 byte */
  12287. page = wq_create->u.request.page;
  12288. break;
  12289. case 128:
  12290. if (!(phba->sli4_hba.pc_sli4_params.wqsize &
  12291. LPFC_WQ_SZ128_SUPPORT)) {
  12292. status = -ERANGE;
  12293. goto out;
  12294. }
  12295. /* If we get here the HBA MUST also support V1 and
  12296. * we MUST use it
  12297. */
  12298. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12299. LPFC_Q_CREATE_VERSION_1);
  12300. bf_set(lpfc_mbx_wq_create_wqe_count,
  12301. &wq_create->u.request_1, wq->entry_count);
  12302. bf_set(lpfc_mbx_wq_create_wqe_size,
  12303. &wq_create->u.request_1,
  12304. LPFC_WQ_WQE_SIZE_128);
  12305. bf_set(lpfc_mbx_wq_create_page_size,
  12306. &wq_create->u.request_1,
  12307. LPFC_WQ_PAGE_SIZE_4096);
  12308. page = wq_create->u.request_1.page;
  12309. break;
  12310. }
  12311. break;
  12312. case LPFC_Q_CREATE_VERSION_1:
  12313. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  12314. wq->entry_count);
  12315. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12316. LPFC_Q_CREATE_VERSION_1);
  12317. switch (wq->entry_size) {
  12318. default:
  12319. case 64:
  12320. bf_set(lpfc_mbx_wq_create_wqe_size,
  12321. &wq_create->u.request_1,
  12322. LPFC_WQ_WQE_SIZE_64);
  12323. break;
  12324. case 128:
  12325. if (!(phba->sli4_hba.pc_sli4_params.wqsize &
  12326. LPFC_WQ_SZ128_SUPPORT)) {
  12327. status = -ERANGE;
  12328. goto out;
  12329. }
  12330. bf_set(lpfc_mbx_wq_create_wqe_size,
  12331. &wq_create->u.request_1,
  12332. LPFC_WQ_WQE_SIZE_128);
  12333. break;
  12334. }
  12335. bf_set(lpfc_mbx_wq_create_page_size,
  12336. &wq_create->u.request_1,
  12337. LPFC_WQ_PAGE_SIZE_4096);
  12338. page = wq_create->u.request_1.page;
  12339. break;
  12340. default:
  12341. status = -ERANGE;
  12342. goto out;
  12343. }
  12344. list_for_each_entry(dmabuf, &wq->page_list, list) {
  12345. memset(dmabuf->virt, 0, hw_page_size);
  12346. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  12347. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  12348. }
  12349. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12350. bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
  12351. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  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. "2503 WQ_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. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  12364. if (wq->queue_id == 0xFFFF) {
  12365. status = -ENXIO;
  12366. goto out;
  12367. }
  12368. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  12369. wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
  12370. &wq_create->u.response);
  12371. if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
  12372. (wq->db_format != LPFC_DB_RING_FORMAT)) {
  12373. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12374. "3265 WQ[%d] doorbell format not "
  12375. "supported: x%x\n", wq->queue_id,
  12376. wq->db_format);
  12377. status = -EINVAL;
  12378. goto out;
  12379. }
  12380. pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
  12381. &wq_create->u.response);
  12382. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  12383. if (!bar_memmap_p) {
  12384. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12385. "3263 WQ[%d] failed to memmap pci "
  12386. "barset:x%x\n", wq->queue_id,
  12387. pci_barset);
  12388. status = -ENOMEM;
  12389. goto out;
  12390. }
  12391. db_offset = wq_create->u.response.doorbell_offset;
  12392. if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
  12393. (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
  12394. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12395. "3252 WQ[%d] doorbell offset not "
  12396. "supported: x%x\n", wq->queue_id,
  12397. db_offset);
  12398. status = -EINVAL;
  12399. goto out;
  12400. }
  12401. wq->db_regaddr = bar_memmap_p + db_offset;
  12402. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12403. "3264 WQ[%d]: barset:x%x, offset:x%x, "
  12404. "format:x%x\n", wq->queue_id, pci_barset,
  12405. db_offset, wq->db_format);
  12406. } else {
  12407. wq->db_format = LPFC_DB_LIST_FORMAT;
  12408. wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
  12409. }
  12410. wq->type = LPFC_WQ;
  12411. wq->assoc_qid = cq->queue_id;
  12412. wq->subtype = subtype;
  12413. wq->host_index = 0;
  12414. wq->hba_index = 0;
  12415. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  12416. /* link the wq onto the parent cq child list */
  12417. list_add_tail(&wq->list, &cq->child_list);
  12418. out:
  12419. mempool_free(mbox, phba->mbox_mem_pool);
  12420. return status;
  12421. }
  12422. /**
  12423. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  12424. * @phba: HBA structure that indicates port to create a queue on.
  12425. * @rq: The queue structure to use for the receive queue.
  12426. * @qno: The associated HBQ number
  12427. *
  12428. *
  12429. * For SLI4 we need to adjust the RQ repost value based on
  12430. * the number of buffers that are initially posted to the RQ.
  12431. */
  12432. void
  12433. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  12434. {
  12435. uint32_t cnt;
  12436. /* sanity check on queue memory */
  12437. if (!rq)
  12438. return;
  12439. cnt = lpfc_hbq_defs[qno]->entry_count;
  12440. /* Recalc repost for RQs based on buffers initially posted */
  12441. cnt = (cnt >> 3);
  12442. if (cnt < LPFC_QUEUE_MIN_REPOST)
  12443. cnt = LPFC_QUEUE_MIN_REPOST;
  12444. rq->entry_repost = cnt;
  12445. }
  12446. /**
  12447. * lpfc_rq_create - Create a Receive Queue on the HBA
  12448. * @phba: HBA structure that indicates port to create a queue on.
  12449. * @hrq: The queue structure to use to create the header receive queue.
  12450. * @drq: The queue structure to use to create the data receive queue.
  12451. * @cq: The completion queue to bind this work queue to.
  12452. *
  12453. * This function creates a receive buffer queue pair , as detailed in @hrq and
  12454. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  12455. * to the HBA.
  12456. *
  12457. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  12458. * struct is used to get the entry count that is necessary to determine the
  12459. * number of pages to use for this queue. The @cq is used to indicate which
  12460. * completion queue to bind received buffers that are posted to these queues to.
  12461. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  12462. * receive queue pair. This function is asynchronous and will wait for the
  12463. * mailbox command to finish before continuing.
  12464. *
  12465. * On success this function will return a zero. If unable to allocate enough
  12466. * memory this function will return -ENOMEM. If the queue create mailbox command
  12467. * fails this function will return -ENXIO.
  12468. **/
  12469. int
  12470. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  12471. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  12472. {
  12473. struct lpfc_mbx_rq_create *rq_create;
  12474. struct lpfc_dmabuf *dmabuf;
  12475. LPFC_MBOXQ_t *mbox;
  12476. int rc, length, status = 0;
  12477. uint32_t shdr_status, shdr_add_status;
  12478. union lpfc_sli4_cfg_shdr *shdr;
  12479. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  12480. void __iomem *bar_memmap_p;
  12481. uint32_t db_offset;
  12482. uint16_t pci_barset;
  12483. /* sanity check on queue memory */
  12484. if (!hrq || !drq || !cq)
  12485. return -ENODEV;
  12486. if (!phba->sli4_hba.pc_sli4_params.supported)
  12487. hw_page_size = SLI4_PAGE_SIZE;
  12488. if (hrq->entry_count != drq->entry_count)
  12489. return -EINVAL;
  12490. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12491. if (!mbox)
  12492. return -ENOMEM;
  12493. length = (sizeof(struct lpfc_mbx_rq_create) -
  12494. sizeof(struct lpfc_sli4_cfg_mhdr));
  12495. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12496. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12497. length, LPFC_SLI4_MBX_EMBED);
  12498. rq_create = &mbox->u.mqe.un.rq_create;
  12499. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12500. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12501. phba->sli4_hba.pc_sli4_params.rqv);
  12502. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12503. bf_set(lpfc_rq_context_rqe_count_1,
  12504. &rq_create->u.request.context,
  12505. hrq->entry_count);
  12506. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  12507. bf_set(lpfc_rq_context_rqe_size,
  12508. &rq_create->u.request.context,
  12509. LPFC_RQE_SIZE_8);
  12510. bf_set(lpfc_rq_context_page_size,
  12511. &rq_create->u.request.context,
  12512. LPFC_RQ_PAGE_SIZE_4096);
  12513. } else {
  12514. switch (hrq->entry_count) {
  12515. default:
  12516. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12517. "2535 Unsupported RQ count. (%d)\n",
  12518. hrq->entry_count);
  12519. if (hrq->entry_count < 512) {
  12520. status = -EINVAL;
  12521. goto out;
  12522. }
  12523. /* otherwise default to smallest count (drop through) */
  12524. case 512:
  12525. bf_set(lpfc_rq_context_rqe_count,
  12526. &rq_create->u.request.context,
  12527. LPFC_RQ_RING_SIZE_512);
  12528. break;
  12529. case 1024:
  12530. bf_set(lpfc_rq_context_rqe_count,
  12531. &rq_create->u.request.context,
  12532. LPFC_RQ_RING_SIZE_1024);
  12533. break;
  12534. case 2048:
  12535. bf_set(lpfc_rq_context_rqe_count,
  12536. &rq_create->u.request.context,
  12537. LPFC_RQ_RING_SIZE_2048);
  12538. break;
  12539. case 4096:
  12540. bf_set(lpfc_rq_context_rqe_count,
  12541. &rq_create->u.request.context,
  12542. LPFC_RQ_RING_SIZE_4096);
  12543. break;
  12544. }
  12545. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12546. LPFC_HDR_BUF_SIZE);
  12547. }
  12548. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12549. cq->queue_id);
  12550. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12551. hrq->page_count);
  12552. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  12553. memset(dmabuf->virt, 0, hw_page_size);
  12554. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12555. putPaddrLow(dmabuf->phys);
  12556. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12557. putPaddrHigh(dmabuf->phys);
  12558. }
  12559. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12560. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12561. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12562. /* The IOCTL status is embedded in the mailbox subheader. */
  12563. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12564. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12565. if (shdr_status || shdr_add_status || rc) {
  12566. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12567. "2504 RQ_CREATE mailbox failed with "
  12568. "status x%x add_status x%x, mbx status x%x\n",
  12569. shdr_status, shdr_add_status, rc);
  12570. status = -ENXIO;
  12571. goto out;
  12572. }
  12573. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12574. if (hrq->queue_id == 0xFFFF) {
  12575. status = -ENXIO;
  12576. goto out;
  12577. }
  12578. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  12579. hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
  12580. &rq_create->u.response);
  12581. if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
  12582. (hrq->db_format != LPFC_DB_RING_FORMAT)) {
  12583. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12584. "3262 RQ [%d] doorbell format not "
  12585. "supported: x%x\n", hrq->queue_id,
  12586. hrq->db_format);
  12587. status = -EINVAL;
  12588. goto out;
  12589. }
  12590. pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
  12591. &rq_create->u.response);
  12592. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  12593. if (!bar_memmap_p) {
  12594. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12595. "3269 RQ[%d] failed to memmap pci "
  12596. "barset:x%x\n", hrq->queue_id,
  12597. pci_barset);
  12598. status = -ENOMEM;
  12599. goto out;
  12600. }
  12601. db_offset = rq_create->u.response.doorbell_offset;
  12602. if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
  12603. (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
  12604. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12605. "3270 RQ[%d] doorbell offset not "
  12606. "supported: x%x\n", hrq->queue_id,
  12607. db_offset);
  12608. status = -EINVAL;
  12609. goto out;
  12610. }
  12611. hrq->db_regaddr = bar_memmap_p + db_offset;
  12612. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12613. "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
  12614. "format:x%x\n", hrq->queue_id, pci_barset,
  12615. db_offset, hrq->db_format);
  12616. } else {
  12617. hrq->db_format = LPFC_DB_RING_FORMAT;
  12618. hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  12619. }
  12620. hrq->type = LPFC_HRQ;
  12621. hrq->assoc_qid = cq->queue_id;
  12622. hrq->subtype = subtype;
  12623. hrq->host_index = 0;
  12624. hrq->hba_index = 0;
  12625. /* now create the data queue */
  12626. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12627. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12628. length, LPFC_SLI4_MBX_EMBED);
  12629. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12630. phba->sli4_hba.pc_sli4_params.rqv);
  12631. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12632. bf_set(lpfc_rq_context_rqe_count_1,
  12633. &rq_create->u.request.context, hrq->entry_count);
  12634. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  12635. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  12636. LPFC_RQE_SIZE_8);
  12637. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  12638. (PAGE_SIZE/SLI4_PAGE_SIZE));
  12639. } else {
  12640. switch (drq->entry_count) {
  12641. default:
  12642. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12643. "2536 Unsupported RQ count. (%d)\n",
  12644. drq->entry_count);
  12645. if (drq->entry_count < 512) {
  12646. status = -EINVAL;
  12647. goto out;
  12648. }
  12649. /* otherwise default to smallest count (drop through) */
  12650. case 512:
  12651. bf_set(lpfc_rq_context_rqe_count,
  12652. &rq_create->u.request.context,
  12653. LPFC_RQ_RING_SIZE_512);
  12654. break;
  12655. case 1024:
  12656. bf_set(lpfc_rq_context_rqe_count,
  12657. &rq_create->u.request.context,
  12658. LPFC_RQ_RING_SIZE_1024);
  12659. break;
  12660. case 2048:
  12661. bf_set(lpfc_rq_context_rqe_count,
  12662. &rq_create->u.request.context,
  12663. LPFC_RQ_RING_SIZE_2048);
  12664. break;
  12665. case 4096:
  12666. bf_set(lpfc_rq_context_rqe_count,
  12667. &rq_create->u.request.context,
  12668. LPFC_RQ_RING_SIZE_4096);
  12669. break;
  12670. }
  12671. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12672. LPFC_DATA_BUF_SIZE);
  12673. }
  12674. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12675. cq->queue_id);
  12676. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12677. drq->page_count);
  12678. list_for_each_entry(dmabuf, &drq->page_list, list) {
  12679. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12680. putPaddrLow(dmabuf->phys);
  12681. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12682. putPaddrHigh(dmabuf->phys);
  12683. }
  12684. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12685. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12686. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12687. /* The IOCTL status is embedded in the mailbox subheader. */
  12688. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12689. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12690. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12691. if (shdr_status || shdr_add_status || rc) {
  12692. status = -ENXIO;
  12693. goto out;
  12694. }
  12695. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12696. if (drq->queue_id == 0xFFFF) {
  12697. status = -ENXIO;
  12698. goto out;
  12699. }
  12700. drq->type = LPFC_DRQ;
  12701. drq->assoc_qid = cq->queue_id;
  12702. drq->subtype = subtype;
  12703. drq->host_index = 0;
  12704. drq->hba_index = 0;
  12705. /* link the header and data RQs onto the parent cq child list */
  12706. list_add_tail(&hrq->list, &cq->child_list);
  12707. list_add_tail(&drq->list, &cq->child_list);
  12708. out:
  12709. mempool_free(mbox, phba->mbox_mem_pool);
  12710. return status;
  12711. }
  12712. /**
  12713. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  12714. * @eq: The queue structure associated with the queue to destroy.
  12715. *
  12716. * This function destroys a queue, as detailed in @eq by sending an mailbox
  12717. * command, specific to the type of queue, to the HBA.
  12718. *
  12719. * The @eq struct is used to get the queue ID of the queue to destroy.
  12720. *
  12721. * On success this function will return a zero. If the queue destroy mailbox
  12722. * command fails this function will return -ENXIO.
  12723. **/
  12724. int
  12725. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  12726. {
  12727. LPFC_MBOXQ_t *mbox;
  12728. int rc, length, status = 0;
  12729. uint32_t shdr_status, shdr_add_status;
  12730. union lpfc_sli4_cfg_shdr *shdr;
  12731. /* sanity check on queue memory */
  12732. if (!eq)
  12733. return -ENODEV;
  12734. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  12735. if (!mbox)
  12736. return -ENOMEM;
  12737. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  12738. sizeof(struct lpfc_sli4_cfg_mhdr));
  12739. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12740. LPFC_MBOX_OPCODE_EQ_DESTROY,
  12741. length, LPFC_SLI4_MBX_EMBED);
  12742. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  12743. eq->queue_id);
  12744. mbox->vport = eq->phba->pport;
  12745. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12746. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  12747. /* The IOCTL status is embedded in the mailbox subheader. */
  12748. shdr = (union lpfc_sli4_cfg_shdr *)
  12749. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  12750. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12751. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12752. if (shdr_status || shdr_add_status || rc) {
  12753. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12754. "2505 EQ_DESTROY mailbox failed with "
  12755. "status x%x add_status x%x, mbx status x%x\n",
  12756. shdr_status, shdr_add_status, rc);
  12757. status = -ENXIO;
  12758. }
  12759. /* Remove eq from any list */
  12760. list_del_init(&eq->list);
  12761. mempool_free(mbox, eq->phba->mbox_mem_pool);
  12762. return status;
  12763. }
  12764. /**
  12765. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  12766. * @cq: The queue structure associated with the queue to destroy.
  12767. *
  12768. * This function destroys a queue, as detailed in @cq by sending an mailbox
  12769. * command, specific to the type of queue, to the HBA.
  12770. *
  12771. * The @cq struct is used to get the queue ID of the queue to destroy.
  12772. *
  12773. * On success this function will return a zero. If the queue destroy mailbox
  12774. * command fails this function will return -ENXIO.
  12775. **/
  12776. int
  12777. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  12778. {
  12779. LPFC_MBOXQ_t *mbox;
  12780. int rc, length, status = 0;
  12781. uint32_t shdr_status, shdr_add_status;
  12782. union lpfc_sli4_cfg_shdr *shdr;
  12783. /* sanity check on queue memory */
  12784. if (!cq)
  12785. return -ENODEV;
  12786. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  12787. if (!mbox)
  12788. return -ENOMEM;
  12789. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  12790. sizeof(struct lpfc_sli4_cfg_mhdr));
  12791. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12792. LPFC_MBOX_OPCODE_CQ_DESTROY,
  12793. length, LPFC_SLI4_MBX_EMBED);
  12794. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  12795. cq->queue_id);
  12796. mbox->vport = cq->phba->pport;
  12797. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12798. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  12799. /* The IOCTL status is embedded in the mailbox subheader. */
  12800. shdr = (union lpfc_sli4_cfg_shdr *)
  12801. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  12802. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12803. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12804. if (shdr_status || shdr_add_status || rc) {
  12805. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12806. "2506 CQ_DESTROY mailbox failed with "
  12807. "status x%x add_status x%x, mbx status x%x\n",
  12808. shdr_status, shdr_add_status, rc);
  12809. status = -ENXIO;
  12810. }
  12811. /* Remove cq from any list */
  12812. list_del_init(&cq->list);
  12813. mempool_free(mbox, cq->phba->mbox_mem_pool);
  12814. return status;
  12815. }
  12816. /**
  12817. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  12818. * @qm: The queue structure associated with the queue to destroy.
  12819. *
  12820. * This function destroys a queue, as detailed in @mq by sending an mailbox
  12821. * command, specific to the type of queue, to the HBA.
  12822. *
  12823. * The @mq struct is used to get the queue ID of the queue to destroy.
  12824. *
  12825. * On success this function will return a zero. If the queue destroy mailbox
  12826. * command fails this function will return -ENXIO.
  12827. **/
  12828. int
  12829. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  12830. {
  12831. LPFC_MBOXQ_t *mbox;
  12832. int rc, length, status = 0;
  12833. uint32_t shdr_status, shdr_add_status;
  12834. union lpfc_sli4_cfg_shdr *shdr;
  12835. /* sanity check on queue memory */
  12836. if (!mq)
  12837. return -ENODEV;
  12838. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  12839. if (!mbox)
  12840. return -ENOMEM;
  12841. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  12842. sizeof(struct lpfc_sli4_cfg_mhdr));
  12843. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12844. LPFC_MBOX_OPCODE_MQ_DESTROY,
  12845. length, LPFC_SLI4_MBX_EMBED);
  12846. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  12847. mq->queue_id);
  12848. mbox->vport = mq->phba->pport;
  12849. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12850. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  12851. /* The IOCTL status is embedded in the mailbox subheader. */
  12852. shdr = (union lpfc_sli4_cfg_shdr *)
  12853. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  12854. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12855. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12856. if (shdr_status || shdr_add_status || rc) {
  12857. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12858. "2507 MQ_DESTROY mailbox failed with "
  12859. "status x%x add_status x%x, mbx status x%x\n",
  12860. shdr_status, shdr_add_status, rc);
  12861. status = -ENXIO;
  12862. }
  12863. /* Remove mq from any list */
  12864. list_del_init(&mq->list);
  12865. mempool_free(mbox, mq->phba->mbox_mem_pool);
  12866. return status;
  12867. }
  12868. /**
  12869. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  12870. * @wq: The queue structure associated with the queue to destroy.
  12871. *
  12872. * This function destroys a queue, as detailed in @wq by sending an mailbox
  12873. * command, specific to the type of queue, to the HBA.
  12874. *
  12875. * The @wq 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_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  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 (!wq)
  12889. return -ENODEV;
  12890. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  12891. if (!mbox)
  12892. return -ENOMEM;
  12893. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  12894. sizeof(struct lpfc_sli4_cfg_mhdr));
  12895. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12896. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  12897. length, LPFC_SLI4_MBX_EMBED);
  12898. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  12899. wq->queue_id);
  12900. mbox->vport = wq->phba->pport;
  12901. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12902. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  12903. shdr = (union lpfc_sli4_cfg_shdr *)
  12904. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  12905. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12906. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12907. if (shdr_status || shdr_add_status || rc) {
  12908. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12909. "2508 WQ_DESTROY mailbox failed with "
  12910. "status x%x add_status x%x, mbx status x%x\n",
  12911. shdr_status, shdr_add_status, rc);
  12912. status = -ENXIO;
  12913. }
  12914. /* Remove wq from any list */
  12915. list_del_init(&wq->list);
  12916. mempool_free(mbox, wq->phba->mbox_mem_pool);
  12917. return status;
  12918. }
  12919. /**
  12920. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  12921. * @rq: The queue structure associated with the queue to destroy.
  12922. *
  12923. * This function destroys a queue, as detailed in @rq by sending an mailbox
  12924. * command, specific to the type of queue, to the HBA.
  12925. *
  12926. * The @rq struct is used to get the queue ID of the queue to destroy.
  12927. *
  12928. * On success this function will return a zero. If the queue destroy mailbox
  12929. * command fails this function will return -ENXIO.
  12930. **/
  12931. int
  12932. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  12933. struct lpfc_queue *drq)
  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 (!hrq || !drq)
  12941. return -ENODEV;
  12942. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  12943. if (!mbox)
  12944. return -ENOMEM;
  12945. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  12946. sizeof(struct lpfc_sli4_cfg_mhdr));
  12947. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12948. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  12949. length, LPFC_SLI4_MBX_EMBED);
  12950. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12951. hrq->queue_id);
  12952. mbox->vport = hrq->phba->pport;
  12953. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12954. rc = lpfc_sli_issue_mbox(hrq->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.rq_destroy.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. "2509 RQ_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. if (rc != MBX_TIMEOUT)
  12966. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12967. return -ENXIO;
  12968. }
  12969. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12970. drq->queue_id);
  12971. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  12972. shdr = (union lpfc_sli4_cfg_shdr *)
  12973. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12974. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12975. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12976. if (shdr_status || shdr_add_status || rc) {
  12977. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12978. "2510 RQ_DESTROY mailbox failed with "
  12979. "status x%x add_status x%x, mbx status x%x\n",
  12980. shdr_status, shdr_add_status, rc);
  12981. status = -ENXIO;
  12982. }
  12983. list_del_init(&hrq->list);
  12984. list_del_init(&drq->list);
  12985. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12986. return status;
  12987. }
  12988. /**
  12989. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  12990. * @phba: The virtual port for which this call being executed.
  12991. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  12992. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  12993. * @xritag: the xritag that ties this io to the SGL pages.
  12994. *
  12995. * This routine will post the sgl pages for the IO that has the xritag
  12996. * that is in the iocbq structure. The xritag is assigned during iocbq
  12997. * creation and persists for as long as the driver is loaded.
  12998. * if the caller has fewer than 256 scatter gather segments to map then
  12999. * pdma_phys_addr1 should be 0.
  13000. * If the caller needs to map more than 256 scatter gather segment then
  13001. * pdma_phys_addr1 should be a valid physical address.
  13002. * physical address for SGLs must be 64 byte aligned.
  13003. * If you are going to map 2 SGL's then the first one must have 256 entries
  13004. * the second sgl can have between 1 and 256 entries.
  13005. *
  13006. * Return codes:
  13007. * 0 - Success
  13008. * -ENXIO, -ENOMEM - Failure
  13009. **/
  13010. int
  13011. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  13012. dma_addr_t pdma_phys_addr0,
  13013. dma_addr_t pdma_phys_addr1,
  13014. uint16_t xritag)
  13015. {
  13016. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  13017. LPFC_MBOXQ_t *mbox;
  13018. int rc;
  13019. uint32_t shdr_status, shdr_add_status;
  13020. uint32_t mbox_tmo;
  13021. union lpfc_sli4_cfg_shdr *shdr;
  13022. if (xritag == NO_XRI) {
  13023. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13024. "0364 Invalid param:\n");
  13025. return -EINVAL;
  13026. }
  13027. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13028. if (!mbox)
  13029. return -ENOMEM;
  13030. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13031. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  13032. sizeof(struct lpfc_mbx_post_sgl_pages) -
  13033. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  13034. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  13035. &mbox->u.mqe.un.post_sgl_pages;
  13036. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  13037. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  13038. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  13039. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  13040. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  13041. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  13042. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  13043. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  13044. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  13045. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  13046. if (!phba->sli4_hba.intr_enable)
  13047. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13048. else {
  13049. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13050. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13051. }
  13052. /* The IOCTL status is embedded in the mailbox subheader. */
  13053. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  13054. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13055. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13056. if (rc != MBX_TIMEOUT)
  13057. mempool_free(mbox, phba->mbox_mem_pool);
  13058. if (shdr_status || shdr_add_status || rc) {
  13059. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13060. "2511 POST_SGL mailbox failed with "
  13061. "status x%x add_status x%x, mbx status x%x\n",
  13062. shdr_status, shdr_add_status, rc);
  13063. }
  13064. return 0;
  13065. }
  13066. /**
  13067. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  13068. * @phba: pointer to lpfc hba data structure.
  13069. *
  13070. * This routine is invoked to post rpi header templates to the
  13071. * HBA consistent with the SLI-4 interface spec. This routine
  13072. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13073. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13074. *
  13075. * Returns
  13076. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13077. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13078. **/
  13079. static uint16_t
  13080. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  13081. {
  13082. unsigned long xri;
  13083. /*
  13084. * Fetch the next logical xri. Because this index is logical,
  13085. * the driver starts at 0 each time.
  13086. */
  13087. spin_lock_irq(&phba->hbalock);
  13088. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  13089. phba->sli4_hba.max_cfg_param.max_xri, 0);
  13090. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  13091. spin_unlock_irq(&phba->hbalock);
  13092. return NO_XRI;
  13093. } else {
  13094. set_bit(xri, phba->sli4_hba.xri_bmask);
  13095. phba->sli4_hba.max_cfg_param.xri_used++;
  13096. }
  13097. spin_unlock_irq(&phba->hbalock);
  13098. return xri;
  13099. }
  13100. /**
  13101. * lpfc_sli4_free_xri - Release an xri for reuse.
  13102. * @phba: pointer to lpfc hba data structure.
  13103. *
  13104. * This routine is invoked to release an xri to the pool of
  13105. * available rpis maintained by the driver.
  13106. **/
  13107. static void
  13108. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  13109. {
  13110. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  13111. phba->sli4_hba.max_cfg_param.xri_used--;
  13112. }
  13113. }
  13114. /**
  13115. * lpfc_sli4_free_xri - Release an xri for reuse.
  13116. * @phba: pointer to lpfc hba data structure.
  13117. *
  13118. * This routine is invoked to release an xri to the pool of
  13119. * available rpis maintained by the driver.
  13120. **/
  13121. void
  13122. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  13123. {
  13124. spin_lock_irq(&phba->hbalock);
  13125. __lpfc_sli4_free_xri(phba, xri);
  13126. spin_unlock_irq(&phba->hbalock);
  13127. }
  13128. /**
  13129. * lpfc_sli4_next_xritag - Get an xritag for the io
  13130. * @phba: Pointer to HBA context object.
  13131. *
  13132. * This function gets an xritag for the iocb. If there is no unused xritag
  13133. * it will return 0xffff.
  13134. * The function returns the allocated xritag if successful, else returns zero.
  13135. * Zero is not a valid xritag.
  13136. * The caller is not required to hold any lock.
  13137. **/
  13138. uint16_t
  13139. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  13140. {
  13141. uint16_t xri_index;
  13142. xri_index = lpfc_sli4_alloc_xri(phba);
  13143. if (xri_index == NO_XRI)
  13144. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  13145. "2004 Failed to allocate XRI.last XRITAG is %d"
  13146. " Max XRI is %d, Used XRI is %d\n",
  13147. xri_index,
  13148. phba->sli4_hba.max_cfg_param.max_xri,
  13149. phba->sli4_hba.max_cfg_param.xri_used);
  13150. return xri_index;
  13151. }
  13152. /**
  13153. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  13154. * @phba: pointer to lpfc hba data structure.
  13155. * @post_sgl_list: pointer to els sgl entry list.
  13156. * @count: number of els sgl entries on the list.
  13157. *
  13158. * This routine is invoked to post a block of driver's sgl pages to the
  13159. * HBA using non-embedded mailbox command. No Lock is held. This routine
  13160. * is only called when the driver is loading and after all IO has been
  13161. * stopped.
  13162. **/
  13163. static int
  13164. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  13165. struct list_head *post_sgl_list,
  13166. int post_cnt)
  13167. {
  13168. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  13169. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  13170. struct sgl_page_pairs *sgl_pg_pairs;
  13171. void *viraddr;
  13172. LPFC_MBOXQ_t *mbox;
  13173. uint32_t reqlen, alloclen, pg_pairs;
  13174. uint32_t mbox_tmo;
  13175. uint16_t xritag_start = 0;
  13176. int rc = 0;
  13177. uint32_t shdr_status, shdr_add_status;
  13178. union lpfc_sli4_cfg_shdr *shdr;
  13179. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  13180. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  13181. if (reqlen > SLI4_PAGE_SIZE) {
  13182. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  13183. "2559 Block sgl registration required DMA "
  13184. "size (%d) great than a page\n", reqlen);
  13185. return -ENOMEM;
  13186. }
  13187. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13188. if (!mbox)
  13189. return -ENOMEM;
  13190. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13191. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13192. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  13193. LPFC_SLI4_MBX_NEMBED);
  13194. if (alloclen < reqlen) {
  13195. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13196. "0285 Allocated DMA memory size (%d) is "
  13197. "less than the requested DMA memory "
  13198. "size (%d)\n", alloclen, reqlen);
  13199. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13200. return -ENOMEM;
  13201. }
  13202. /* Set up the SGL pages in the non-embedded DMA pages */
  13203. viraddr = mbox->sge_array->addr[0];
  13204. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  13205. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  13206. pg_pairs = 0;
  13207. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  13208. /* Set up the sge entry */
  13209. sgl_pg_pairs->sgl_pg0_addr_lo =
  13210. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  13211. sgl_pg_pairs->sgl_pg0_addr_hi =
  13212. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  13213. sgl_pg_pairs->sgl_pg1_addr_lo =
  13214. cpu_to_le32(putPaddrLow(0));
  13215. sgl_pg_pairs->sgl_pg1_addr_hi =
  13216. cpu_to_le32(putPaddrHigh(0));
  13217. /* Keep the first xritag on the list */
  13218. if (pg_pairs == 0)
  13219. xritag_start = sglq_entry->sli4_xritag;
  13220. sgl_pg_pairs++;
  13221. pg_pairs++;
  13222. }
  13223. /* Complete initialization and perform endian conversion. */
  13224. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  13225. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  13226. sgl->word0 = cpu_to_le32(sgl->word0);
  13227. if (!phba->sli4_hba.intr_enable)
  13228. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13229. else {
  13230. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13231. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13232. }
  13233. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  13234. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13235. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13236. if (rc != MBX_TIMEOUT)
  13237. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13238. if (shdr_status || shdr_add_status || rc) {
  13239. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13240. "2513 POST_SGL_BLOCK mailbox command failed "
  13241. "status x%x add_status x%x mbx status x%x\n",
  13242. shdr_status, shdr_add_status, rc);
  13243. rc = -ENXIO;
  13244. }
  13245. return rc;
  13246. }
  13247. /**
  13248. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  13249. * @phba: pointer to lpfc hba data structure.
  13250. * @sblist: pointer to scsi buffer list.
  13251. * @count: number of scsi buffers on the list.
  13252. *
  13253. * This routine is invoked to post a block of @count scsi sgl pages from a
  13254. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  13255. * No Lock is held.
  13256. *
  13257. **/
  13258. int
  13259. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  13260. struct list_head *sblist,
  13261. int count)
  13262. {
  13263. struct lpfc_scsi_buf *psb;
  13264. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  13265. struct sgl_page_pairs *sgl_pg_pairs;
  13266. void *viraddr;
  13267. LPFC_MBOXQ_t *mbox;
  13268. uint32_t reqlen, alloclen, pg_pairs;
  13269. uint32_t mbox_tmo;
  13270. uint16_t xritag_start = 0;
  13271. int rc = 0;
  13272. uint32_t shdr_status, shdr_add_status;
  13273. dma_addr_t pdma_phys_bpl1;
  13274. union lpfc_sli4_cfg_shdr *shdr;
  13275. /* Calculate the requested length of the dma memory */
  13276. reqlen = count * sizeof(struct sgl_page_pairs) +
  13277. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  13278. if (reqlen > SLI4_PAGE_SIZE) {
  13279. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  13280. "0217 Block sgl registration required DMA "
  13281. "size (%d) great than a page\n", reqlen);
  13282. return -ENOMEM;
  13283. }
  13284. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13285. if (!mbox) {
  13286. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13287. "0283 Failed to allocate mbox cmd memory\n");
  13288. return -ENOMEM;
  13289. }
  13290. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13291. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  13292. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  13293. LPFC_SLI4_MBX_NEMBED);
  13294. if (alloclen < reqlen) {
  13295. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13296. "2561 Allocated DMA memory size (%d) is "
  13297. "less than the requested DMA memory "
  13298. "size (%d)\n", alloclen, reqlen);
  13299. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13300. return -ENOMEM;
  13301. }
  13302. /* Get the first SGE entry from the non-embedded DMA memory */
  13303. viraddr = mbox->sge_array->addr[0];
  13304. /* Set up the SGL pages in the non-embedded DMA pages */
  13305. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  13306. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  13307. pg_pairs = 0;
  13308. list_for_each_entry(psb, sblist, list) {
  13309. /* Set up the sge entry */
  13310. sgl_pg_pairs->sgl_pg0_addr_lo =
  13311. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  13312. sgl_pg_pairs->sgl_pg0_addr_hi =
  13313. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  13314. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  13315. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  13316. else
  13317. pdma_phys_bpl1 = 0;
  13318. sgl_pg_pairs->sgl_pg1_addr_lo =
  13319. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  13320. sgl_pg_pairs->sgl_pg1_addr_hi =
  13321. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  13322. /* Keep the first xritag on the list */
  13323. if (pg_pairs == 0)
  13324. xritag_start = psb->cur_iocbq.sli4_xritag;
  13325. sgl_pg_pairs++;
  13326. pg_pairs++;
  13327. }
  13328. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  13329. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  13330. /* Perform endian conversion if necessary */
  13331. sgl->word0 = cpu_to_le32(sgl->word0);
  13332. if (!phba->sli4_hba.intr_enable)
  13333. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  13334. else {
  13335. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  13336. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  13337. }
  13338. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  13339. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13340. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13341. if (rc != MBX_TIMEOUT)
  13342. lpfc_sli4_mbox_cmd_free(phba, mbox);
  13343. if (shdr_status || shdr_add_status || rc) {
  13344. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13345. "2564 POST_SGL_BLOCK mailbox command failed "
  13346. "status x%x add_status x%x mbx status x%x\n",
  13347. shdr_status, shdr_add_status, rc);
  13348. rc = -ENXIO;
  13349. }
  13350. return rc;
  13351. }
  13352. /**
  13353. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  13354. * @phba: pointer to lpfc_hba struct that the frame was received on
  13355. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13356. *
  13357. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  13358. * valid type of frame that the LPFC driver will handle. This function will
  13359. * return a zero if the frame is a valid frame or a non zero value when the
  13360. * frame does not pass the check.
  13361. **/
  13362. static int
  13363. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  13364. {
  13365. /* make rctl_names static to save stack space */
  13366. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  13367. char *type_names[] = FC_TYPE_NAMES_INIT;
  13368. struct fc_vft_header *fc_vft_hdr;
  13369. uint32_t *header = (uint32_t *) fc_hdr;
  13370. switch (fc_hdr->fh_r_ctl) {
  13371. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  13372. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  13373. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  13374. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  13375. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  13376. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  13377. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  13378. case FC_RCTL_DD_CMD_STATUS: /* command status */
  13379. case FC_RCTL_ELS_REQ: /* extended link services request */
  13380. case FC_RCTL_ELS_REP: /* extended link services reply */
  13381. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  13382. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  13383. case FC_RCTL_BA_NOP: /* basic link service NOP */
  13384. case FC_RCTL_BA_ABTS: /* basic link service abort */
  13385. case FC_RCTL_BA_RMC: /* remove connection */
  13386. case FC_RCTL_BA_ACC: /* basic accept */
  13387. case FC_RCTL_BA_RJT: /* basic reject */
  13388. case FC_RCTL_BA_PRMT:
  13389. case FC_RCTL_ACK_1: /* acknowledge_1 */
  13390. case FC_RCTL_ACK_0: /* acknowledge_0 */
  13391. case FC_RCTL_P_RJT: /* port reject */
  13392. case FC_RCTL_F_RJT: /* fabric reject */
  13393. case FC_RCTL_P_BSY: /* port busy */
  13394. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  13395. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  13396. case FC_RCTL_LCR: /* link credit reset */
  13397. case FC_RCTL_END: /* end */
  13398. break;
  13399. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  13400. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  13401. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  13402. return lpfc_fc_frame_check(phba, fc_hdr);
  13403. default:
  13404. goto drop;
  13405. }
  13406. switch (fc_hdr->fh_type) {
  13407. case FC_TYPE_BLS:
  13408. case FC_TYPE_ELS:
  13409. case FC_TYPE_FCP:
  13410. case FC_TYPE_CT:
  13411. break;
  13412. case FC_TYPE_IP:
  13413. case FC_TYPE_ILS:
  13414. default:
  13415. goto drop;
  13416. }
  13417. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  13418. "2538 Received frame rctl:%s (x%x), type:%s (x%x), "
  13419. "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
  13420. rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl,
  13421. type_names[fc_hdr->fh_type], fc_hdr->fh_type,
  13422. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  13423. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  13424. be32_to_cpu(header[4]), be32_to_cpu(header[5]),
  13425. be32_to_cpu(header[6]));
  13426. return 0;
  13427. drop:
  13428. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  13429. "2539 Dropped frame rctl:%s type:%s\n",
  13430. rctl_names[fc_hdr->fh_r_ctl],
  13431. type_names[fc_hdr->fh_type]);
  13432. return 1;
  13433. }
  13434. /**
  13435. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  13436. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13437. *
  13438. * This function processes the FC header to retrieve the VFI from the VF
  13439. * header, if one exists. This function will return the VFI if one exists
  13440. * or 0 if no VSAN Header exists.
  13441. **/
  13442. static uint32_t
  13443. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  13444. {
  13445. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  13446. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  13447. return 0;
  13448. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  13449. }
  13450. /**
  13451. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  13452. * @phba: Pointer to the HBA structure to search for the vport on
  13453. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  13454. * @fcfi: The FC Fabric ID that the frame came from
  13455. *
  13456. * This function searches the @phba for a vport that matches the content of the
  13457. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  13458. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  13459. * returns the matching vport pointer or NULL if unable to match frame to a
  13460. * vport.
  13461. **/
  13462. static struct lpfc_vport *
  13463. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  13464. uint16_t fcfi)
  13465. {
  13466. struct lpfc_vport **vports;
  13467. struct lpfc_vport *vport = NULL;
  13468. int i;
  13469. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  13470. fc_hdr->fh_d_id[1] << 8 |
  13471. fc_hdr->fh_d_id[2]);
  13472. if (did == Fabric_DID)
  13473. return phba->pport;
  13474. if ((phba->pport->fc_flag & FC_PT2PT) &&
  13475. !(phba->link_state == LPFC_HBA_READY))
  13476. return phba->pport;
  13477. vports = lpfc_create_vport_work_array(phba);
  13478. if (vports != NULL)
  13479. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  13480. if (phba->fcf.fcfi == fcfi &&
  13481. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  13482. vports[i]->fc_myDID == did) {
  13483. vport = vports[i];
  13484. break;
  13485. }
  13486. }
  13487. lpfc_destroy_vport_work_array(phba, vports);
  13488. return vport;
  13489. }
  13490. /**
  13491. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  13492. * @vport: The vport to work on.
  13493. *
  13494. * This function updates the receive sequence time stamp for this vport. The
  13495. * receive sequence time stamp indicates the time that the last frame of the
  13496. * the sequence that has been idle for the longest amount of time was received.
  13497. * the driver uses this time stamp to indicate if any received sequences have
  13498. * timed out.
  13499. **/
  13500. static void
  13501. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  13502. {
  13503. struct lpfc_dmabuf *h_buf;
  13504. struct hbq_dmabuf *dmabuf = NULL;
  13505. /* get the oldest sequence on the rcv list */
  13506. h_buf = list_get_first(&vport->rcv_buffer_list,
  13507. struct lpfc_dmabuf, list);
  13508. if (!h_buf)
  13509. return;
  13510. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13511. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  13512. }
  13513. /**
  13514. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  13515. * @vport: The vport that the received sequences were sent to.
  13516. *
  13517. * This function cleans up all outstanding received sequences. This is called
  13518. * by the driver when a link event or user action invalidates all the received
  13519. * sequences.
  13520. **/
  13521. void
  13522. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  13523. {
  13524. struct lpfc_dmabuf *h_buf, *hnext;
  13525. struct lpfc_dmabuf *d_buf, *dnext;
  13526. struct hbq_dmabuf *dmabuf = NULL;
  13527. /* start with the oldest sequence on the rcv list */
  13528. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  13529. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13530. list_del_init(&dmabuf->hbuf.list);
  13531. list_for_each_entry_safe(d_buf, dnext,
  13532. &dmabuf->dbuf.list, list) {
  13533. list_del_init(&d_buf->list);
  13534. lpfc_in_buf_free(vport->phba, d_buf);
  13535. }
  13536. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  13537. }
  13538. }
  13539. /**
  13540. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  13541. * @vport: The vport that the received sequences were sent to.
  13542. *
  13543. * This function determines whether any received sequences have timed out by
  13544. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  13545. * indicates that there is at least one timed out sequence this routine will
  13546. * go through the received sequences one at a time from most inactive to most
  13547. * active to determine which ones need to be cleaned up. Once it has determined
  13548. * that a sequence needs to be cleaned up it will simply free up the resources
  13549. * without sending an abort.
  13550. **/
  13551. void
  13552. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  13553. {
  13554. struct lpfc_dmabuf *h_buf, *hnext;
  13555. struct lpfc_dmabuf *d_buf, *dnext;
  13556. struct hbq_dmabuf *dmabuf = NULL;
  13557. unsigned long timeout;
  13558. int abort_count = 0;
  13559. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  13560. vport->rcv_buffer_time_stamp);
  13561. if (list_empty(&vport->rcv_buffer_list) ||
  13562. time_before(jiffies, timeout))
  13563. return;
  13564. /* start with the oldest sequence on the rcv list */
  13565. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  13566. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13567. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  13568. dmabuf->time_stamp);
  13569. if (time_before(jiffies, timeout))
  13570. break;
  13571. abort_count++;
  13572. list_del_init(&dmabuf->hbuf.list);
  13573. list_for_each_entry_safe(d_buf, dnext,
  13574. &dmabuf->dbuf.list, list) {
  13575. list_del_init(&d_buf->list);
  13576. lpfc_in_buf_free(vport->phba, d_buf);
  13577. }
  13578. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  13579. }
  13580. if (abort_count)
  13581. lpfc_update_rcv_time_stamp(vport);
  13582. }
  13583. /**
  13584. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  13585. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  13586. *
  13587. * This function searches through the existing incomplete sequences that have
  13588. * been sent to this @vport. If the frame matches one of the incomplete
  13589. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  13590. * make up that sequence. If no sequence is found that matches this frame then
  13591. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  13592. * This function returns a pointer to the first dmabuf in the sequence list that
  13593. * the frame was linked to.
  13594. **/
  13595. static struct hbq_dmabuf *
  13596. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13597. {
  13598. struct fc_frame_header *new_hdr;
  13599. struct fc_frame_header *temp_hdr;
  13600. struct lpfc_dmabuf *d_buf;
  13601. struct lpfc_dmabuf *h_buf;
  13602. struct hbq_dmabuf *seq_dmabuf = NULL;
  13603. struct hbq_dmabuf *temp_dmabuf = NULL;
  13604. uint8_t found = 0;
  13605. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13606. dmabuf->time_stamp = jiffies;
  13607. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13608. /* Use the hdr_buf to find the sequence that this frame belongs to */
  13609. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13610. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13611. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13612. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13613. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13614. continue;
  13615. /* found a pending sequence that matches this frame */
  13616. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13617. break;
  13618. }
  13619. if (!seq_dmabuf) {
  13620. /*
  13621. * This indicates first frame received for this sequence.
  13622. * Queue the buffer on the vport's rcv_buffer_list.
  13623. */
  13624. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13625. lpfc_update_rcv_time_stamp(vport);
  13626. return dmabuf;
  13627. }
  13628. temp_hdr = seq_dmabuf->hbuf.virt;
  13629. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  13630. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13631. list_del_init(&seq_dmabuf->hbuf.list);
  13632. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13633. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13634. lpfc_update_rcv_time_stamp(vport);
  13635. return dmabuf;
  13636. }
  13637. /* move this sequence to the tail to indicate a young sequence */
  13638. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13639. seq_dmabuf->time_stamp = jiffies;
  13640. lpfc_update_rcv_time_stamp(vport);
  13641. if (list_empty(&seq_dmabuf->dbuf.list)) {
  13642. temp_hdr = dmabuf->hbuf.virt;
  13643. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13644. return seq_dmabuf;
  13645. }
  13646. /* find the correct place in the sequence to insert this frame */
  13647. d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
  13648. while (!found) {
  13649. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13650. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  13651. /*
  13652. * If the frame's sequence count is greater than the frame on
  13653. * the list then insert the frame right after this frame
  13654. */
  13655. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  13656. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13657. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  13658. found = 1;
  13659. break;
  13660. }
  13661. if (&d_buf->list == &seq_dmabuf->dbuf.list)
  13662. break;
  13663. d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
  13664. }
  13665. if (found)
  13666. return seq_dmabuf;
  13667. return NULL;
  13668. }
  13669. /**
  13670. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  13671. * @vport: pointer to a vitural port
  13672. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13673. *
  13674. * This function tries to abort from the partially assembed sequence, described
  13675. * by the information from basic abbort @dmabuf. It checks to see whether such
  13676. * partially assembled sequence held by the driver. If so, it shall free up all
  13677. * the frames from the partially assembled sequence.
  13678. *
  13679. * Return
  13680. * true -- if there is matching partially assembled sequence present and all
  13681. * the frames freed with the sequence;
  13682. * false -- if there is no matching partially assembled sequence present so
  13683. * nothing got aborted in the lower layer driver
  13684. **/
  13685. static bool
  13686. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  13687. struct hbq_dmabuf *dmabuf)
  13688. {
  13689. struct fc_frame_header *new_hdr;
  13690. struct fc_frame_header *temp_hdr;
  13691. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  13692. struct hbq_dmabuf *seq_dmabuf = NULL;
  13693. /* Use the hdr_buf to find the sequence that matches this frame */
  13694. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13695. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  13696. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13697. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13698. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13699. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13700. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13701. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13702. continue;
  13703. /* found a pending sequence that matches this frame */
  13704. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13705. break;
  13706. }
  13707. /* Free up all the frames from the partially assembled sequence */
  13708. if (seq_dmabuf) {
  13709. list_for_each_entry_safe(d_buf, n_buf,
  13710. &seq_dmabuf->dbuf.list, list) {
  13711. list_del_init(&d_buf->list);
  13712. lpfc_in_buf_free(vport->phba, d_buf);
  13713. }
  13714. return true;
  13715. }
  13716. return false;
  13717. }
  13718. /**
  13719. * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
  13720. * @vport: pointer to a vitural port
  13721. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13722. *
  13723. * This function tries to abort from the assembed sequence from upper level
  13724. * protocol, described by the information from basic abbort @dmabuf. It
  13725. * checks to see whether such pending context exists at upper level protocol.
  13726. * If so, it shall clean up the pending context.
  13727. *
  13728. * Return
  13729. * true -- if there is matching pending context of the sequence cleaned
  13730. * at ulp;
  13731. * false -- if there is no matching pending context of the sequence present
  13732. * at ulp.
  13733. **/
  13734. static bool
  13735. lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13736. {
  13737. struct lpfc_hba *phba = vport->phba;
  13738. int handled;
  13739. /* Accepting abort at ulp with SLI4 only */
  13740. if (phba->sli_rev < LPFC_SLI_REV4)
  13741. return false;
  13742. /* Register all caring upper level protocols to attend abort */
  13743. handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
  13744. if (handled)
  13745. return true;
  13746. return false;
  13747. }
  13748. /**
  13749. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  13750. * @phba: Pointer to HBA context object.
  13751. * @cmd_iocbq: pointer to the command iocbq structure.
  13752. * @rsp_iocbq: pointer to the response iocbq structure.
  13753. *
  13754. * This function handles the sequence abort response iocb command complete
  13755. * event. It properly releases the memory allocated to the sequence abort
  13756. * accept iocb.
  13757. **/
  13758. static void
  13759. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  13760. struct lpfc_iocbq *cmd_iocbq,
  13761. struct lpfc_iocbq *rsp_iocbq)
  13762. {
  13763. struct lpfc_nodelist *ndlp;
  13764. if (cmd_iocbq) {
  13765. ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
  13766. lpfc_nlp_put(ndlp);
  13767. lpfc_nlp_not_used(ndlp);
  13768. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  13769. }
  13770. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  13771. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  13772. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13773. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  13774. rsp_iocbq->iocb.ulpStatus,
  13775. rsp_iocbq->iocb.un.ulpWord[4]);
  13776. }
  13777. /**
  13778. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  13779. * @phba: Pointer to HBA context object.
  13780. * @xri: xri id in transaction.
  13781. *
  13782. * This function validates the xri maps to the known range of XRIs allocated an
  13783. * used by the driver.
  13784. **/
  13785. uint16_t
  13786. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  13787. uint16_t xri)
  13788. {
  13789. uint16_t i;
  13790. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  13791. if (xri == phba->sli4_hba.xri_ids[i])
  13792. return i;
  13793. }
  13794. return NO_XRI;
  13795. }
  13796. /**
  13797. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  13798. * @phba: Pointer to HBA context object.
  13799. * @fc_hdr: pointer to a FC frame header.
  13800. *
  13801. * This function sends a basic response to a previous unsol sequence abort
  13802. * event after aborting the sequence handling.
  13803. **/
  13804. static void
  13805. lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
  13806. struct fc_frame_header *fc_hdr, bool aborted)
  13807. {
  13808. struct lpfc_hba *phba = vport->phba;
  13809. struct lpfc_iocbq *ctiocb = NULL;
  13810. struct lpfc_nodelist *ndlp;
  13811. uint16_t oxid, rxid, xri, lxri;
  13812. uint32_t sid, fctl;
  13813. IOCB_t *icmd;
  13814. int rc;
  13815. if (!lpfc_is_link_up(phba))
  13816. return;
  13817. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13818. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  13819. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  13820. ndlp = lpfc_findnode_did(vport, sid);
  13821. if (!ndlp) {
  13822. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  13823. if (!ndlp) {
  13824. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13825. "1268 Failed to allocate ndlp for "
  13826. "oxid:x%x SID:x%x\n", oxid, sid);
  13827. return;
  13828. }
  13829. lpfc_nlp_init(vport, ndlp, sid);
  13830. /* Put ndlp onto pport node list */
  13831. lpfc_enqueue_node(vport, ndlp);
  13832. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  13833. /* re-setup ndlp without removing from node list */
  13834. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  13835. if (!ndlp) {
  13836. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13837. "3275 Failed to active ndlp found "
  13838. "for oxid:x%x SID:x%x\n", oxid, sid);
  13839. return;
  13840. }
  13841. }
  13842. /* Allocate buffer for rsp iocb */
  13843. ctiocb = lpfc_sli_get_iocbq(phba);
  13844. if (!ctiocb)
  13845. return;
  13846. /* Extract the F_CTL field from FC_HDR */
  13847. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  13848. icmd = &ctiocb->iocb;
  13849. icmd->un.xseq64.bdl.bdeSize = 0;
  13850. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  13851. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  13852. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  13853. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  13854. /* Fill in the rest of iocb fields */
  13855. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  13856. icmd->ulpBdeCount = 0;
  13857. icmd->ulpLe = 1;
  13858. icmd->ulpClass = CLASS3;
  13859. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  13860. ctiocb->context1 = lpfc_nlp_get(ndlp);
  13861. ctiocb->iocb_cmpl = NULL;
  13862. ctiocb->vport = phba->pport;
  13863. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  13864. ctiocb->sli4_lxritag = NO_XRI;
  13865. ctiocb->sli4_xritag = NO_XRI;
  13866. if (fctl & FC_FC_EX_CTX)
  13867. /* Exchange responder sent the abort so we
  13868. * own the oxid.
  13869. */
  13870. xri = oxid;
  13871. else
  13872. xri = rxid;
  13873. lxri = lpfc_sli4_xri_inrange(phba, xri);
  13874. if (lxri != NO_XRI)
  13875. lpfc_set_rrq_active(phba, ndlp, lxri,
  13876. (xri == oxid) ? rxid : oxid, 0);
  13877. /* For BA_ABTS from exchange responder, if the logical xri with
  13878. * the oxid maps to the FCP XRI range, the port no longer has
  13879. * that exchange context, send a BLS_RJT. Override the IOCB for
  13880. * a BA_RJT.
  13881. */
  13882. if ((fctl & FC_FC_EX_CTX) &&
  13883. (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) {
  13884. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  13885. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  13886. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  13887. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  13888. }
  13889. /* If BA_ABTS failed to abort a partially assembled receive sequence,
  13890. * the driver no longer has that exchange, send a BLS_RJT. Override
  13891. * the IOCB for a BA_RJT.
  13892. */
  13893. if (aborted == false) {
  13894. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  13895. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  13896. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  13897. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  13898. }
  13899. if (fctl & FC_FC_EX_CTX) {
  13900. /* ABTS sent by responder to CT exchange, construction
  13901. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  13902. * field and RX_ID from ABTS for RX_ID field.
  13903. */
  13904. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  13905. } else {
  13906. /* ABTS sent by initiator to CT exchange, construction
  13907. * of BA_ACC will need to allocate a new XRI as for the
  13908. * XRI_TAG field.
  13909. */
  13910. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  13911. }
  13912. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  13913. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  13914. /* Xmit CT abts response on exchange <xid> */
  13915. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  13916. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  13917. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  13918. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  13919. if (rc == IOCB_ERROR) {
  13920. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  13921. "2925 Failed to issue CT ABTS RSP x%x on "
  13922. "xri x%x, Data x%x\n",
  13923. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  13924. phba->link_state);
  13925. lpfc_nlp_put(ndlp);
  13926. ctiocb->context1 = NULL;
  13927. lpfc_sli_release_iocbq(phba, ctiocb);
  13928. }
  13929. }
  13930. /**
  13931. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  13932. * @vport: Pointer to the vport on which this sequence was received
  13933. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13934. *
  13935. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  13936. * receive sequence is only partially assembed by the driver, it shall abort
  13937. * the partially assembled frames for the sequence. Otherwise, if the
  13938. * unsolicited receive sequence has been completely assembled and passed to
  13939. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  13940. * unsolicited sequence has been aborted. After that, it will issue a basic
  13941. * accept to accept the abort.
  13942. **/
  13943. static void
  13944. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  13945. struct hbq_dmabuf *dmabuf)
  13946. {
  13947. struct lpfc_hba *phba = vport->phba;
  13948. struct fc_frame_header fc_hdr;
  13949. uint32_t fctl;
  13950. bool aborted;
  13951. /* Make a copy of fc_hdr before the dmabuf being released */
  13952. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  13953. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  13954. if (fctl & FC_FC_EX_CTX) {
  13955. /* ABTS by responder to exchange, no cleanup needed */
  13956. aborted = true;
  13957. } else {
  13958. /* ABTS by initiator to exchange, need to do cleanup */
  13959. aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  13960. if (aborted == false)
  13961. aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
  13962. }
  13963. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13964. /* Respond with BA_ACC or BA_RJT accordingly */
  13965. lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
  13966. }
  13967. /**
  13968. * lpfc_seq_complete - Indicates if a sequence is complete
  13969. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13970. *
  13971. * This function checks the sequence, starting with the frame described by
  13972. * @dmabuf, to see if all the frames associated with this sequence are present.
  13973. * the frames associated with this sequence are linked to the @dmabuf using the
  13974. * dbuf list. This function looks for two major things. 1) That the first frame
  13975. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  13976. * set. 3) That there are no holes in the sequence count. The function will
  13977. * return 1 when the sequence is complete, otherwise it will return 0.
  13978. **/
  13979. static int
  13980. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  13981. {
  13982. struct fc_frame_header *hdr;
  13983. struct lpfc_dmabuf *d_buf;
  13984. struct hbq_dmabuf *seq_dmabuf;
  13985. uint32_t fctl;
  13986. int seq_count = 0;
  13987. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13988. /* make sure first fame of sequence has a sequence count of zero */
  13989. if (hdr->fh_seq_cnt != seq_count)
  13990. return 0;
  13991. fctl = (hdr->fh_f_ctl[0] << 16 |
  13992. hdr->fh_f_ctl[1] << 8 |
  13993. hdr->fh_f_ctl[2]);
  13994. /* If last frame of sequence we can return success. */
  13995. if (fctl & FC_FC_END_SEQ)
  13996. return 1;
  13997. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  13998. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13999. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14000. /* If there is a hole in the sequence count then fail. */
  14001. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  14002. return 0;
  14003. fctl = (hdr->fh_f_ctl[0] << 16 |
  14004. hdr->fh_f_ctl[1] << 8 |
  14005. hdr->fh_f_ctl[2]);
  14006. /* If last frame of sequence we can return success. */
  14007. if (fctl & FC_FC_END_SEQ)
  14008. return 1;
  14009. }
  14010. return 0;
  14011. }
  14012. /**
  14013. * lpfc_prep_seq - Prep sequence for ULP processing
  14014. * @vport: Pointer to the vport on which this sequence was received
  14015. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  14016. *
  14017. * This function takes a sequence, described by a list of frames, and creates
  14018. * a list of iocbq structures to describe the sequence. This iocbq list will be
  14019. * used to issue to the generic unsolicited sequence handler. This routine
  14020. * returns a pointer to the first iocbq in the list. If the function is unable
  14021. * to allocate an iocbq then it throw out the received frames that were not
  14022. * able to be described and return a pointer to the first iocbq. If unable to
  14023. * allocate any iocbqs (including the first) this function will return NULL.
  14024. **/
  14025. static struct lpfc_iocbq *
  14026. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  14027. {
  14028. struct hbq_dmabuf *hbq_buf;
  14029. struct lpfc_dmabuf *d_buf, *n_buf;
  14030. struct lpfc_iocbq *first_iocbq, *iocbq;
  14031. struct fc_frame_header *fc_hdr;
  14032. uint32_t sid;
  14033. uint32_t len, tot_len;
  14034. struct ulp_bde64 *pbde;
  14035. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14036. /* remove from receive buffer list */
  14037. list_del_init(&seq_dmabuf->hbuf.list);
  14038. lpfc_update_rcv_time_stamp(vport);
  14039. /* get the Remote Port's SID */
  14040. sid = sli4_sid_from_fc_hdr(fc_hdr);
  14041. tot_len = 0;
  14042. /* Get an iocbq struct to fill in. */
  14043. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  14044. if (first_iocbq) {
  14045. /* Initialize the first IOCB. */
  14046. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  14047. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  14048. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  14049. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  14050. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  14051. first_iocbq->iocb.un.rcvels.parmRo =
  14052. sli4_did_from_fc_hdr(fc_hdr);
  14053. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  14054. } else
  14055. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  14056. first_iocbq->iocb.ulpContext = NO_XRI;
  14057. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  14058. be16_to_cpu(fc_hdr->fh_ox_id);
  14059. /* iocbq is prepped for internal consumption. Physical vpi. */
  14060. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  14061. vport->phba->vpi_ids[vport->vpi];
  14062. /* put the first buffer into the first IOCBq */
  14063. tot_len = bf_get(lpfc_rcqe_length,
  14064. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  14065. first_iocbq->context2 = &seq_dmabuf->dbuf;
  14066. first_iocbq->context3 = NULL;
  14067. first_iocbq->iocb.ulpBdeCount = 1;
  14068. if (tot_len > LPFC_DATA_BUF_SIZE)
  14069. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  14070. LPFC_DATA_BUF_SIZE;
  14071. else
  14072. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
  14073. first_iocbq->iocb.un.rcvels.remoteID = sid;
  14074. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  14075. }
  14076. iocbq = first_iocbq;
  14077. /*
  14078. * Each IOCBq can have two Buffers assigned, so go through the list
  14079. * of buffers for this sequence and save two buffers in each IOCBq
  14080. */
  14081. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  14082. if (!iocbq) {
  14083. lpfc_in_buf_free(vport->phba, d_buf);
  14084. continue;
  14085. }
  14086. if (!iocbq->context3) {
  14087. iocbq->context3 = d_buf;
  14088. iocbq->iocb.ulpBdeCount++;
  14089. /* We need to get the size out of the right CQE */
  14090. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  14091. len = bf_get(lpfc_rcqe_length,
  14092. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  14093. pbde = (struct ulp_bde64 *)
  14094. &iocbq->iocb.unsli3.sli3Words[4];
  14095. if (len > LPFC_DATA_BUF_SIZE)
  14096. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  14097. else
  14098. pbde->tus.f.bdeSize = len;
  14099. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  14100. tot_len += len;
  14101. } else {
  14102. iocbq = lpfc_sli_get_iocbq(vport->phba);
  14103. if (!iocbq) {
  14104. if (first_iocbq) {
  14105. first_iocbq->iocb.ulpStatus =
  14106. IOSTAT_FCP_RSP_ERROR;
  14107. first_iocbq->iocb.un.ulpWord[4] =
  14108. IOERR_NO_RESOURCES;
  14109. }
  14110. lpfc_in_buf_free(vport->phba, d_buf);
  14111. continue;
  14112. }
  14113. /* We need to get the size out of the right CQE */
  14114. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  14115. len = bf_get(lpfc_rcqe_length,
  14116. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  14117. iocbq->context2 = d_buf;
  14118. iocbq->context3 = NULL;
  14119. iocbq->iocb.ulpBdeCount = 1;
  14120. if (len > LPFC_DATA_BUF_SIZE)
  14121. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  14122. LPFC_DATA_BUF_SIZE;
  14123. else
  14124. iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
  14125. tot_len += len;
  14126. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  14127. iocbq->iocb.un.rcvels.remoteID = sid;
  14128. list_add_tail(&iocbq->list, &first_iocbq->list);
  14129. }
  14130. }
  14131. return first_iocbq;
  14132. }
  14133. static void
  14134. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  14135. struct hbq_dmabuf *seq_dmabuf)
  14136. {
  14137. struct fc_frame_header *fc_hdr;
  14138. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  14139. struct lpfc_hba *phba = vport->phba;
  14140. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  14141. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  14142. if (!iocbq) {
  14143. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14144. "2707 Ring %d handler: Failed to allocate "
  14145. "iocb Rctl x%x Type x%x received\n",
  14146. LPFC_ELS_RING,
  14147. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  14148. return;
  14149. }
  14150. if (!lpfc_complete_unsol_iocb(phba,
  14151. &phba->sli.ring[LPFC_ELS_RING],
  14152. iocbq, fc_hdr->fh_r_ctl,
  14153. fc_hdr->fh_type))
  14154. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14155. "2540 Ring %d handler: unexpected Rctl "
  14156. "x%x Type x%x received\n",
  14157. LPFC_ELS_RING,
  14158. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  14159. /* Free iocb created in lpfc_prep_seq */
  14160. list_for_each_entry_safe(curr_iocb, next_iocb,
  14161. &iocbq->list, list) {
  14162. list_del_init(&curr_iocb->list);
  14163. lpfc_sli_release_iocbq(phba, curr_iocb);
  14164. }
  14165. lpfc_sli_release_iocbq(phba, iocbq);
  14166. }
  14167. /**
  14168. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  14169. * @phba: Pointer to HBA context object.
  14170. *
  14171. * This function is called with no lock held. This function processes all
  14172. * the received buffers and gives it to upper layers when a received buffer
  14173. * indicates that it is the final frame in the sequence. The interrupt
  14174. * service routine processes received buffers at interrupt contexts and adds
  14175. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  14176. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  14177. * appropriate receive function when the final frame in a sequence is received.
  14178. **/
  14179. void
  14180. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  14181. struct hbq_dmabuf *dmabuf)
  14182. {
  14183. struct hbq_dmabuf *seq_dmabuf;
  14184. struct fc_frame_header *fc_hdr;
  14185. struct lpfc_vport *vport;
  14186. uint32_t fcfi;
  14187. uint32_t did;
  14188. /* Process each received buffer */
  14189. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  14190. /* check to see if this a valid type of frame */
  14191. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  14192. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14193. return;
  14194. }
  14195. if ((bf_get(lpfc_cqe_code,
  14196. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  14197. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  14198. &dmabuf->cq_event.cqe.rcqe_cmpl);
  14199. else
  14200. fcfi = bf_get(lpfc_rcqe_fcf_id,
  14201. &dmabuf->cq_event.cqe.rcqe_cmpl);
  14202. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  14203. if (!vport) {
  14204. /* throw out the frame */
  14205. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14206. return;
  14207. }
  14208. /* d_id this frame is directed to */
  14209. did = sli4_did_from_fc_hdr(fc_hdr);
  14210. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  14211. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  14212. (did != Fabric_DID)) {
  14213. /*
  14214. * Throw out the frame if we are not pt2pt.
  14215. * The pt2pt protocol allows for discovery frames
  14216. * to be received without a registered VPI.
  14217. */
  14218. if (!(vport->fc_flag & FC_PT2PT) ||
  14219. (phba->link_state == LPFC_HBA_READY)) {
  14220. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14221. return;
  14222. }
  14223. }
  14224. /* Handle the basic abort sequence (BA_ABTS) event */
  14225. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  14226. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  14227. return;
  14228. }
  14229. /* Link this frame */
  14230. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  14231. if (!seq_dmabuf) {
  14232. /* unable to add frame to vport - throw it out */
  14233. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  14234. return;
  14235. }
  14236. /* If not last frame in sequence continue processing frames. */
  14237. if (!lpfc_seq_complete(seq_dmabuf))
  14238. return;
  14239. /* Send the complete sequence to the upper layer protocol */
  14240. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  14241. }
  14242. /**
  14243. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  14244. * @phba: pointer to lpfc hba data structure.
  14245. *
  14246. * This routine is invoked to post rpi header templates to the
  14247. * HBA consistent with the SLI-4 interface spec. This routine
  14248. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  14249. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  14250. *
  14251. * This routine does not require any locks. It's usage is expected
  14252. * to be driver load or reset recovery when the driver is
  14253. * sequential.
  14254. *
  14255. * Return codes
  14256. * 0 - successful
  14257. * -EIO - The mailbox failed to complete successfully.
  14258. * When this error occurs, the driver is not guaranteed
  14259. * to have any rpi regions posted to the device and
  14260. * must either attempt to repost the regions or take a
  14261. * fatal error.
  14262. **/
  14263. int
  14264. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  14265. {
  14266. struct lpfc_rpi_hdr *rpi_page;
  14267. uint32_t rc = 0;
  14268. uint16_t lrpi = 0;
  14269. /* SLI4 ports that support extents do not require RPI headers. */
  14270. if (!phba->sli4_hba.rpi_hdrs_in_use)
  14271. goto exit;
  14272. if (phba->sli4_hba.extents_in_use)
  14273. return -EIO;
  14274. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  14275. /*
  14276. * Assign the rpi headers a physical rpi only if the driver
  14277. * has not initialized those resources. A port reset only
  14278. * needs the headers posted.
  14279. */
  14280. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  14281. LPFC_RPI_RSRC_RDY)
  14282. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  14283. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  14284. if (rc != MBX_SUCCESS) {
  14285. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14286. "2008 Error %d posting all rpi "
  14287. "headers\n", rc);
  14288. rc = -EIO;
  14289. break;
  14290. }
  14291. }
  14292. exit:
  14293. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  14294. LPFC_RPI_RSRC_RDY);
  14295. return rc;
  14296. }
  14297. /**
  14298. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  14299. * @phba: pointer to lpfc hba data structure.
  14300. * @rpi_page: pointer to the rpi memory region.
  14301. *
  14302. * This routine is invoked to post a single rpi header to the
  14303. * HBA consistent with the SLI-4 interface spec. This memory region
  14304. * maps up to 64 rpi context regions.
  14305. *
  14306. * Return codes
  14307. * 0 - successful
  14308. * -ENOMEM - No available memory
  14309. * -EIO - The mailbox failed to complete successfully.
  14310. **/
  14311. int
  14312. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  14313. {
  14314. LPFC_MBOXQ_t *mboxq;
  14315. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  14316. uint32_t rc = 0;
  14317. uint32_t shdr_status, shdr_add_status;
  14318. union lpfc_sli4_cfg_shdr *shdr;
  14319. /* SLI4 ports that support extents do not require RPI headers. */
  14320. if (!phba->sli4_hba.rpi_hdrs_in_use)
  14321. return rc;
  14322. if (phba->sli4_hba.extents_in_use)
  14323. return -EIO;
  14324. /* The port is notified of the header region via a mailbox command. */
  14325. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14326. if (!mboxq) {
  14327. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14328. "2001 Unable to allocate memory for issuing "
  14329. "SLI_CONFIG_SPECIAL mailbox command\n");
  14330. return -ENOMEM;
  14331. }
  14332. /* Post all rpi memory regions to the port. */
  14333. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  14334. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  14335. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  14336. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  14337. sizeof(struct lpfc_sli4_cfg_mhdr),
  14338. LPFC_SLI4_MBX_EMBED);
  14339. /* Post the physical rpi to the port for this rpi header. */
  14340. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  14341. rpi_page->start_rpi);
  14342. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  14343. hdr_tmpl, rpi_page->page_count);
  14344. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  14345. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  14346. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14347. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  14348. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14349. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14350. if (rc != MBX_TIMEOUT)
  14351. mempool_free(mboxq, phba->mbox_mem_pool);
  14352. if (shdr_status || shdr_add_status || rc) {
  14353. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14354. "2514 POST_RPI_HDR mailbox failed with "
  14355. "status x%x add_status x%x, mbx status x%x\n",
  14356. shdr_status, shdr_add_status, rc);
  14357. rc = -ENXIO;
  14358. }
  14359. return rc;
  14360. }
  14361. /**
  14362. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  14363. * @phba: pointer to lpfc hba data structure.
  14364. *
  14365. * This routine is invoked to post rpi header templates to the
  14366. * HBA consistent with the SLI-4 interface spec. This routine
  14367. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  14368. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  14369. *
  14370. * Returns
  14371. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  14372. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  14373. **/
  14374. int
  14375. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  14376. {
  14377. unsigned long rpi;
  14378. uint16_t max_rpi, rpi_limit;
  14379. uint16_t rpi_remaining, lrpi = 0;
  14380. struct lpfc_rpi_hdr *rpi_hdr;
  14381. unsigned long iflag;
  14382. /*
  14383. * Fetch the next logical rpi. Because this index is logical,
  14384. * the driver starts at 0 each time.
  14385. */
  14386. spin_lock_irqsave(&phba->hbalock, iflag);
  14387. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  14388. rpi_limit = phba->sli4_hba.next_rpi;
  14389. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  14390. if (rpi >= rpi_limit)
  14391. rpi = LPFC_RPI_ALLOC_ERROR;
  14392. else {
  14393. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  14394. phba->sli4_hba.max_cfg_param.rpi_used++;
  14395. phba->sli4_hba.rpi_count++;
  14396. }
  14397. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  14398. "0001 rpi:%x max:%x lim:%x\n",
  14399. (int) rpi, max_rpi, rpi_limit);
  14400. /*
  14401. * Don't try to allocate more rpi header regions if the device limit
  14402. * has been exhausted.
  14403. */
  14404. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  14405. (phba->sli4_hba.rpi_count >= max_rpi)) {
  14406. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14407. return rpi;
  14408. }
  14409. /*
  14410. * RPI header postings are not required for SLI4 ports capable of
  14411. * extents.
  14412. */
  14413. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  14414. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14415. return rpi;
  14416. }
  14417. /*
  14418. * If the driver is running low on rpi resources, allocate another
  14419. * page now. Note that the next_rpi value is used because
  14420. * it represents how many are actually in use whereas max_rpi notes
  14421. * how many are supported max by the device.
  14422. */
  14423. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  14424. spin_unlock_irqrestore(&phba->hbalock, iflag);
  14425. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  14426. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  14427. if (!rpi_hdr) {
  14428. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14429. "2002 Error Could not grow rpi "
  14430. "count\n");
  14431. } else {
  14432. lrpi = rpi_hdr->start_rpi;
  14433. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  14434. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  14435. }
  14436. }
  14437. return rpi;
  14438. }
  14439. /**
  14440. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  14441. * @phba: pointer to lpfc hba data structure.
  14442. *
  14443. * This routine is invoked to release an rpi to the pool of
  14444. * available rpis maintained by the driver.
  14445. **/
  14446. static void
  14447. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  14448. {
  14449. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  14450. phba->sli4_hba.rpi_count--;
  14451. phba->sli4_hba.max_cfg_param.rpi_used--;
  14452. }
  14453. }
  14454. /**
  14455. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  14456. * @phba: pointer to lpfc hba data structure.
  14457. *
  14458. * This routine is invoked to release an rpi to the pool of
  14459. * available rpis maintained by the driver.
  14460. **/
  14461. void
  14462. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  14463. {
  14464. spin_lock_irq(&phba->hbalock);
  14465. __lpfc_sli4_free_rpi(phba, rpi);
  14466. spin_unlock_irq(&phba->hbalock);
  14467. }
  14468. /**
  14469. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  14470. * @phba: pointer to lpfc hba data structure.
  14471. *
  14472. * This routine is invoked to remove the memory region that
  14473. * provided rpi via a bitmask.
  14474. **/
  14475. void
  14476. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  14477. {
  14478. kfree(phba->sli4_hba.rpi_bmask);
  14479. kfree(phba->sli4_hba.rpi_ids);
  14480. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  14481. }
  14482. /**
  14483. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  14484. * @phba: pointer to lpfc hba data structure.
  14485. *
  14486. * This routine is invoked to remove the memory region that
  14487. * provided rpi via a bitmask.
  14488. **/
  14489. int
  14490. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  14491. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  14492. {
  14493. LPFC_MBOXQ_t *mboxq;
  14494. struct lpfc_hba *phba = ndlp->phba;
  14495. int rc;
  14496. /* The port is notified of the header region via a mailbox command. */
  14497. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14498. if (!mboxq)
  14499. return -ENOMEM;
  14500. /* Post all rpi memory regions to the port. */
  14501. lpfc_resume_rpi(mboxq, ndlp);
  14502. if (cmpl) {
  14503. mboxq->mbox_cmpl = cmpl;
  14504. mboxq->context1 = arg;
  14505. mboxq->context2 = ndlp;
  14506. } else
  14507. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14508. mboxq->vport = ndlp->vport;
  14509. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14510. if (rc == MBX_NOT_FINISHED) {
  14511. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14512. "2010 Resume RPI Mailbox failed "
  14513. "status %d, mbxStatus x%x\n", rc,
  14514. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  14515. mempool_free(mboxq, phba->mbox_mem_pool);
  14516. return -EIO;
  14517. }
  14518. return 0;
  14519. }
  14520. /**
  14521. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  14522. * @vport: Pointer to the vport for which the vpi is being initialized
  14523. *
  14524. * This routine is invoked to activate a vpi with the port.
  14525. *
  14526. * Returns:
  14527. * 0 success
  14528. * -Evalue otherwise
  14529. **/
  14530. int
  14531. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  14532. {
  14533. LPFC_MBOXQ_t *mboxq;
  14534. int rc = 0;
  14535. int retval = MBX_SUCCESS;
  14536. uint32_t mbox_tmo;
  14537. struct lpfc_hba *phba = vport->phba;
  14538. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14539. if (!mboxq)
  14540. return -ENOMEM;
  14541. lpfc_init_vpi(phba, mboxq, vport->vpi);
  14542. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  14543. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  14544. if (rc != MBX_SUCCESS) {
  14545. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  14546. "2022 INIT VPI Mailbox failed "
  14547. "status %d, mbxStatus x%x\n", rc,
  14548. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  14549. retval = -EIO;
  14550. }
  14551. if (rc != MBX_TIMEOUT)
  14552. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  14553. return retval;
  14554. }
  14555. /**
  14556. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  14557. * @phba: pointer to lpfc hba data structure.
  14558. * @mboxq: Pointer to mailbox object.
  14559. *
  14560. * This routine is invoked to manually add a single FCF record. The caller
  14561. * must pass a completely initialized FCF_Record. This routine takes
  14562. * care of the nonembedded mailbox operations.
  14563. **/
  14564. static void
  14565. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  14566. {
  14567. void *virt_addr;
  14568. union lpfc_sli4_cfg_shdr *shdr;
  14569. uint32_t shdr_status, shdr_add_status;
  14570. virt_addr = mboxq->sge_array->addr[0];
  14571. /* The IOCTL status is embedded in the mailbox subheader. */
  14572. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  14573. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14574. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14575. if ((shdr_status || shdr_add_status) &&
  14576. (shdr_status != STATUS_FCF_IN_USE))
  14577. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14578. "2558 ADD_FCF_RECORD mailbox failed with "
  14579. "status x%x add_status x%x\n",
  14580. shdr_status, shdr_add_status);
  14581. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14582. }
  14583. /**
  14584. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  14585. * @phba: pointer to lpfc hba data structure.
  14586. * @fcf_record: pointer to the initialized fcf record to add.
  14587. *
  14588. * This routine is invoked to manually add a single FCF record. The caller
  14589. * must pass a completely initialized FCF_Record. This routine takes
  14590. * care of the nonembedded mailbox operations.
  14591. **/
  14592. int
  14593. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  14594. {
  14595. int rc = 0;
  14596. LPFC_MBOXQ_t *mboxq;
  14597. uint8_t *bytep;
  14598. void *virt_addr;
  14599. struct lpfc_mbx_sge sge;
  14600. uint32_t alloc_len, req_len;
  14601. uint32_t fcfindex;
  14602. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14603. if (!mboxq) {
  14604. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14605. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  14606. return -ENOMEM;
  14607. }
  14608. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  14609. sizeof(uint32_t);
  14610. /* Allocate DMA memory and set up the non-embedded mailbox command */
  14611. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  14612. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  14613. req_len, LPFC_SLI4_MBX_NEMBED);
  14614. if (alloc_len < req_len) {
  14615. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14616. "2523 Allocated DMA memory size (x%x) is "
  14617. "less than the requested DMA memory "
  14618. "size (x%x)\n", alloc_len, req_len);
  14619. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14620. return -ENOMEM;
  14621. }
  14622. /*
  14623. * Get the first SGE entry from the non-embedded DMA memory. This
  14624. * routine only uses a single SGE.
  14625. */
  14626. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  14627. virt_addr = mboxq->sge_array->addr[0];
  14628. /*
  14629. * Configure the FCF record for FCFI 0. This is the driver's
  14630. * hardcoded default and gets used in nonFIP mode.
  14631. */
  14632. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  14633. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  14634. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  14635. /*
  14636. * Copy the fcf_index and the FCF Record Data. The data starts after
  14637. * the FCoE header plus word10. The data copy needs to be endian
  14638. * correct.
  14639. */
  14640. bytep += sizeof(uint32_t);
  14641. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  14642. mboxq->vport = phba->pport;
  14643. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  14644. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14645. if (rc == MBX_NOT_FINISHED) {
  14646. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14647. "2515 ADD_FCF_RECORD mailbox failed with "
  14648. "status 0x%x\n", rc);
  14649. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14650. rc = -EIO;
  14651. } else
  14652. rc = 0;
  14653. return rc;
  14654. }
  14655. /**
  14656. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  14657. * @phba: pointer to lpfc hba data structure.
  14658. * @fcf_record: pointer to the fcf record to write the default data.
  14659. * @fcf_index: FCF table entry index.
  14660. *
  14661. * This routine is invoked to build the driver's default FCF record. The
  14662. * values used are hardcoded. This routine handles memory initialization.
  14663. *
  14664. **/
  14665. void
  14666. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  14667. struct fcf_record *fcf_record,
  14668. uint16_t fcf_index)
  14669. {
  14670. memset(fcf_record, 0, sizeof(struct fcf_record));
  14671. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  14672. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  14673. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  14674. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  14675. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  14676. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  14677. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  14678. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  14679. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  14680. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  14681. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  14682. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  14683. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  14684. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  14685. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  14686. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  14687. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  14688. /* Set the VLAN bit map */
  14689. if (phba->valid_vlan) {
  14690. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  14691. = 1 << (phba->vlan_id % 8);
  14692. }
  14693. }
  14694. /**
  14695. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  14696. * @phba: pointer to lpfc hba data structure.
  14697. * @fcf_index: FCF table entry offset.
  14698. *
  14699. * This routine is invoked to scan the entire FCF table by reading FCF
  14700. * record and processing it one at a time starting from the @fcf_index
  14701. * for initial FCF discovery or fast FCF failover rediscovery.
  14702. *
  14703. * Return 0 if the mailbox command is submitted successfully, none 0
  14704. * otherwise.
  14705. **/
  14706. int
  14707. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14708. {
  14709. int rc = 0, error;
  14710. LPFC_MBOXQ_t *mboxq;
  14711. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  14712. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  14713. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14714. if (!mboxq) {
  14715. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14716. "2000 Failed to allocate mbox for "
  14717. "READ_FCF cmd\n");
  14718. error = -ENOMEM;
  14719. goto fail_fcf_scan;
  14720. }
  14721. /* Construct the read FCF record mailbox command */
  14722. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14723. if (rc) {
  14724. error = -EINVAL;
  14725. goto fail_fcf_scan;
  14726. }
  14727. /* Issue the mailbox command asynchronously */
  14728. mboxq->vport = phba->pport;
  14729. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  14730. spin_lock_irq(&phba->hbalock);
  14731. phba->hba_flag |= FCF_TS_INPROG;
  14732. spin_unlock_irq(&phba->hbalock);
  14733. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14734. if (rc == MBX_NOT_FINISHED)
  14735. error = -EIO;
  14736. else {
  14737. /* Reset eligible FCF count for new scan */
  14738. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  14739. phba->fcf.eligible_fcf_cnt = 0;
  14740. error = 0;
  14741. }
  14742. fail_fcf_scan:
  14743. if (error) {
  14744. if (mboxq)
  14745. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14746. /* FCF scan failed, clear FCF_TS_INPROG flag */
  14747. spin_lock_irq(&phba->hbalock);
  14748. phba->hba_flag &= ~FCF_TS_INPROG;
  14749. spin_unlock_irq(&phba->hbalock);
  14750. }
  14751. return error;
  14752. }
  14753. /**
  14754. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  14755. * @phba: pointer to lpfc hba data structure.
  14756. * @fcf_index: FCF table entry offset.
  14757. *
  14758. * This routine is invoked to read an FCF record indicated by @fcf_index
  14759. * and to use it for FLOGI roundrobin FCF failover.
  14760. *
  14761. * Return 0 if the mailbox command is submitted successfully, none 0
  14762. * otherwise.
  14763. **/
  14764. int
  14765. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14766. {
  14767. int rc = 0, error;
  14768. LPFC_MBOXQ_t *mboxq;
  14769. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14770. if (!mboxq) {
  14771. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14772. "2763 Failed to allocate mbox for "
  14773. "READ_FCF cmd\n");
  14774. error = -ENOMEM;
  14775. goto fail_fcf_read;
  14776. }
  14777. /* Construct the read FCF record mailbox command */
  14778. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14779. if (rc) {
  14780. error = -EINVAL;
  14781. goto fail_fcf_read;
  14782. }
  14783. /* Issue the mailbox command asynchronously */
  14784. mboxq->vport = phba->pport;
  14785. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  14786. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14787. if (rc == MBX_NOT_FINISHED)
  14788. error = -EIO;
  14789. else
  14790. error = 0;
  14791. fail_fcf_read:
  14792. if (error && mboxq)
  14793. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14794. return error;
  14795. }
  14796. /**
  14797. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  14798. * @phba: pointer to lpfc hba data structure.
  14799. * @fcf_index: FCF table entry offset.
  14800. *
  14801. * This routine is invoked to read an FCF record indicated by @fcf_index to
  14802. * determine whether it's eligible for FLOGI roundrobin failover list.
  14803. *
  14804. * Return 0 if the mailbox command is submitted successfully, none 0
  14805. * otherwise.
  14806. **/
  14807. int
  14808. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14809. {
  14810. int rc = 0, error;
  14811. LPFC_MBOXQ_t *mboxq;
  14812. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14813. if (!mboxq) {
  14814. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14815. "2758 Failed to allocate mbox for "
  14816. "READ_FCF cmd\n");
  14817. error = -ENOMEM;
  14818. goto fail_fcf_read;
  14819. }
  14820. /* Construct the read FCF record mailbox command */
  14821. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14822. if (rc) {
  14823. error = -EINVAL;
  14824. goto fail_fcf_read;
  14825. }
  14826. /* Issue the mailbox command asynchronously */
  14827. mboxq->vport = phba->pport;
  14828. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  14829. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14830. if (rc == MBX_NOT_FINISHED)
  14831. error = -EIO;
  14832. else
  14833. error = 0;
  14834. fail_fcf_read:
  14835. if (error && mboxq)
  14836. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14837. return error;
  14838. }
  14839. /**
  14840. * lpfc_check_next_fcf_pri_level
  14841. * phba pointer to the lpfc_hba struct for this port.
  14842. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  14843. * routine when the rr_bmask is empty. The FCF indecies are put into the
  14844. * rr_bmask based on their priority level. Starting from the highest priority
  14845. * to the lowest. The most likely FCF candidate will be in the highest
  14846. * priority group. When this routine is called it searches the fcf_pri list for
  14847. * next lowest priority group and repopulates the rr_bmask with only those
  14848. * fcf_indexes.
  14849. * returns:
  14850. * 1=success 0=failure
  14851. **/
  14852. static int
  14853. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  14854. {
  14855. uint16_t next_fcf_pri;
  14856. uint16_t last_index;
  14857. struct lpfc_fcf_pri *fcf_pri;
  14858. int rc;
  14859. int ret = 0;
  14860. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  14861. LPFC_SLI4_FCF_TBL_INDX_MAX);
  14862. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14863. "3060 Last IDX %d\n", last_index);
  14864. /* Verify the priority list has 2 or more entries */
  14865. spin_lock_irq(&phba->hbalock);
  14866. if (list_empty(&phba->fcf.fcf_pri_list) ||
  14867. list_is_singular(&phba->fcf.fcf_pri_list)) {
  14868. spin_unlock_irq(&phba->hbalock);
  14869. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14870. "3061 Last IDX %d\n", last_index);
  14871. return 0; /* Empty rr list */
  14872. }
  14873. spin_unlock_irq(&phba->hbalock);
  14874. next_fcf_pri = 0;
  14875. /*
  14876. * Clear the rr_bmask and set all of the bits that are at this
  14877. * priority.
  14878. */
  14879. memset(phba->fcf.fcf_rr_bmask, 0,
  14880. sizeof(*phba->fcf.fcf_rr_bmask));
  14881. spin_lock_irq(&phba->hbalock);
  14882. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14883. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  14884. continue;
  14885. /*
  14886. * the 1st priority that has not FLOGI failed
  14887. * will be the highest.
  14888. */
  14889. if (!next_fcf_pri)
  14890. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14891. spin_unlock_irq(&phba->hbalock);
  14892. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14893. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14894. fcf_pri->fcf_rec.fcf_index);
  14895. if (rc)
  14896. return 0;
  14897. }
  14898. spin_lock_irq(&phba->hbalock);
  14899. }
  14900. /*
  14901. * if next_fcf_pri was not set above and the list is not empty then
  14902. * we have failed flogis on all of them. So reset flogi failed
  14903. * and start at the beginning.
  14904. */
  14905. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  14906. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14907. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  14908. /*
  14909. * the 1st priority that has not FLOGI failed
  14910. * will be the highest.
  14911. */
  14912. if (!next_fcf_pri)
  14913. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14914. spin_unlock_irq(&phba->hbalock);
  14915. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14916. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14917. fcf_pri->fcf_rec.fcf_index);
  14918. if (rc)
  14919. return 0;
  14920. }
  14921. spin_lock_irq(&phba->hbalock);
  14922. }
  14923. } else
  14924. ret = 1;
  14925. spin_unlock_irq(&phba->hbalock);
  14926. return ret;
  14927. }
  14928. /**
  14929. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  14930. * @phba: pointer to lpfc hba data structure.
  14931. *
  14932. * This routine is to get the next eligible FCF record index in a round
  14933. * robin fashion. If the next eligible FCF record index equals to the
  14934. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  14935. * shall be returned, otherwise, the next eligible FCF record's index
  14936. * shall be returned.
  14937. **/
  14938. uint16_t
  14939. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  14940. {
  14941. uint16_t next_fcf_index;
  14942. initial_priority:
  14943. /* Search start from next bit of currently registered FCF index */
  14944. next_fcf_index = phba->fcf.current_rec.fcf_indx;
  14945. next_priority:
  14946. /* Determine the next fcf index to check */
  14947. next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
  14948. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14949. LPFC_SLI4_FCF_TBL_INDX_MAX,
  14950. next_fcf_index);
  14951. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  14952. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14953. /*
  14954. * If we have wrapped then we need to clear the bits that
  14955. * have been tested so that we can detect when we should
  14956. * change the priority level.
  14957. */
  14958. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14959. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  14960. }
  14961. /* Check roundrobin failover list empty condition */
  14962. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  14963. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  14964. /*
  14965. * If next fcf index is not found check if there are lower
  14966. * Priority level fcf's in the fcf_priority list.
  14967. * Set up the rr_bmask with all of the avaiable fcf bits
  14968. * at that level and continue the selection process.
  14969. */
  14970. if (lpfc_check_next_fcf_pri_level(phba))
  14971. goto initial_priority;
  14972. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14973. "2844 No roundrobin failover FCF available\n");
  14974. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  14975. return LPFC_FCOE_FCF_NEXT_NONE;
  14976. else {
  14977. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14978. "3063 Only FCF available idx %d, flag %x\n",
  14979. next_fcf_index,
  14980. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  14981. return next_fcf_index;
  14982. }
  14983. }
  14984. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  14985. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  14986. LPFC_FCF_FLOGI_FAILED) {
  14987. if (list_is_singular(&phba->fcf.fcf_pri_list))
  14988. return LPFC_FCOE_FCF_NEXT_NONE;
  14989. goto next_priority;
  14990. }
  14991. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14992. "2845 Get next roundrobin failover FCF (x%x)\n",
  14993. next_fcf_index);
  14994. return next_fcf_index;
  14995. }
  14996. /**
  14997. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  14998. * @phba: pointer to lpfc hba data structure.
  14999. *
  15000. * This routine sets the FCF record index in to the eligible bmask for
  15001. * roundrobin failover search. It checks to make sure that the index
  15002. * does not go beyond the range of the driver allocated bmask dimension
  15003. * before setting the bit.
  15004. *
  15005. * Returns 0 if the index bit successfully set, otherwise, it returns
  15006. * -EINVAL.
  15007. **/
  15008. int
  15009. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  15010. {
  15011. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  15012. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15013. "2610 FCF (x%x) reached driver's book "
  15014. "keeping dimension:x%x\n",
  15015. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  15016. return -EINVAL;
  15017. }
  15018. /* Set the eligible FCF record index bmask */
  15019. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  15020. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15021. "2790 Set FCF (x%x) to roundrobin FCF failover "
  15022. "bmask\n", fcf_index);
  15023. return 0;
  15024. }
  15025. /**
  15026. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  15027. * @phba: pointer to lpfc hba data structure.
  15028. *
  15029. * This routine clears the FCF record index from the eligible bmask for
  15030. * roundrobin failover search. It checks to make sure that the index
  15031. * does not go beyond the range of the driver allocated bmask dimension
  15032. * before clearing the bit.
  15033. **/
  15034. void
  15035. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  15036. {
  15037. struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
  15038. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  15039. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15040. "2762 FCF (x%x) reached driver's book "
  15041. "keeping dimension:x%x\n",
  15042. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  15043. return;
  15044. }
  15045. /* Clear the eligible FCF record index bmask */
  15046. spin_lock_irq(&phba->hbalock);
  15047. list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
  15048. list) {
  15049. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  15050. list_del_init(&fcf_pri->list);
  15051. break;
  15052. }
  15053. }
  15054. spin_unlock_irq(&phba->hbalock);
  15055. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  15056. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15057. "2791 Clear FCF (x%x) from roundrobin failover "
  15058. "bmask\n", fcf_index);
  15059. }
  15060. /**
  15061. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  15062. * @phba: pointer to lpfc hba data structure.
  15063. *
  15064. * This routine is the completion routine for the rediscover FCF table mailbox
  15065. * command. If the mailbox command returned failure, it will try to stop the
  15066. * FCF rediscover wait timer.
  15067. **/
  15068. static void
  15069. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  15070. {
  15071. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  15072. uint32_t shdr_status, shdr_add_status;
  15073. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  15074. shdr_status = bf_get(lpfc_mbox_hdr_status,
  15075. &redisc_fcf->header.cfg_shdr.response);
  15076. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  15077. &redisc_fcf->header.cfg_shdr.response);
  15078. if (shdr_status || shdr_add_status) {
  15079. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  15080. "2746 Requesting for FCF rediscovery failed "
  15081. "status x%x add_status x%x\n",
  15082. shdr_status, shdr_add_status);
  15083. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  15084. spin_lock_irq(&phba->hbalock);
  15085. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  15086. spin_unlock_irq(&phba->hbalock);
  15087. /*
  15088. * CVL event triggered FCF rediscover request failed,
  15089. * last resort to re-try current registered FCF entry.
  15090. */
  15091. lpfc_retry_pport_discovery(phba);
  15092. } else {
  15093. spin_lock_irq(&phba->hbalock);
  15094. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  15095. spin_unlock_irq(&phba->hbalock);
  15096. /*
  15097. * DEAD FCF event triggered FCF rediscover request
  15098. * failed, last resort to fail over as a link down
  15099. * to FCF registration.
  15100. */
  15101. lpfc_sli4_fcf_dead_failthrough(phba);
  15102. }
  15103. } else {
  15104. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  15105. "2775 Start FCF rediscover quiescent timer\n");
  15106. /*
  15107. * Start FCF rediscovery wait timer for pending FCF
  15108. * before rescan FCF record table.
  15109. */
  15110. lpfc_fcf_redisc_wait_start_timer(phba);
  15111. }
  15112. mempool_free(mbox, phba->mbox_mem_pool);
  15113. }
  15114. /**
  15115. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  15116. * @phba: pointer to lpfc hba data structure.
  15117. *
  15118. * This routine is invoked to request for rediscovery of the entire FCF table
  15119. * by the port.
  15120. **/
  15121. int
  15122. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  15123. {
  15124. LPFC_MBOXQ_t *mbox;
  15125. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  15126. int rc, length;
  15127. /* Cancel retry delay timers to all vports before FCF rediscover */
  15128. lpfc_cancel_all_vport_retry_delay_timer(phba);
  15129. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15130. if (!mbox) {
  15131. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15132. "2745 Failed to allocate mbox for "
  15133. "requesting FCF rediscover.\n");
  15134. return -ENOMEM;
  15135. }
  15136. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  15137. sizeof(struct lpfc_sli4_cfg_mhdr));
  15138. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  15139. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  15140. length, LPFC_SLI4_MBX_EMBED);
  15141. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  15142. /* Set count to 0 for invalidating the entire FCF database */
  15143. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  15144. /* Issue the mailbox command asynchronously */
  15145. mbox->vport = phba->pport;
  15146. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  15147. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  15148. if (rc == MBX_NOT_FINISHED) {
  15149. mempool_free(mbox, phba->mbox_mem_pool);
  15150. return -EIO;
  15151. }
  15152. return 0;
  15153. }
  15154. /**
  15155. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  15156. * @phba: pointer to lpfc hba data structure.
  15157. *
  15158. * This function is the failover routine as a last resort to the FCF DEAD
  15159. * event when driver failed to perform fast FCF failover.
  15160. **/
  15161. void
  15162. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  15163. {
  15164. uint32_t link_state;
  15165. /*
  15166. * Last resort as FCF DEAD event failover will treat this as
  15167. * a link down, but save the link state because we don't want
  15168. * it to be changed to Link Down unless it is already down.
  15169. */
  15170. link_state = phba->link_state;
  15171. lpfc_linkdown(phba);
  15172. phba->link_state = link_state;
  15173. /* Unregister FCF if no devices connected to it */
  15174. lpfc_unregister_unused_fcf(phba);
  15175. }
  15176. /**
  15177. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  15178. * @phba: pointer to lpfc hba data structure.
  15179. * @rgn23_data: pointer to configure region 23 data.
  15180. *
  15181. * This function gets SLI3 port configure region 23 data through memory dump
  15182. * mailbox command. When it successfully retrieves data, the size of the data
  15183. * will be returned, otherwise, 0 will be returned.
  15184. **/
  15185. static uint32_t
  15186. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  15187. {
  15188. LPFC_MBOXQ_t *pmb = NULL;
  15189. MAILBOX_t *mb;
  15190. uint32_t offset = 0;
  15191. int rc;
  15192. if (!rgn23_data)
  15193. return 0;
  15194. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15195. if (!pmb) {
  15196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15197. "2600 failed to allocate mailbox memory\n");
  15198. return 0;
  15199. }
  15200. mb = &pmb->u.mb;
  15201. do {
  15202. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  15203. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  15204. if (rc != MBX_SUCCESS) {
  15205. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  15206. "2601 failed to read config "
  15207. "region 23, rc 0x%x Status 0x%x\n",
  15208. rc, mb->mbxStatus);
  15209. mb->un.varDmp.word_cnt = 0;
  15210. }
  15211. /*
  15212. * dump mem may return a zero when finished or we got a
  15213. * mailbox error, either way we are done.
  15214. */
  15215. if (mb->un.varDmp.word_cnt == 0)
  15216. break;
  15217. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  15218. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  15219. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  15220. rgn23_data + offset,
  15221. mb->un.varDmp.word_cnt);
  15222. offset += mb->un.varDmp.word_cnt;
  15223. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  15224. mempool_free(pmb, phba->mbox_mem_pool);
  15225. return offset;
  15226. }
  15227. /**
  15228. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  15229. * @phba: pointer to lpfc hba data structure.
  15230. * @rgn23_data: pointer to configure region 23 data.
  15231. *
  15232. * This function gets SLI4 port configure region 23 data through memory dump
  15233. * mailbox command. When it successfully retrieves data, the size of the data
  15234. * will be returned, otherwise, 0 will be returned.
  15235. **/
  15236. static uint32_t
  15237. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  15238. {
  15239. LPFC_MBOXQ_t *mboxq = NULL;
  15240. struct lpfc_dmabuf *mp = NULL;
  15241. struct lpfc_mqe *mqe;
  15242. uint32_t data_length = 0;
  15243. int rc;
  15244. if (!rgn23_data)
  15245. return 0;
  15246. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15247. if (!mboxq) {
  15248. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15249. "3105 failed to allocate mailbox memory\n");
  15250. return 0;
  15251. }
  15252. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  15253. goto out;
  15254. mqe = &mboxq->u.mqe;
  15255. mp = (struct lpfc_dmabuf *) mboxq->context1;
  15256. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  15257. if (rc)
  15258. goto out;
  15259. data_length = mqe->un.mb_words[5];
  15260. if (data_length == 0)
  15261. goto out;
  15262. if (data_length > DMP_RGN23_SIZE) {
  15263. data_length = 0;
  15264. goto out;
  15265. }
  15266. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  15267. out:
  15268. mempool_free(mboxq, phba->mbox_mem_pool);
  15269. if (mp) {
  15270. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  15271. kfree(mp);
  15272. }
  15273. return data_length;
  15274. }
  15275. /**
  15276. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  15277. * @phba: pointer to lpfc hba data structure.
  15278. *
  15279. * This function read region 23 and parse TLV for port status to
  15280. * decide if the user disaled the port. If the TLV indicates the
  15281. * port is disabled, the hba_flag is set accordingly.
  15282. **/
  15283. void
  15284. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  15285. {
  15286. uint8_t *rgn23_data = NULL;
  15287. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  15288. uint32_t offset = 0;
  15289. /* Get adapter Region 23 data */
  15290. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  15291. if (!rgn23_data)
  15292. goto out;
  15293. if (phba->sli_rev < LPFC_SLI_REV4)
  15294. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  15295. else {
  15296. if_type = bf_get(lpfc_sli_intf_if_type,
  15297. &phba->sli4_hba.sli_intf);
  15298. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  15299. goto out;
  15300. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  15301. }
  15302. if (!data_size)
  15303. goto out;
  15304. /* Check the region signature first */
  15305. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  15306. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15307. "2619 Config region 23 has bad signature\n");
  15308. goto out;
  15309. }
  15310. offset += 4;
  15311. /* Check the data structure version */
  15312. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  15313. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15314. "2620 Config region 23 has bad version\n");
  15315. goto out;
  15316. }
  15317. offset += 4;
  15318. /* Parse TLV entries in the region */
  15319. while (offset < data_size) {
  15320. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  15321. break;
  15322. /*
  15323. * If the TLV is not driver specific TLV or driver id is
  15324. * not linux driver id, skip the record.
  15325. */
  15326. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  15327. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  15328. (rgn23_data[offset + 3] != 0)) {
  15329. offset += rgn23_data[offset + 1] * 4 + 4;
  15330. continue;
  15331. }
  15332. /* Driver found a driver specific TLV in the config region */
  15333. sub_tlv_len = rgn23_data[offset + 1] * 4;
  15334. offset += 4;
  15335. tlv_offset = 0;
  15336. /*
  15337. * Search for configured port state sub-TLV.
  15338. */
  15339. while ((offset < data_size) &&
  15340. (tlv_offset < sub_tlv_len)) {
  15341. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  15342. offset += 4;
  15343. tlv_offset += 4;
  15344. break;
  15345. }
  15346. if (rgn23_data[offset] != PORT_STE_TYPE) {
  15347. offset += rgn23_data[offset + 1] * 4 + 4;
  15348. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  15349. continue;
  15350. }
  15351. /* This HBA contains PORT_STE configured */
  15352. if (!rgn23_data[offset + 2])
  15353. phba->hba_flag |= LINK_DISABLED;
  15354. goto out;
  15355. }
  15356. }
  15357. out:
  15358. kfree(rgn23_data);
  15359. return;
  15360. }
  15361. /**
  15362. * lpfc_wr_object - write an object to the firmware
  15363. * @phba: HBA structure that indicates port to create a queue on.
  15364. * @dmabuf_list: list of dmabufs to write to the port.
  15365. * @size: the total byte value of the objects to write to the port.
  15366. * @offset: the current offset to be used to start the transfer.
  15367. *
  15368. * This routine will create a wr_object mailbox command to send to the port.
  15369. * the mailbox command will be constructed using the dma buffers described in
  15370. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  15371. * BDEs that the imbedded mailbox can support. The @offset variable will be
  15372. * used to indicate the starting offset of the transfer and will also return
  15373. * the offset after the write object mailbox has completed. @size is used to
  15374. * determine the end of the object and whether the eof bit should be set.
  15375. *
  15376. * Return 0 is successful and offset will contain the the new offset to use
  15377. * for the next write.
  15378. * Return negative value for error cases.
  15379. **/
  15380. int
  15381. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  15382. uint32_t size, uint32_t *offset)
  15383. {
  15384. struct lpfc_mbx_wr_object *wr_object;
  15385. LPFC_MBOXQ_t *mbox;
  15386. int rc = 0, i = 0;
  15387. uint32_t shdr_status, shdr_add_status;
  15388. uint32_t mbox_tmo;
  15389. union lpfc_sli4_cfg_shdr *shdr;
  15390. struct lpfc_dmabuf *dmabuf;
  15391. uint32_t written = 0;
  15392. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15393. if (!mbox)
  15394. return -ENOMEM;
  15395. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  15396. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  15397. sizeof(struct lpfc_mbx_wr_object) -
  15398. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  15399. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  15400. wr_object->u.request.write_offset = *offset;
  15401. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  15402. wr_object->u.request.object_name[0] =
  15403. cpu_to_le32(wr_object->u.request.object_name[0]);
  15404. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  15405. list_for_each_entry(dmabuf, dmabuf_list, list) {
  15406. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  15407. break;
  15408. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  15409. wr_object->u.request.bde[i].addrHigh =
  15410. putPaddrHigh(dmabuf->phys);
  15411. if (written + SLI4_PAGE_SIZE >= size) {
  15412. wr_object->u.request.bde[i].tus.f.bdeSize =
  15413. (size - written);
  15414. written += (size - written);
  15415. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  15416. } else {
  15417. wr_object->u.request.bde[i].tus.f.bdeSize =
  15418. SLI4_PAGE_SIZE;
  15419. written += SLI4_PAGE_SIZE;
  15420. }
  15421. i++;
  15422. }
  15423. wr_object->u.request.bde_count = i;
  15424. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  15425. if (!phba->sli4_hba.intr_enable)
  15426. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15427. else {
  15428. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  15429. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  15430. }
  15431. /* The IOCTL status is embedded in the mailbox subheader. */
  15432. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  15433. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15434. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15435. if (rc != MBX_TIMEOUT)
  15436. mempool_free(mbox, phba->mbox_mem_pool);
  15437. if (shdr_status || shdr_add_status || rc) {
  15438. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15439. "3025 Write Object mailbox failed with "
  15440. "status x%x add_status x%x, mbx status x%x\n",
  15441. shdr_status, shdr_add_status, rc);
  15442. rc = -ENXIO;
  15443. } else
  15444. *offset += wr_object->u.response.actual_write_length;
  15445. return rc;
  15446. }
  15447. /**
  15448. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  15449. * @vport: pointer to vport data structure.
  15450. *
  15451. * This function iterate through the mailboxq and clean up all REG_LOGIN
  15452. * and REG_VPI mailbox commands associated with the vport. This function
  15453. * is called when driver want to restart discovery of the vport due to
  15454. * a Clear Virtual Link event.
  15455. **/
  15456. void
  15457. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  15458. {
  15459. struct lpfc_hba *phba = vport->phba;
  15460. LPFC_MBOXQ_t *mb, *nextmb;
  15461. struct lpfc_dmabuf *mp;
  15462. struct lpfc_nodelist *ndlp;
  15463. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  15464. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  15465. LIST_HEAD(mbox_cmd_list);
  15466. uint8_t restart_loop;
  15467. /* Clean up internally queued mailbox commands with the vport */
  15468. spin_lock_irq(&phba->hbalock);
  15469. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  15470. if (mb->vport != vport)
  15471. continue;
  15472. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  15473. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  15474. continue;
  15475. list_del(&mb->list);
  15476. list_add_tail(&mb->list, &mbox_cmd_list);
  15477. }
  15478. /* Clean up active mailbox command with the vport */
  15479. mb = phba->sli.mbox_active;
  15480. if (mb && (mb->vport == vport)) {
  15481. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  15482. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  15483. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15484. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15485. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  15486. /* Put reference count for delayed processing */
  15487. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  15488. /* Unregister the RPI when mailbox complete */
  15489. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  15490. }
  15491. }
  15492. /* Cleanup any mailbox completions which are not yet processed */
  15493. do {
  15494. restart_loop = 0;
  15495. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  15496. /*
  15497. * If this mailox is already processed or it is
  15498. * for another vport ignore it.
  15499. */
  15500. if ((mb->vport != vport) ||
  15501. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  15502. continue;
  15503. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  15504. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  15505. continue;
  15506. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15507. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15508. ndlp = (struct lpfc_nodelist *)mb->context2;
  15509. /* Unregister the RPI when mailbox complete */
  15510. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  15511. restart_loop = 1;
  15512. spin_unlock_irq(&phba->hbalock);
  15513. spin_lock(shost->host_lock);
  15514. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15515. spin_unlock(shost->host_lock);
  15516. spin_lock_irq(&phba->hbalock);
  15517. break;
  15518. }
  15519. }
  15520. } while (restart_loop);
  15521. spin_unlock_irq(&phba->hbalock);
  15522. /* Release the cleaned-up mailbox commands */
  15523. while (!list_empty(&mbox_cmd_list)) {
  15524. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  15525. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  15526. mp = (struct lpfc_dmabuf *) (mb->context1);
  15527. if (mp) {
  15528. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  15529. kfree(mp);
  15530. }
  15531. ndlp = (struct lpfc_nodelist *) mb->context2;
  15532. mb->context2 = NULL;
  15533. if (ndlp) {
  15534. spin_lock(shost->host_lock);
  15535. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15536. spin_unlock(shost->host_lock);
  15537. lpfc_nlp_put(ndlp);
  15538. }
  15539. }
  15540. mempool_free(mb, phba->mbox_mem_pool);
  15541. }
  15542. /* Release the ndlp with the cleaned-up active mailbox command */
  15543. if (act_mbx_ndlp) {
  15544. spin_lock(shost->host_lock);
  15545. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  15546. spin_unlock(shost->host_lock);
  15547. lpfc_nlp_put(act_mbx_ndlp);
  15548. }
  15549. }
  15550. /**
  15551. * lpfc_drain_txq - Drain the txq
  15552. * @phba: Pointer to HBA context object.
  15553. *
  15554. * This function attempt to submit IOCBs on the txq
  15555. * to the adapter. For SLI4 adapters, the txq contains
  15556. * ELS IOCBs that have been deferred because the there
  15557. * are no SGLs. This congestion can occur with large
  15558. * vport counts during node discovery.
  15559. **/
  15560. uint32_t
  15561. lpfc_drain_txq(struct lpfc_hba *phba)
  15562. {
  15563. LIST_HEAD(completions);
  15564. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  15565. struct lpfc_iocbq *piocbq = NULL;
  15566. unsigned long iflags = 0;
  15567. char *fail_msg = NULL;
  15568. struct lpfc_sglq *sglq;
  15569. union lpfc_wqe wqe;
  15570. uint32_t txq_cnt = 0;
  15571. spin_lock_irqsave(&pring->ring_lock, iflags);
  15572. list_for_each_entry(piocbq, &pring->txq, list) {
  15573. txq_cnt++;
  15574. }
  15575. if (txq_cnt > pring->txq_max)
  15576. pring->txq_max = txq_cnt;
  15577. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15578. while (!list_empty(&pring->txq)) {
  15579. spin_lock_irqsave(&pring->ring_lock, iflags);
  15580. piocbq = lpfc_sli_ringtx_get(phba, pring);
  15581. if (!piocbq) {
  15582. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15583. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15584. "2823 txq empty and txq_cnt is %d\n ",
  15585. txq_cnt);
  15586. break;
  15587. }
  15588. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  15589. if (!sglq) {
  15590. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  15591. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15592. break;
  15593. }
  15594. txq_cnt--;
  15595. /* The xri and iocb resources secured,
  15596. * attempt to issue request
  15597. */
  15598. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  15599. piocbq->sli4_xritag = sglq->sli4_xritag;
  15600. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  15601. fail_msg = "to convert bpl to sgl";
  15602. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  15603. fail_msg = "to convert iocb to wqe";
  15604. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  15605. fail_msg = " - Wq is full";
  15606. else
  15607. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  15608. if (fail_msg) {
  15609. /* Failed means we can't issue and need to cancel */
  15610. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  15611. "2822 IOCB failed %s iotag 0x%x "
  15612. "xri 0x%x\n",
  15613. fail_msg,
  15614. piocbq->iotag, piocbq->sli4_xritag);
  15615. list_add_tail(&piocbq->list, &completions);
  15616. }
  15617. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  15618. }
  15619. /* Cancel all the IOCBs that cannot be issued */
  15620. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  15621. IOERR_SLI_ABORTED);
  15622. return txq_cnt;
  15623. }