lpfc_sli.c 500 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 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 IOCB_t *
  69. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  70. {
  71. return &iocbq->iocb;
  72. }
  73. /**
  74. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  75. * @q: The Work Queue to operate on.
  76. * @wqe: The work Queue Entry to put on the Work queue.
  77. *
  78. * This routine will copy the contents of @wqe to the next available entry on
  79. * the @q. This function will then ring the Work Queue Doorbell to signal the
  80. * HBA to start processing the Work Queue Entry. This function returns 0 if
  81. * successful. If no entries are available on @q then this function will return
  82. * -ENOMEM.
  83. * The caller is expected to hold the hbalock when calling this routine.
  84. **/
  85. static uint32_t
  86. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  87. {
  88. union lpfc_wqe *temp_wqe;
  89. struct lpfc_register doorbell;
  90. uint32_t host_index;
  91. uint32_t idx;
  92. /* sanity check on queue memory */
  93. if (unlikely(!q))
  94. return -ENOMEM;
  95. temp_wqe = q->qe[q->host_index].wqe;
  96. /* If the host has not yet processed the next entry then we are done */
  97. idx = ((q->host_index + 1) % q->entry_count);
  98. if (idx == q->hba_index) {
  99. q->WQ_overflow++;
  100. return -ENOMEM;
  101. }
  102. q->WQ_posted++;
  103. /* set consumption flag every once in a while */
  104. if (!((q->host_index + 1) % q->entry_repost))
  105. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  106. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  107. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  108. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  109. /* Update the host index before invoking device */
  110. host_index = q->host_index;
  111. q->host_index = idx;
  112. /* Ring Doorbell */
  113. doorbell.word0 = 0;
  114. if (q->db_format == LPFC_DB_LIST_FORMAT) {
  115. bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
  116. bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index);
  117. bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
  118. } else if (q->db_format == LPFC_DB_RING_FORMAT) {
  119. bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
  120. bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
  121. } else {
  122. return -EINVAL;
  123. }
  124. writel(doorbell.word0, q->db_regaddr);
  125. return 0;
  126. }
  127. /**
  128. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  129. * @q: The Work Queue to operate on.
  130. * @index: The index to advance the hba index to.
  131. *
  132. * This routine will update the HBA index of a queue to reflect consumption of
  133. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  134. * an entry the host calls this function to update the queue's internal
  135. * pointers. This routine returns the number of entries that were consumed by
  136. * the HBA.
  137. **/
  138. static uint32_t
  139. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  140. {
  141. uint32_t released = 0;
  142. /* sanity check on queue memory */
  143. if (unlikely(!q))
  144. return 0;
  145. if (q->hba_index == index)
  146. return 0;
  147. do {
  148. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  149. released++;
  150. } while (q->hba_index != index);
  151. return released;
  152. }
  153. /**
  154. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  155. * @q: The Mailbox Queue to operate on.
  156. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  157. *
  158. * This routine will copy the contents of @mqe to the next available entry on
  159. * the @q. This function will then ring the Work Queue Doorbell to signal the
  160. * HBA to start processing the Work Queue Entry. This function returns 0 if
  161. * successful. If no entries are available on @q then this function will return
  162. * -ENOMEM.
  163. * The caller is expected to hold the hbalock when calling this routine.
  164. **/
  165. static uint32_t
  166. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  167. {
  168. struct lpfc_mqe *temp_mqe;
  169. struct lpfc_register doorbell;
  170. uint32_t host_index;
  171. /* sanity check on queue memory */
  172. if (unlikely(!q))
  173. return -ENOMEM;
  174. temp_mqe = q->qe[q->host_index].mqe;
  175. /* If the host has not yet processed the next entry then we are done */
  176. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  177. return -ENOMEM;
  178. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  179. /* Save off the mailbox pointer for completion */
  180. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  181. /* Update the host index before invoking device */
  182. host_index = q->host_index;
  183. q->host_index = ((q->host_index + 1) % q->entry_count);
  184. /* Ring Doorbell */
  185. doorbell.word0 = 0;
  186. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  187. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  188. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  189. return 0;
  190. }
  191. /**
  192. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  193. * @q: The Mailbox Queue to operate on.
  194. *
  195. * This routine will update the HBA index of a queue to reflect consumption of
  196. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  197. * an entry the host calls this function to update the queue's internal
  198. * pointers. This routine returns the number of entries that were consumed by
  199. * the HBA.
  200. **/
  201. static uint32_t
  202. lpfc_sli4_mq_release(struct lpfc_queue *q)
  203. {
  204. /* sanity check on queue memory */
  205. if (unlikely(!q))
  206. return 0;
  207. /* Clear the mailbox pointer for completion */
  208. q->phba->mbox = NULL;
  209. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  210. return 1;
  211. }
  212. /**
  213. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  214. * @q: The Event Queue to get the first valid EQE from
  215. *
  216. * This routine will get the first valid Event Queue Entry from @q, update
  217. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  218. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  219. * processed, but not popped back to the HBA then this routine will return NULL.
  220. **/
  221. static struct lpfc_eqe *
  222. lpfc_sli4_eq_get(struct lpfc_queue *q)
  223. {
  224. struct lpfc_eqe *eqe;
  225. uint32_t idx;
  226. /* sanity check on queue memory */
  227. if (unlikely(!q))
  228. return NULL;
  229. eqe = q->qe[q->hba_index].eqe;
  230. /* If the next EQE is not valid then we are done */
  231. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  232. return NULL;
  233. /* If the host has not yet processed the next entry then we are done */
  234. idx = ((q->hba_index + 1) % q->entry_count);
  235. if (idx == q->host_index)
  236. return NULL;
  237. q->hba_index = idx;
  238. return eqe;
  239. }
  240. /**
  241. * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
  242. * @q: The Event Queue to disable interrupts
  243. *
  244. **/
  245. static inline void
  246. lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
  247. {
  248. struct lpfc_register doorbell;
  249. doorbell.word0 = 0;
  250. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  251. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  252. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  253. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  254. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  255. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  256. }
  257. /**
  258. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  259. * @q: The Event Queue that the host has completed processing for.
  260. * @arm: Indicates whether the host wants to arms this CQ.
  261. *
  262. * This routine will mark all Event Queue Entries on @q, from the last
  263. * known completed entry to the last entry that was processed, as completed
  264. * by clearing the valid bit for each completion queue entry. Then it will
  265. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  266. * The internal host index in the @q will be updated by this routine to indicate
  267. * that the host has finished processing the entries. The @arm parameter
  268. * indicates that the queue should be rearmed when ringing the doorbell.
  269. *
  270. * This function will return the number of EQEs that were popped.
  271. **/
  272. uint32_t
  273. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  274. {
  275. uint32_t released = 0;
  276. struct lpfc_eqe *temp_eqe;
  277. struct lpfc_register doorbell;
  278. /* sanity check on queue memory */
  279. if (unlikely(!q))
  280. return 0;
  281. /* while there are valid entries */
  282. while (q->hba_index != q->host_index) {
  283. temp_eqe = q->qe[q->host_index].eqe;
  284. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  285. released++;
  286. q->host_index = ((q->host_index + 1) % q->entry_count);
  287. }
  288. if (unlikely(released == 0 && !arm))
  289. return 0;
  290. /* ring doorbell for number popped */
  291. doorbell.word0 = 0;
  292. if (arm) {
  293. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  294. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  295. }
  296. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  297. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  298. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  299. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  300. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  301. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  302. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  303. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  304. readl(q->phba->sli4_hba.EQCQDBregaddr);
  305. return released;
  306. }
  307. /**
  308. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  309. * @q: The Completion Queue to get the first valid CQE from
  310. *
  311. * This routine will get the first valid Completion Queue Entry from @q, update
  312. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  313. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  314. * processed, but not popped back to the HBA then this routine will return NULL.
  315. **/
  316. static struct lpfc_cqe *
  317. lpfc_sli4_cq_get(struct lpfc_queue *q)
  318. {
  319. struct lpfc_cqe *cqe;
  320. uint32_t idx;
  321. /* sanity check on queue memory */
  322. if (unlikely(!q))
  323. return NULL;
  324. /* If the next CQE is not valid then we are done */
  325. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  326. return NULL;
  327. /* If the host has not yet processed the next entry then we are done */
  328. idx = ((q->hba_index + 1) % q->entry_count);
  329. if (idx == q->host_index)
  330. return NULL;
  331. cqe = q->qe[q->hba_index].cqe;
  332. q->hba_index = idx;
  333. return cqe;
  334. }
  335. /**
  336. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  337. * @q: The Completion Queue that the host has completed processing for.
  338. * @arm: Indicates whether the host wants to arms this CQ.
  339. *
  340. * This routine will mark all Completion queue entries on @q, from the last
  341. * known completed entry to the last entry that was processed, as completed
  342. * by clearing the valid bit for each completion queue entry. Then it will
  343. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  344. * The internal host index in the @q will be updated by this routine to indicate
  345. * that the host has finished processing the entries. The @arm parameter
  346. * indicates that the queue should be rearmed when ringing the doorbell.
  347. *
  348. * This function will return the number of CQEs that were released.
  349. **/
  350. uint32_t
  351. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  352. {
  353. uint32_t released = 0;
  354. struct lpfc_cqe *temp_qe;
  355. struct lpfc_register doorbell;
  356. /* sanity check on queue memory */
  357. if (unlikely(!q))
  358. return 0;
  359. /* while there are valid entries */
  360. while (q->hba_index != q->host_index) {
  361. temp_qe = q->qe[q->host_index].cqe;
  362. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  363. released++;
  364. q->host_index = ((q->host_index + 1) % q->entry_count);
  365. }
  366. if (unlikely(released == 0 && !arm))
  367. return 0;
  368. /* ring doorbell for number popped */
  369. doorbell.word0 = 0;
  370. if (arm)
  371. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  372. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  373. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  374. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  375. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  376. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  377. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  378. return released;
  379. }
  380. /**
  381. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  382. * @q: The Header Receive Queue to operate on.
  383. * @wqe: The Receive Queue Entry to put on the Receive queue.
  384. *
  385. * This routine will copy the contents of @wqe to the next available entry on
  386. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  387. * HBA to start processing the Receive Queue Entry. This function returns the
  388. * index that the rqe was copied to if successful. If no entries are available
  389. * on @q then this function will return -ENOMEM.
  390. * The caller is expected to hold the hbalock when calling this routine.
  391. **/
  392. static int
  393. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  394. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  395. {
  396. struct lpfc_rqe *temp_hrqe;
  397. struct lpfc_rqe *temp_drqe;
  398. struct lpfc_register doorbell;
  399. int put_index;
  400. /* sanity check on queue memory */
  401. if (unlikely(!hq) || unlikely(!dq))
  402. return -ENOMEM;
  403. put_index = hq->host_index;
  404. temp_hrqe = hq->qe[hq->host_index].rqe;
  405. temp_drqe = dq->qe[dq->host_index].rqe;
  406. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  407. return -EINVAL;
  408. if (hq->host_index != dq->host_index)
  409. return -EINVAL;
  410. /* If the host has not yet processed the next entry then we are done */
  411. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  412. return -EBUSY;
  413. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  414. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  415. /* Update the host index to point to the next slot */
  416. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  417. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  418. /* Ring The Header Receive Queue Doorbell */
  419. if (!(hq->host_index % hq->entry_repost)) {
  420. doorbell.word0 = 0;
  421. if (hq->db_format == LPFC_DB_RING_FORMAT) {
  422. bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
  423. hq->entry_repost);
  424. bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
  425. } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
  426. bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
  427. hq->entry_repost);
  428. bf_set(lpfc_rq_db_list_fm_index, &doorbell,
  429. hq->host_index);
  430. bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
  431. } else {
  432. return -EINVAL;
  433. }
  434. writel(doorbell.word0, hq->db_regaddr);
  435. }
  436. return put_index;
  437. }
  438. /**
  439. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  440. * @q: The Header Receive Queue to operate on.
  441. *
  442. * This routine will update the HBA index of a queue to reflect consumption of
  443. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  444. * consumed an entry the host calls this function to update the queue's
  445. * internal pointers. This routine returns the number of entries that were
  446. * consumed by the HBA.
  447. **/
  448. static uint32_t
  449. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  450. {
  451. /* sanity check on queue memory */
  452. if (unlikely(!hq) || unlikely(!dq))
  453. return 0;
  454. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  455. return 0;
  456. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  457. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  458. return 1;
  459. }
  460. /**
  461. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  462. * @phba: Pointer to HBA context object.
  463. * @pring: Pointer to driver SLI ring object.
  464. *
  465. * This function returns pointer to next command iocb entry
  466. * in the command ring. The caller must hold hbalock to prevent
  467. * other threads consume the next command iocb.
  468. * SLI-2/SLI-3 provide different sized iocbs.
  469. **/
  470. static inline IOCB_t *
  471. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  472. {
  473. return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
  474. pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
  475. }
  476. /**
  477. * lpfc_resp_iocb - Get next response iocb entry in the ring
  478. * @phba: Pointer to HBA context object.
  479. * @pring: Pointer to driver SLI ring object.
  480. *
  481. * This function returns pointer to next response iocb entry
  482. * in the response ring. The caller must hold hbalock to make sure
  483. * that no other thread consume the next response iocb.
  484. * SLI-2/SLI-3 provide different sized iocbs.
  485. **/
  486. static inline IOCB_t *
  487. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  488. {
  489. return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
  490. pring->sli.sli3.rspidx * phba->iocb_rsp_size);
  491. }
  492. /**
  493. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  494. * @phba: Pointer to HBA context object.
  495. *
  496. * This function is called with hbalock held. This function
  497. * allocates a new driver iocb object from the iocb pool. If the
  498. * allocation is successful, it returns pointer to the newly
  499. * allocated iocb object else it returns NULL.
  500. **/
  501. struct lpfc_iocbq *
  502. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  503. {
  504. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  505. struct lpfc_iocbq * iocbq = NULL;
  506. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  507. if (iocbq)
  508. phba->iocb_cnt++;
  509. if (phba->iocb_cnt > phba->iocb_max)
  510. phba->iocb_max = phba->iocb_cnt;
  511. return iocbq;
  512. }
  513. /**
  514. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  515. * @phba: Pointer to HBA context object.
  516. * @xritag: XRI value.
  517. *
  518. * This function clears the sglq pointer from the array of acive
  519. * sglq's. The xritag that is passed in is used to index into the
  520. * array. Before the xritag can be used it needs to be adjusted
  521. * by subtracting the xribase.
  522. *
  523. * Returns sglq ponter = success, NULL = Failure.
  524. **/
  525. static struct lpfc_sglq *
  526. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  527. {
  528. struct lpfc_sglq *sglq;
  529. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  530. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  531. return sglq;
  532. }
  533. /**
  534. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  535. * @phba: Pointer to HBA context object.
  536. * @xritag: XRI value.
  537. *
  538. * This function returns the sglq pointer from the array of acive
  539. * sglq's. The xritag that is passed in is used to index into the
  540. * array. Before the xritag can be used it needs to be adjusted
  541. * by subtracting the xribase.
  542. *
  543. * Returns sglq ponter = success, NULL = Failure.
  544. **/
  545. struct lpfc_sglq *
  546. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  547. {
  548. struct lpfc_sglq *sglq;
  549. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  550. return sglq;
  551. }
  552. /**
  553. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  554. * @phba: Pointer to HBA context object.
  555. * @xritag: xri used in this exchange.
  556. * @rrq: The RRQ to be cleared.
  557. *
  558. **/
  559. void
  560. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  561. uint16_t xritag,
  562. struct lpfc_node_rrq *rrq)
  563. {
  564. struct lpfc_nodelist *ndlp = NULL;
  565. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  566. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  567. /* The target DID could have been swapped (cable swap)
  568. * we should use the ndlp from the findnode if it is
  569. * available.
  570. */
  571. if ((!ndlp) && rrq->ndlp)
  572. ndlp = rrq->ndlp;
  573. if (!ndlp)
  574. goto out;
  575. if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
  576. rrq->send_rrq = 0;
  577. rrq->xritag = 0;
  578. rrq->rrq_stop_time = 0;
  579. }
  580. out:
  581. mempool_free(rrq, phba->rrq_pool);
  582. }
  583. /**
  584. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  585. * @phba: Pointer to HBA context object.
  586. *
  587. * This function is called with hbalock held. This function
  588. * Checks if stop_time (ratov from setting rrq active) has
  589. * been reached, if it has and the send_rrq flag is set then
  590. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  591. * then it will just call the routine to clear the rrq and
  592. * free the rrq resource.
  593. * The timer is set to the next rrq that is going to expire before
  594. * leaving the routine.
  595. *
  596. **/
  597. void
  598. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  599. {
  600. struct lpfc_node_rrq *rrq;
  601. struct lpfc_node_rrq *nextrrq;
  602. unsigned long next_time;
  603. unsigned long iflags;
  604. LIST_HEAD(send_rrq);
  605. spin_lock_irqsave(&phba->hbalock, iflags);
  606. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  607. next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  608. list_for_each_entry_safe(rrq, nextrrq,
  609. &phba->active_rrq_list, list) {
  610. if (time_after(jiffies, rrq->rrq_stop_time))
  611. list_move(&rrq->list, &send_rrq);
  612. else if (time_before(rrq->rrq_stop_time, next_time))
  613. next_time = rrq->rrq_stop_time;
  614. }
  615. spin_unlock_irqrestore(&phba->hbalock, iflags);
  616. if (!list_empty(&phba->active_rrq_list))
  617. mod_timer(&phba->rrq_tmr, next_time);
  618. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  619. list_del(&rrq->list);
  620. if (!rrq->send_rrq)
  621. /* this call will free the rrq */
  622. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  623. else if (lpfc_send_rrq(phba, rrq)) {
  624. /* if we send the rrq then the completion handler
  625. * will clear the bit in the xribitmap.
  626. */
  627. lpfc_clr_rrq_active(phba, rrq->xritag,
  628. rrq);
  629. }
  630. }
  631. }
  632. /**
  633. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  634. * @vport: Pointer to vport context object.
  635. * @xri: The xri used in the exchange.
  636. * @did: The targets DID for this exchange.
  637. *
  638. * returns NULL = rrq not found in the phba->active_rrq_list.
  639. * rrq = rrq for this xri and target.
  640. **/
  641. struct lpfc_node_rrq *
  642. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  643. {
  644. struct lpfc_hba *phba = vport->phba;
  645. struct lpfc_node_rrq *rrq;
  646. struct lpfc_node_rrq *nextrrq;
  647. unsigned long iflags;
  648. if (phba->sli_rev != LPFC_SLI_REV4)
  649. return NULL;
  650. spin_lock_irqsave(&phba->hbalock, iflags);
  651. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  652. if (rrq->vport == vport && rrq->xritag == xri &&
  653. rrq->nlp_DID == did){
  654. list_del(&rrq->list);
  655. spin_unlock_irqrestore(&phba->hbalock, iflags);
  656. return rrq;
  657. }
  658. }
  659. spin_unlock_irqrestore(&phba->hbalock, iflags);
  660. return NULL;
  661. }
  662. /**
  663. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  664. * @vport: Pointer to vport context object.
  665. * @ndlp: Pointer to the lpfc_node_list structure.
  666. * If ndlp is NULL Remove all active RRQs for this vport from the
  667. * phba->active_rrq_list and clear the rrq.
  668. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  669. **/
  670. void
  671. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  672. {
  673. struct lpfc_hba *phba = vport->phba;
  674. struct lpfc_node_rrq *rrq;
  675. struct lpfc_node_rrq *nextrrq;
  676. unsigned long iflags;
  677. LIST_HEAD(rrq_list);
  678. if (phba->sli_rev != LPFC_SLI_REV4)
  679. return;
  680. if (!ndlp) {
  681. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  682. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  683. }
  684. spin_lock_irqsave(&phba->hbalock, iflags);
  685. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  686. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  687. list_move(&rrq->list, &rrq_list);
  688. spin_unlock_irqrestore(&phba->hbalock, iflags);
  689. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  690. list_del(&rrq->list);
  691. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  692. }
  693. }
  694. /**
  695. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  696. * @phba: Pointer to HBA context object.
  697. *
  698. * Remove all rrqs from the phba->active_rrq_list and free them by
  699. * calling __lpfc_clr_active_rrq
  700. *
  701. **/
  702. void
  703. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  704. {
  705. struct lpfc_node_rrq *rrq;
  706. struct lpfc_node_rrq *nextrrq;
  707. unsigned long next_time;
  708. unsigned long iflags;
  709. LIST_HEAD(rrq_list);
  710. if (phba->sli_rev != LPFC_SLI_REV4)
  711. return;
  712. spin_lock_irqsave(&phba->hbalock, iflags);
  713. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  714. next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2));
  715. list_splice_init(&phba->active_rrq_list, &rrq_list);
  716. spin_unlock_irqrestore(&phba->hbalock, iflags);
  717. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  718. list_del(&rrq->list);
  719. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  720. }
  721. if (!list_empty(&phba->active_rrq_list))
  722. mod_timer(&phba->rrq_tmr, next_time);
  723. }
  724. /**
  725. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  726. * @phba: Pointer to HBA context object.
  727. * @ndlp: Targets nodelist pointer for this exchange.
  728. * @xritag the xri in the bitmap to test.
  729. *
  730. * This function is called with hbalock held. This function
  731. * returns 0 = rrq not active for this xri
  732. * 1 = rrq is valid for this xri.
  733. **/
  734. int
  735. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  736. uint16_t xritag)
  737. {
  738. if (!ndlp)
  739. return 0;
  740. if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  741. return 1;
  742. else
  743. return 0;
  744. }
  745. /**
  746. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  747. * @phba: Pointer to HBA context object.
  748. * @ndlp: nodelist pointer for this target.
  749. * @xritag: xri used in this exchange.
  750. * @rxid: Remote Exchange ID.
  751. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  752. *
  753. * This function takes the hbalock.
  754. * The active bit is always set in the active rrq xri_bitmap even
  755. * if there is no slot avaiable for the other rrq information.
  756. *
  757. * returns 0 rrq actived for this xri
  758. * < 0 No memory or invalid ndlp.
  759. **/
  760. int
  761. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  762. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  763. {
  764. unsigned long iflags;
  765. struct lpfc_node_rrq *rrq;
  766. int empty;
  767. if (!ndlp)
  768. return -EINVAL;
  769. if (!phba->cfg_enable_rrq)
  770. return -EINVAL;
  771. spin_lock_irqsave(&phba->hbalock, iflags);
  772. if (phba->pport->load_flag & FC_UNLOADING) {
  773. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  774. goto out;
  775. }
  776. /*
  777. * set the active bit even if there is no mem available.
  778. */
  779. if (NLP_CHK_FREE_REQ(ndlp))
  780. goto out;
  781. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  782. goto out;
  783. if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  784. goto out;
  785. spin_unlock_irqrestore(&phba->hbalock, iflags);
  786. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  787. if (!rrq) {
  788. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  789. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  790. " DID:0x%x Send:%d\n",
  791. xritag, rxid, ndlp->nlp_DID, send_rrq);
  792. return -EINVAL;
  793. }
  794. if (phba->cfg_enable_rrq == 1)
  795. rrq->send_rrq = send_rrq;
  796. else
  797. rrq->send_rrq = 0;
  798. rrq->xritag = xritag;
  799. rrq->rrq_stop_time = jiffies +
  800. msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  801. rrq->ndlp = ndlp;
  802. rrq->nlp_DID = ndlp->nlp_DID;
  803. rrq->vport = ndlp->vport;
  804. rrq->rxid = rxid;
  805. spin_lock_irqsave(&phba->hbalock, iflags);
  806. empty = list_empty(&phba->active_rrq_list);
  807. list_add_tail(&rrq->list, &phba->active_rrq_list);
  808. phba->hba_flag |= HBA_RRQ_ACTIVE;
  809. if (empty)
  810. lpfc_worker_wake_up(phba);
  811. spin_unlock_irqrestore(&phba->hbalock, iflags);
  812. return 0;
  813. out:
  814. spin_unlock_irqrestore(&phba->hbalock, iflags);
  815. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  816. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  817. " DID:0x%x Send:%d\n",
  818. xritag, rxid, ndlp->nlp_DID, send_rrq);
  819. return -EINVAL;
  820. }
  821. /**
  822. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  823. * @phba: Pointer to HBA context object.
  824. * @piocb: Pointer to the iocbq.
  825. *
  826. * This function is called with hbalock held. This function
  827. * gets a new driver sglq object from the sglq list. If the
  828. * list is not empty then it is successful, it returns pointer to the newly
  829. * allocated sglq object else it returns NULL.
  830. **/
  831. static struct lpfc_sglq *
  832. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  833. {
  834. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  835. struct lpfc_sglq *sglq = NULL;
  836. struct lpfc_sglq *start_sglq = NULL;
  837. struct lpfc_scsi_buf *lpfc_cmd;
  838. struct lpfc_nodelist *ndlp;
  839. int found = 0;
  840. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  841. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  842. ndlp = lpfc_cmd->rdata->pnode;
  843. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  844. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  845. ndlp = piocbq->context_un.ndlp;
  846. else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) &&
  847. (piocbq->iocb_flag & LPFC_IO_LIBDFC))
  848. ndlp = piocbq->context_un.ndlp;
  849. else
  850. ndlp = piocbq->context1;
  851. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  852. start_sglq = sglq;
  853. while (!found) {
  854. if (!sglq)
  855. return NULL;
  856. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
  857. /* This xri has an rrq outstanding for this DID.
  858. * put it back in the list and get another xri.
  859. */
  860. list_add_tail(&sglq->list, lpfc_sgl_list);
  861. sglq = NULL;
  862. list_remove_head(lpfc_sgl_list, sglq,
  863. struct lpfc_sglq, list);
  864. if (sglq == start_sglq) {
  865. sglq = NULL;
  866. break;
  867. } else
  868. continue;
  869. }
  870. sglq->ndlp = ndlp;
  871. found = 1;
  872. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  873. sglq->state = SGL_ALLOCATED;
  874. }
  875. return sglq;
  876. }
  877. /**
  878. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  879. * @phba: Pointer to HBA context object.
  880. *
  881. * This function is called with no lock held. This function
  882. * allocates a new driver iocb object from the iocb pool. If the
  883. * allocation is successful, it returns pointer to the newly
  884. * allocated iocb object else it returns NULL.
  885. **/
  886. struct lpfc_iocbq *
  887. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  888. {
  889. struct lpfc_iocbq * iocbq = NULL;
  890. unsigned long iflags;
  891. spin_lock_irqsave(&phba->hbalock, iflags);
  892. iocbq = __lpfc_sli_get_iocbq(phba);
  893. spin_unlock_irqrestore(&phba->hbalock, iflags);
  894. return iocbq;
  895. }
  896. /**
  897. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  898. * @phba: Pointer to HBA context object.
  899. * @iocbq: Pointer to driver iocb object.
  900. *
  901. * This function is called with hbalock held to release driver
  902. * iocb object to the iocb pool. The iotag in the iocb object
  903. * does not change for each use of the iocb object. This function
  904. * clears all other fields of the iocb object when it is freed.
  905. * The sqlq structure that holds the xritag and phys and virtual
  906. * mappings for the scatter gather list is retrieved from the
  907. * active array of sglq. The get of the sglq pointer also clears
  908. * the entry in the array. If the status of the IO indiactes that
  909. * this IO was aborted then the sglq entry it put on the
  910. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  911. * IO has good status or fails for any other reason then the sglq
  912. * entry is added to the free list (lpfc_sgl_list).
  913. **/
  914. static void
  915. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  916. {
  917. struct lpfc_sglq *sglq;
  918. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  919. unsigned long iflag = 0;
  920. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  921. if (iocbq->sli4_xritag == NO_XRI)
  922. sglq = NULL;
  923. else
  924. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  925. /*
  926. ** This should have been removed from the txcmplq before calling
  927. ** iocbq_release. The normal completion
  928. ** path should have already done the list_del_init.
  929. */
  930. if (unlikely(!list_empty(&iocbq->list))) {
  931. if (iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)
  932. iocbq->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  933. list_del_init(&iocbq->list);
  934. }
  935. if (sglq) {
  936. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  937. (sglq->state != SGL_XRI_ABORTED)) {
  938. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  939. iflag);
  940. list_add(&sglq->list,
  941. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  942. spin_unlock_irqrestore(
  943. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  944. } else {
  945. sglq->state = SGL_FREED;
  946. sglq->ndlp = NULL;
  947. list_add_tail(&sglq->list,
  948. &phba->sli4_hba.lpfc_sgl_list);
  949. /* Check if TXQ queue needs to be serviced */
  950. if (!list_empty(&pring->txq))
  951. lpfc_worker_wake_up(phba);
  952. }
  953. }
  954. /*
  955. * Clean all volatile data fields, preserve iotag and node struct.
  956. */
  957. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  958. iocbq->sli4_lxritag = NO_XRI;
  959. iocbq->sli4_xritag = NO_XRI;
  960. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  961. }
  962. /**
  963. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  964. * @phba: Pointer to HBA context object.
  965. * @iocbq: Pointer to driver iocb object.
  966. *
  967. * This function is called with hbalock held to release driver
  968. * iocb object to the iocb pool. The iotag in the iocb object
  969. * does not change for each use of the iocb object. This function
  970. * clears all other fields of the iocb object when it is freed.
  971. **/
  972. static void
  973. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  974. {
  975. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  976. /*
  977. ** This should have been removed from the txcmplq before calling
  978. ** iocbq_release. The normal completion
  979. ** path should have already done the list_del_init.
  980. */
  981. if (unlikely(!list_empty(&iocbq->list)))
  982. list_del_init(&iocbq->list);
  983. /*
  984. * Clean all volatile data fields, preserve iotag and node struct.
  985. */
  986. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  987. iocbq->sli4_xritag = NO_XRI;
  988. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  989. }
  990. /**
  991. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  992. * @phba: Pointer to HBA context object.
  993. * @iocbq: Pointer to driver iocb object.
  994. *
  995. * This function is called with hbalock held to release driver
  996. * iocb object to the iocb pool. The iotag in the iocb object
  997. * does not change for each use of the iocb object. This function
  998. * clears all other fields of the iocb object when it is freed.
  999. **/
  1000. static void
  1001. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1002. {
  1003. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  1004. phba->iocb_cnt--;
  1005. }
  1006. /**
  1007. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  1008. * @phba: Pointer to HBA context object.
  1009. * @iocbq: Pointer to driver iocb object.
  1010. *
  1011. * This function is called with no lock held to release the iocb to
  1012. * iocb pool.
  1013. **/
  1014. void
  1015. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1016. {
  1017. unsigned long iflags;
  1018. /*
  1019. * Clean all volatile data fields, preserve iotag and node struct.
  1020. */
  1021. spin_lock_irqsave(&phba->hbalock, iflags);
  1022. __lpfc_sli_release_iocbq(phba, iocbq);
  1023. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1024. }
  1025. /**
  1026. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  1027. * @phba: Pointer to HBA context object.
  1028. * @iocblist: List of IOCBs.
  1029. * @ulpstatus: ULP status in IOCB command field.
  1030. * @ulpWord4: ULP word-4 in IOCB command field.
  1031. *
  1032. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  1033. * on the list by invoking the complete callback function associated with the
  1034. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  1035. * fields.
  1036. **/
  1037. void
  1038. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  1039. uint32_t ulpstatus, uint32_t ulpWord4)
  1040. {
  1041. struct lpfc_iocbq *piocb;
  1042. while (!list_empty(iocblist)) {
  1043. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  1044. if (!piocb->iocb_cmpl)
  1045. lpfc_sli_release_iocbq(phba, piocb);
  1046. else {
  1047. piocb->iocb.ulpStatus = ulpstatus;
  1048. piocb->iocb.un.ulpWord[4] = ulpWord4;
  1049. (piocb->iocb_cmpl) (phba, piocb, piocb);
  1050. }
  1051. }
  1052. return;
  1053. }
  1054. /**
  1055. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1056. * @iocb_cmnd: iocb command code.
  1057. *
  1058. * This function is called by ring event handler function to get the iocb type.
  1059. * This function translates the iocb command to an iocb command type used to
  1060. * decide the final disposition of each completed IOCB.
  1061. * The function returns
  1062. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1063. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1064. * LPFC_ABORT_IOCB if it is an abort iocb
  1065. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1066. *
  1067. * The caller is not required to hold any lock.
  1068. **/
  1069. static lpfc_iocb_type
  1070. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1071. {
  1072. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1073. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1074. return 0;
  1075. switch (iocb_cmnd) {
  1076. case CMD_XMIT_SEQUENCE_CR:
  1077. case CMD_XMIT_SEQUENCE_CX:
  1078. case CMD_XMIT_BCAST_CN:
  1079. case CMD_XMIT_BCAST_CX:
  1080. case CMD_ELS_REQUEST_CR:
  1081. case CMD_ELS_REQUEST_CX:
  1082. case CMD_CREATE_XRI_CR:
  1083. case CMD_CREATE_XRI_CX:
  1084. case CMD_GET_RPI_CN:
  1085. case CMD_XMIT_ELS_RSP_CX:
  1086. case CMD_GET_RPI_CR:
  1087. case CMD_FCP_IWRITE_CR:
  1088. case CMD_FCP_IWRITE_CX:
  1089. case CMD_FCP_IREAD_CR:
  1090. case CMD_FCP_IREAD_CX:
  1091. case CMD_FCP_ICMND_CR:
  1092. case CMD_FCP_ICMND_CX:
  1093. case CMD_FCP_TSEND_CX:
  1094. case CMD_FCP_TRSP_CX:
  1095. case CMD_FCP_TRECEIVE_CX:
  1096. case CMD_FCP_AUTO_TRSP_CX:
  1097. case CMD_ADAPTER_MSG:
  1098. case CMD_ADAPTER_DUMP:
  1099. case CMD_XMIT_SEQUENCE64_CR:
  1100. case CMD_XMIT_SEQUENCE64_CX:
  1101. case CMD_XMIT_BCAST64_CN:
  1102. case CMD_XMIT_BCAST64_CX:
  1103. case CMD_ELS_REQUEST64_CR:
  1104. case CMD_ELS_REQUEST64_CX:
  1105. case CMD_FCP_IWRITE64_CR:
  1106. case CMD_FCP_IWRITE64_CX:
  1107. case CMD_FCP_IREAD64_CR:
  1108. case CMD_FCP_IREAD64_CX:
  1109. case CMD_FCP_ICMND64_CR:
  1110. case CMD_FCP_ICMND64_CX:
  1111. case CMD_FCP_TSEND64_CX:
  1112. case CMD_FCP_TRSP64_CX:
  1113. case CMD_FCP_TRECEIVE64_CX:
  1114. case CMD_GEN_REQUEST64_CR:
  1115. case CMD_GEN_REQUEST64_CX:
  1116. case CMD_XMIT_ELS_RSP64_CX:
  1117. case DSSCMD_IWRITE64_CR:
  1118. case DSSCMD_IWRITE64_CX:
  1119. case DSSCMD_IREAD64_CR:
  1120. case DSSCMD_IREAD64_CX:
  1121. type = LPFC_SOL_IOCB;
  1122. break;
  1123. case CMD_ABORT_XRI_CN:
  1124. case CMD_ABORT_XRI_CX:
  1125. case CMD_CLOSE_XRI_CN:
  1126. case CMD_CLOSE_XRI_CX:
  1127. case CMD_XRI_ABORTED_CX:
  1128. case CMD_ABORT_MXRI64_CN:
  1129. case CMD_XMIT_BLS_RSP64_CX:
  1130. type = LPFC_ABORT_IOCB;
  1131. break;
  1132. case CMD_RCV_SEQUENCE_CX:
  1133. case CMD_RCV_ELS_REQ_CX:
  1134. case CMD_RCV_SEQUENCE64_CX:
  1135. case CMD_RCV_ELS_REQ64_CX:
  1136. case CMD_ASYNC_STATUS:
  1137. case CMD_IOCB_RCV_SEQ64_CX:
  1138. case CMD_IOCB_RCV_ELS64_CX:
  1139. case CMD_IOCB_RCV_CONT64_CX:
  1140. case CMD_IOCB_RET_XRI64_CX:
  1141. type = LPFC_UNSOL_IOCB;
  1142. break;
  1143. case CMD_IOCB_XMIT_MSEQ64_CR:
  1144. case CMD_IOCB_XMIT_MSEQ64_CX:
  1145. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1146. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1147. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1148. case CMD_IOCB_ABORT_EXTENDED_CN:
  1149. case CMD_IOCB_RET_HBQE64_CN:
  1150. case CMD_IOCB_FCP_IBIDIR64_CR:
  1151. case CMD_IOCB_FCP_IBIDIR64_CX:
  1152. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1153. case CMD_IOCB_LOGENTRY_CN:
  1154. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1155. printk("%s - Unhandled SLI-3 Command x%x\n",
  1156. __func__, iocb_cmnd);
  1157. type = LPFC_UNKNOWN_IOCB;
  1158. break;
  1159. default:
  1160. type = LPFC_UNKNOWN_IOCB;
  1161. break;
  1162. }
  1163. return type;
  1164. }
  1165. /**
  1166. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1167. * @phba: Pointer to HBA context object.
  1168. *
  1169. * This function is called from SLI initialization code
  1170. * to configure every ring of the HBA's SLI interface. The
  1171. * caller is not required to hold any lock. This function issues
  1172. * a config_ring mailbox command for each ring.
  1173. * This function returns zero if successful else returns a negative
  1174. * error code.
  1175. **/
  1176. static int
  1177. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1178. {
  1179. struct lpfc_sli *psli = &phba->sli;
  1180. LPFC_MBOXQ_t *pmb;
  1181. MAILBOX_t *pmbox;
  1182. int i, rc, ret = 0;
  1183. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1184. if (!pmb)
  1185. return -ENOMEM;
  1186. pmbox = &pmb->u.mb;
  1187. phba->link_state = LPFC_INIT_MBX_CMDS;
  1188. for (i = 0; i < psli->num_rings; i++) {
  1189. lpfc_config_ring(phba, i, pmb);
  1190. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1191. if (rc != MBX_SUCCESS) {
  1192. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1193. "0446 Adapter failed to init (%d), "
  1194. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1195. "ring %d\n",
  1196. rc, pmbox->mbxCommand,
  1197. pmbox->mbxStatus, i);
  1198. phba->link_state = LPFC_HBA_ERROR;
  1199. ret = -ENXIO;
  1200. break;
  1201. }
  1202. }
  1203. mempool_free(pmb, phba->mbox_mem_pool);
  1204. return ret;
  1205. }
  1206. /**
  1207. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1208. * @phba: Pointer to HBA context object.
  1209. * @pring: Pointer to driver SLI ring object.
  1210. * @piocb: Pointer to the driver iocb object.
  1211. *
  1212. * This function is called with hbalock held. The function adds the
  1213. * new iocb to txcmplq of the given ring. This function always returns
  1214. * 0. If this function is called for ELS ring, this function checks if
  1215. * there is a vport associated with the ELS command. This function also
  1216. * starts els_tmofunc timer if this is an ELS command.
  1217. **/
  1218. static int
  1219. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1220. struct lpfc_iocbq *piocb)
  1221. {
  1222. list_add_tail(&piocb->list, &pring->txcmplq);
  1223. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1224. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1225. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1226. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1227. if (!piocb->vport)
  1228. BUG();
  1229. else
  1230. mod_timer(&piocb->vport->els_tmofunc,
  1231. jiffies +
  1232. msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
  1233. }
  1234. return 0;
  1235. }
  1236. /**
  1237. * lpfc_sli_ringtx_get - Get first element of the txq
  1238. * @phba: Pointer to HBA context object.
  1239. * @pring: Pointer to driver SLI ring object.
  1240. *
  1241. * This function is called with hbalock held to get next
  1242. * iocb in txq of the given ring. If there is any iocb in
  1243. * the txq, the function returns first iocb in the list after
  1244. * removing the iocb from the list, else it returns NULL.
  1245. **/
  1246. struct lpfc_iocbq *
  1247. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1248. {
  1249. struct lpfc_iocbq *cmd_iocb;
  1250. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1251. return cmd_iocb;
  1252. }
  1253. /**
  1254. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1255. * @phba: Pointer to HBA context object.
  1256. * @pring: Pointer to driver SLI ring object.
  1257. *
  1258. * This function is called with hbalock held and the caller must post the
  1259. * iocb without releasing the lock. If the caller releases the lock,
  1260. * iocb slot returned by the function is not guaranteed to be available.
  1261. * The function returns pointer to the next available iocb slot if there
  1262. * is available slot in the ring, else it returns NULL.
  1263. * If the get index of the ring is ahead of the put index, the function
  1264. * will post an error attention event to the worker thread to take the
  1265. * HBA to offline state.
  1266. **/
  1267. static IOCB_t *
  1268. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1269. {
  1270. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1271. uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
  1272. if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
  1273. (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
  1274. pring->sli.sli3.next_cmdidx = 0;
  1275. if (unlikely(pring->sli.sli3.local_getidx ==
  1276. pring->sli.sli3.next_cmdidx)) {
  1277. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1278. if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
  1279. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1280. "0315 Ring %d issue: portCmdGet %d "
  1281. "is bigger than cmd ring %d\n",
  1282. pring->ringno,
  1283. pring->sli.sli3.local_getidx,
  1284. max_cmd_idx);
  1285. phba->link_state = LPFC_HBA_ERROR;
  1286. /*
  1287. * All error attention handlers are posted to
  1288. * worker thread
  1289. */
  1290. phba->work_ha |= HA_ERATT;
  1291. phba->work_hs = HS_FFER3;
  1292. lpfc_worker_wake_up(phba);
  1293. return NULL;
  1294. }
  1295. if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
  1296. return NULL;
  1297. }
  1298. return lpfc_cmd_iocb(phba, pring);
  1299. }
  1300. /**
  1301. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1302. * @phba: Pointer to HBA context object.
  1303. * @iocbq: Pointer to driver iocb object.
  1304. *
  1305. * This function gets an iotag for the iocb. If there is no unused iotag and
  1306. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1307. * array and assigns a new iotag.
  1308. * The function returns the allocated iotag if successful, else returns zero.
  1309. * Zero is not a valid iotag.
  1310. * The caller is not required to hold any lock.
  1311. **/
  1312. uint16_t
  1313. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1314. {
  1315. struct lpfc_iocbq **new_arr;
  1316. struct lpfc_iocbq **old_arr;
  1317. size_t new_len;
  1318. struct lpfc_sli *psli = &phba->sli;
  1319. uint16_t iotag;
  1320. spin_lock_irq(&phba->hbalock);
  1321. iotag = psli->last_iotag;
  1322. if(++iotag < psli->iocbq_lookup_len) {
  1323. psli->last_iotag = iotag;
  1324. psli->iocbq_lookup[iotag] = iocbq;
  1325. spin_unlock_irq(&phba->hbalock);
  1326. iocbq->iotag = iotag;
  1327. return iotag;
  1328. } else if (psli->iocbq_lookup_len < (0xffff
  1329. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1330. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1331. spin_unlock_irq(&phba->hbalock);
  1332. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1333. GFP_KERNEL);
  1334. if (new_arr) {
  1335. spin_lock_irq(&phba->hbalock);
  1336. old_arr = psli->iocbq_lookup;
  1337. if (new_len <= psli->iocbq_lookup_len) {
  1338. /* highly unprobable case */
  1339. kfree(new_arr);
  1340. iotag = psli->last_iotag;
  1341. if(++iotag < psli->iocbq_lookup_len) {
  1342. psli->last_iotag = iotag;
  1343. psli->iocbq_lookup[iotag] = iocbq;
  1344. spin_unlock_irq(&phba->hbalock);
  1345. iocbq->iotag = iotag;
  1346. return iotag;
  1347. }
  1348. spin_unlock_irq(&phba->hbalock);
  1349. return 0;
  1350. }
  1351. if (psli->iocbq_lookup)
  1352. memcpy(new_arr, old_arr,
  1353. ((psli->last_iotag + 1) *
  1354. sizeof (struct lpfc_iocbq *)));
  1355. psli->iocbq_lookup = new_arr;
  1356. psli->iocbq_lookup_len = new_len;
  1357. psli->last_iotag = iotag;
  1358. psli->iocbq_lookup[iotag] = iocbq;
  1359. spin_unlock_irq(&phba->hbalock);
  1360. iocbq->iotag = iotag;
  1361. kfree(old_arr);
  1362. return iotag;
  1363. }
  1364. } else
  1365. spin_unlock_irq(&phba->hbalock);
  1366. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1367. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1368. psli->last_iotag);
  1369. return 0;
  1370. }
  1371. /**
  1372. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1373. * @phba: Pointer to HBA context object.
  1374. * @pring: Pointer to driver SLI ring object.
  1375. * @iocb: Pointer to iocb slot in the ring.
  1376. * @nextiocb: Pointer to driver iocb object which need to be
  1377. * posted to firmware.
  1378. *
  1379. * This function is called with hbalock held to post a new iocb to
  1380. * the firmware. This function copies the new iocb to ring iocb slot and
  1381. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1382. * a completion call back for this iocb else the function will free the
  1383. * iocb object.
  1384. **/
  1385. static void
  1386. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1387. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1388. {
  1389. /*
  1390. * Set up an iotag
  1391. */
  1392. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1393. if (pring->ringno == LPFC_ELS_RING) {
  1394. lpfc_debugfs_slow_ring_trc(phba,
  1395. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1396. *(((uint32_t *) &nextiocb->iocb) + 4),
  1397. *(((uint32_t *) &nextiocb->iocb) + 6),
  1398. *(((uint32_t *) &nextiocb->iocb) + 7));
  1399. }
  1400. /*
  1401. * Issue iocb command to adapter
  1402. */
  1403. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1404. wmb();
  1405. pring->stats.iocb_cmd++;
  1406. /*
  1407. * If there is no completion routine to call, we can release the
  1408. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1409. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1410. */
  1411. if (nextiocb->iocb_cmpl)
  1412. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1413. else
  1414. __lpfc_sli_release_iocbq(phba, nextiocb);
  1415. /*
  1416. * Let the HBA know what IOCB slot will be the next one the
  1417. * driver will put a command into.
  1418. */
  1419. pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
  1420. writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1421. }
  1422. /**
  1423. * lpfc_sli_update_full_ring - Update the chip attention register
  1424. * @phba: Pointer to HBA context object.
  1425. * @pring: Pointer to driver SLI ring object.
  1426. *
  1427. * The caller is not required to hold any lock for calling this function.
  1428. * This function updates the chip attention bits for the ring to inform firmware
  1429. * that there are pending work to be done for this ring and requests an
  1430. * interrupt when there is space available in the ring. This function is
  1431. * called when the driver is unable to post more iocbs to the ring due
  1432. * to unavailability of space in the ring.
  1433. **/
  1434. static void
  1435. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1436. {
  1437. int ringno = pring->ringno;
  1438. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1439. wmb();
  1440. /*
  1441. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1442. * The HBA will tell us when an IOCB entry is available.
  1443. */
  1444. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1445. readl(phba->CAregaddr); /* flush */
  1446. pring->stats.iocb_cmd_full++;
  1447. }
  1448. /**
  1449. * lpfc_sli_update_ring - Update chip attention register
  1450. * @phba: Pointer to HBA context object.
  1451. * @pring: Pointer to driver SLI ring object.
  1452. *
  1453. * This function updates the chip attention register bit for the
  1454. * given ring to inform HBA that there is more work to be done
  1455. * in this ring. The caller is not required to hold any lock.
  1456. **/
  1457. static void
  1458. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1459. {
  1460. int ringno = pring->ringno;
  1461. /*
  1462. * Tell the HBA that there is work to do in this ring.
  1463. */
  1464. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1465. wmb();
  1466. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1467. readl(phba->CAregaddr); /* flush */
  1468. }
  1469. }
  1470. /**
  1471. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1472. * @phba: Pointer to HBA context object.
  1473. * @pring: Pointer to driver SLI ring object.
  1474. *
  1475. * This function is called with hbalock held to post pending iocbs
  1476. * in the txq to the firmware. This function is called when driver
  1477. * detects space available in the ring.
  1478. **/
  1479. static void
  1480. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1481. {
  1482. IOCB_t *iocb;
  1483. struct lpfc_iocbq *nextiocb;
  1484. /*
  1485. * Check to see if:
  1486. * (a) there is anything on the txq to send
  1487. * (b) link is up
  1488. * (c) link attention events can be processed (fcp ring only)
  1489. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1490. */
  1491. if (lpfc_is_link_up(phba) &&
  1492. (!list_empty(&pring->txq)) &&
  1493. (pring->ringno != phba->sli.fcp_ring ||
  1494. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1495. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1496. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1497. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1498. if (iocb)
  1499. lpfc_sli_update_ring(phba, pring);
  1500. else
  1501. lpfc_sli_update_full_ring(phba, pring);
  1502. }
  1503. return;
  1504. }
  1505. /**
  1506. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1507. * @phba: Pointer to HBA context object.
  1508. * @hbqno: HBQ number.
  1509. *
  1510. * This function is called with hbalock held to get the next
  1511. * available slot for the given HBQ. If there is free slot
  1512. * available for the HBQ it will return pointer to the next available
  1513. * HBQ entry else it will return NULL.
  1514. **/
  1515. static struct lpfc_hbq_entry *
  1516. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1517. {
  1518. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1519. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1520. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1521. hbqp->next_hbqPutIdx = 0;
  1522. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1523. uint32_t raw_index = phba->hbq_get[hbqno];
  1524. uint32_t getidx = le32_to_cpu(raw_index);
  1525. hbqp->local_hbqGetIdx = getidx;
  1526. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1527. lpfc_printf_log(phba, KERN_ERR,
  1528. LOG_SLI | LOG_VPORT,
  1529. "1802 HBQ %d: local_hbqGetIdx "
  1530. "%u is > than hbqp->entry_count %u\n",
  1531. hbqno, hbqp->local_hbqGetIdx,
  1532. hbqp->entry_count);
  1533. phba->link_state = LPFC_HBA_ERROR;
  1534. return NULL;
  1535. }
  1536. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1537. return NULL;
  1538. }
  1539. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1540. hbqp->hbqPutIdx;
  1541. }
  1542. /**
  1543. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1544. * @phba: Pointer to HBA context object.
  1545. *
  1546. * This function is called with no lock held to free all the
  1547. * hbq buffers while uninitializing the SLI interface. It also
  1548. * frees the HBQ buffers returned by the firmware but not yet
  1549. * processed by the upper layers.
  1550. **/
  1551. void
  1552. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1553. {
  1554. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1555. struct hbq_dmabuf *hbq_buf;
  1556. unsigned long flags;
  1557. int i, hbq_count;
  1558. uint32_t hbqno;
  1559. hbq_count = lpfc_sli_hbq_count();
  1560. /* Return all memory used by all HBQs */
  1561. spin_lock_irqsave(&phba->hbalock, flags);
  1562. for (i = 0; i < hbq_count; ++i) {
  1563. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1564. &phba->hbqs[i].hbq_buffer_list, list) {
  1565. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1566. list_del(&hbq_buf->dbuf.list);
  1567. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1568. }
  1569. phba->hbqs[i].buffer_count = 0;
  1570. }
  1571. /* Return all HBQ buffer that are in-fly */
  1572. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1573. list) {
  1574. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1575. list_del(&hbq_buf->dbuf.list);
  1576. if (hbq_buf->tag == -1) {
  1577. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1578. (phba, hbq_buf);
  1579. } else {
  1580. hbqno = hbq_buf->tag >> 16;
  1581. if (hbqno >= LPFC_MAX_HBQS)
  1582. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1583. (phba, hbq_buf);
  1584. else
  1585. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1586. hbq_buf);
  1587. }
  1588. }
  1589. /* Mark the HBQs not in use */
  1590. phba->hbq_in_use = 0;
  1591. spin_unlock_irqrestore(&phba->hbalock, flags);
  1592. }
  1593. /**
  1594. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1595. * @phba: Pointer to HBA context object.
  1596. * @hbqno: HBQ number.
  1597. * @hbq_buf: Pointer to HBQ buffer.
  1598. *
  1599. * This function is called with the hbalock held to post a
  1600. * hbq buffer to the firmware. If the function finds an empty
  1601. * slot in the HBQ, it will post the buffer. The function will return
  1602. * pointer to the hbq entry if it successfully post the buffer
  1603. * else it will return NULL.
  1604. **/
  1605. static int
  1606. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1607. struct hbq_dmabuf *hbq_buf)
  1608. {
  1609. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1610. }
  1611. /**
  1612. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1613. * @phba: Pointer to HBA context object.
  1614. * @hbqno: HBQ number.
  1615. * @hbq_buf: Pointer to HBQ buffer.
  1616. *
  1617. * This function is called with the hbalock held to post a hbq buffer to the
  1618. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1619. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1620. * it successfully post the buffer else it will return an error.
  1621. **/
  1622. static int
  1623. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1624. struct hbq_dmabuf *hbq_buf)
  1625. {
  1626. struct lpfc_hbq_entry *hbqe;
  1627. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1628. /* Get next HBQ entry slot to use */
  1629. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1630. if (hbqe) {
  1631. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1632. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1633. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1634. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1635. hbqe->bde.tus.f.bdeFlags = 0;
  1636. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1637. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1638. /* Sync SLIM */
  1639. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1640. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1641. /* flush */
  1642. readl(phba->hbq_put + hbqno);
  1643. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1644. return 0;
  1645. } else
  1646. return -ENOMEM;
  1647. }
  1648. /**
  1649. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1650. * @phba: Pointer to HBA context object.
  1651. * @hbqno: HBQ number.
  1652. * @hbq_buf: Pointer to HBQ buffer.
  1653. *
  1654. * This function is called with the hbalock held to post an RQE to the SLI4
  1655. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1656. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1657. **/
  1658. static int
  1659. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1660. struct hbq_dmabuf *hbq_buf)
  1661. {
  1662. int rc;
  1663. struct lpfc_rqe hrqe;
  1664. struct lpfc_rqe drqe;
  1665. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1666. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1667. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1668. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1669. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1670. &hrqe, &drqe);
  1671. if (rc < 0)
  1672. return rc;
  1673. hbq_buf->tag = rc;
  1674. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1675. return 0;
  1676. }
  1677. /* HBQ for ELS and CT traffic. */
  1678. static struct lpfc_hbq_init lpfc_els_hbq = {
  1679. .rn = 1,
  1680. .entry_count = 256,
  1681. .mask_count = 0,
  1682. .profile = 0,
  1683. .ring_mask = (1 << LPFC_ELS_RING),
  1684. .buffer_count = 0,
  1685. .init_count = 40,
  1686. .add_count = 40,
  1687. };
  1688. /* HBQ for the extra ring if needed */
  1689. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1690. .rn = 1,
  1691. .entry_count = 200,
  1692. .mask_count = 0,
  1693. .profile = 0,
  1694. .ring_mask = (1 << LPFC_EXTRA_RING),
  1695. .buffer_count = 0,
  1696. .init_count = 0,
  1697. .add_count = 5,
  1698. };
  1699. /* Array of HBQs */
  1700. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1701. &lpfc_els_hbq,
  1702. &lpfc_extra_hbq,
  1703. };
  1704. /**
  1705. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1706. * @phba: Pointer to HBA context object.
  1707. * @hbqno: HBQ number.
  1708. * @count: Number of HBQ buffers to be posted.
  1709. *
  1710. * This function is called with no lock held to post more hbq buffers to the
  1711. * given HBQ. The function returns the number of HBQ buffers successfully
  1712. * posted.
  1713. **/
  1714. static int
  1715. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1716. {
  1717. uint32_t i, posted = 0;
  1718. unsigned long flags;
  1719. struct hbq_dmabuf *hbq_buffer;
  1720. LIST_HEAD(hbq_buf_list);
  1721. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1722. return 0;
  1723. if ((phba->hbqs[hbqno].buffer_count + count) >
  1724. lpfc_hbq_defs[hbqno]->entry_count)
  1725. count = lpfc_hbq_defs[hbqno]->entry_count -
  1726. phba->hbqs[hbqno].buffer_count;
  1727. if (!count)
  1728. return 0;
  1729. /* Allocate HBQ entries */
  1730. for (i = 0; i < count; i++) {
  1731. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1732. if (!hbq_buffer)
  1733. break;
  1734. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1735. }
  1736. /* Check whether HBQ is still in use */
  1737. spin_lock_irqsave(&phba->hbalock, flags);
  1738. if (!phba->hbq_in_use)
  1739. goto err;
  1740. while (!list_empty(&hbq_buf_list)) {
  1741. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1742. dbuf.list);
  1743. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1744. (hbqno << 16));
  1745. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1746. phba->hbqs[hbqno].buffer_count++;
  1747. posted++;
  1748. } else
  1749. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1750. }
  1751. spin_unlock_irqrestore(&phba->hbalock, flags);
  1752. return posted;
  1753. err:
  1754. spin_unlock_irqrestore(&phba->hbalock, flags);
  1755. while (!list_empty(&hbq_buf_list)) {
  1756. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1757. dbuf.list);
  1758. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1759. }
  1760. return 0;
  1761. }
  1762. /**
  1763. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1764. * @phba: Pointer to HBA context object.
  1765. * @qno: HBQ number.
  1766. *
  1767. * This function posts more buffers to the HBQ. This function
  1768. * is called with no lock held. The function returns the number of HBQ entries
  1769. * successfully allocated.
  1770. **/
  1771. int
  1772. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1773. {
  1774. if (phba->sli_rev == LPFC_SLI_REV4)
  1775. return 0;
  1776. else
  1777. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1778. lpfc_hbq_defs[qno]->add_count);
  1779. }
  1780. /**
  1781. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1782. * @phba: Pointer to HBA context object.
  1783. * @qno: HBQ queue number.
  1784. *
  1785. * This function is called from SLI initialization code path with
  1786. * no lock held to post initial HBQ buffers to firmware. The
  1787. * function returns the number of HBQ entries successfully allocated.
  1788. **/
  1789. static int
  1790. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1791. {
  1792. if (phba->sli_rev == LPFC_SLI_REV4)
  1793. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1794. lpfc_hbq_defs[qno]->entry_count);
  1795. else
  1796. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1797. lpfc_hbq_defs[qno]->init_count);
  1798. }
  1799. /**
  1800. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1801. * @phba: Pointer to HBA context object.
  1802. * @hbqno: HBQ number.
  1803. *
  1804. * This function removes the first hbq buffer on an hbq list and returns a
  1805. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1806. **/
  1807. static struct hbq_dmabuf *
  1808. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1809. {
  1810. struct lpfc_dmabuf *d_buf;
  1811. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1812. if (!d_buf)
  1813. return NULL;
  1814. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1815. }
  1816. /**
  1817. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1818. * @phba: Pointer to HBA context object.
  1819. * @tag: Tag of the hbq buffer.
  1820. *
  1821. * This function is called with hbalock held. This function searches
  1822. * for the hbq buffer associated with the given tag in the hbq buffer
  1823. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1824. * it returns NULL.
  1825. **/
  1826. static struct hbq_dmabuf *
  1827. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1828. {
  1829. struct lpfc_dmabuf *d_buf;
  1830. struct hbq_dmabuf *hbq_buf;
  1831. uint32_t hbqno;
  1832. hbqno = tag >> 16;
  1833. if (hbqno >= LPFC_MAX_HBQS)
  1834. return NULL;
  1835. spin_lock_irq(&phba->hbalock);
  1836. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1837. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1838. if (hbq_buf->tag == tag) {
  1839. spin_unlock_irq(&phba->hbalock);
  1840. return hbq_buf;
  1841. }
  1842. }
  1843. spin_unlock_irq(&phba->hbalock);
  1844. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1845. "1803 Bad hbq tag. Data: x%x x%x\n",
  1846. tag, phba->hbqs[tag >> 16].buffer_count);
  1847. return NULL;
  1848. }
  1849. /**
  1850. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1851. * @phba: Pointer to HBA context object.
  1852. * @hbq_buffer: Pointer to HBQ buffer.
  1853. *
  1854. * This function is called with hbalock. This function gives back
  1855. * the hbq buffer to firmware. If the HBQ does not have space to
  1856. * post the buffer, it will free the buffer.
  1857. **/
  1858. void
  1859. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1860. {
  1861. uint32_t hbqno;
  1862. if (hbq_buffer) {
  1863. hbqno = hbq_buffer->tag >> 16;
  1864. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1865. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1866. }
  1867. }
  1868. /**
  1869. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1870. * @mbxCommand: mailbox command code.
  1871. *
  1872. * This function is called by the mailbox event handler function to verify
  1873. * that the completed mailbox command is a legitimate mailbox command. If the
  1874. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1875. * and the mailbox event handler will take the HBA offline.
  1876. **/
  1877. static int
  1878. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1879. {
  1880. uint8_t ret;
  1881. switch (mbxCommand) {
  1882. case MBX_LOAD_SM:
  1883. case MBX_READ_NV:
  1884. case MBX_WRITE_NV:
  1885. case MBX_WRITE_VPARMS:
  1886. case MBX_RUN_BIU_DIAG:
  1887. case MBX_INIT_LINK:
  1888. case MBX_DOWN_LINK:
  1889. case MBX_CONFIG_LINK:
  1890. case MBX_CONFIG_RING:
  1891. case MBX_RESET_RING:
  1892. case MBX_READ_CONFIG:
  1893. case MBX_READ_RCONFIG:
  1894. case MBX_READ_SPARM:
  1895. case MBX_READ_STATUS:
  1896. case MBX_READ_RPI:
  1897. case MBX_READ_XRI:
  1898. case MBX_READ_REV:
  1899. case MBX_READ_LNK_STAT:
  1900. case MBX_REG_LOGIN:
  1901. case MBX_UNREG_LOGIN:
  1902. case MBX_CLEAR_LA:
  1903. case MBX_DUMP_MEMORY:
  1904. case MBX_DUMP_CONTEXT:
  1905. case MBX_RUN_DIAGS:
  1906. case MBX_RESTART:
  1907. case MBX_UPDATE_CFG:
  1908. case MBX_DOWN_LOAD:
  1909. case MBX_DEL_LD_ENTRY:
  1910. case MBX_RUN_PROGRAM:
  1911. case MBX_SET_MASK:
  1912. case MBX_SET_VARIABLE:
  1913. case MBX_UNREG_D_ID:
  1914. case MBX_KILL_BOARD:
  1915. case MBX_CONFIG_FARP:
  1916. case MBX_BEACON:
  1917. case MBX_LOAD_AREA:
  1918. case MBX_RUN_BIU_DIAG64:
  1919. case MBX_CONFIG_PORT:
  1920. case MBX_READ_SPARM64:
  1921. case MBX_READ_RPI64:
  1922. case MBX_REG_LOGIN64:
  1923. case MBX_READ_TOPOLOGY:
  1924. case MBX_WRITE_WWN:
  1925. case MBX_SET_DEBUG:
  1926. case MBX_LOAD_EXP_ROM:
  1927. case MBX_ASYNCEVT_ENABLE:
  1928. case MBX_REG_VPI:
  1929. case MBX_UNREG_VPI:
  1930. case MBX_HEARTBEAT:
  1931. case MBX_PORT_CAPABILITIES:
  1932. case MBX_PORT_IOV_CONTROL:
  1933. case MBX_SLI4_CONFIG:
  1934. case MBX_SLI4_REQ_FTRS:
  1935. case MBX_REG_FCFI:
  1936. case MBX_UNREG_FCFI:
  1937. case MBX_REG_VFI:
  1938. case MBX_UNREG_VFI:
  1939. case MBX_INIT_VPI:
  1940. case MBX_INIT_VFI:
  1941. case MBX_RESUME_RPI:
  1942. case MBX_READ_EVENT_LOG_STATUS:
  1943. case MBX_READ_EVENT_LOG:
  1944. case MBX_SECURITY_MGMT:
  1945. case MBX_AUTH_PORT:
  1946. case MBX_ACCESS_VDATA:
  1947. ret = mbxCommand;
  1948. break;
  1949. default:
  1950. ret = MBX_SHUTDOWN;
  1951. break;
  1952. }
  1953. return ret;
  1954. }
  1955. /**
  1956. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1957. * @phba: Pointer to HBA context object.
  1958. * @pmboxq: Pointer to mailbox command.
  1959. *
  1960. * This is completion handler function for mailbox commands issued from
  1961. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1962. * mailbox event handler function with no lock held. This function
  1963. * will wake up thread waiting on the wait queue pointed by context1
  1964. * of the mailbox.
  1965. **/
  1966. void
  1967. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1968. {
  1969. wait_queue_head_t *pdone_q;
  1970. unsigned long drvr_flag;
  1971. /*
  1972. * If pdone_q is empty, the driver thread gave up waiting and
  1973. * continued running.
  1974. */
  1975. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1976. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1977. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1978. if (pdone_q)
  1979. wake_up_interruptible(pdone_q);
  1980. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1981. return;
  1982. }
  1983. /**
  1984. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1985. * @phba: Pointer to HBA context object.
  1986. * @pmb: Pointer to mailbox object.
  1987. *
  1988. * This function is the default mailbox completion handler. It
  1989. * frees the memory resources associated with the completed mailbox
  1990. * command. If the completed command is a REG_LOGIN mailbox command,
  1991. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1992. **/
  1993. void
  1994. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1995. {
  1996. struct lpfc_vport *vport = pmb->vport;
  1997. struct lpfc_dmabuf *mp;
  1998. struct lpfc_nodelist *ndlp;
  1999. struct Scsi_Host *shost;
  2000. uint16_t rpi, vpi;
  2001. int rc;
  2002. mp = (struct lpfc_dmabuf *) (pmb->context1);
  2003. if (mp) {
  2004. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2005. kfree(mp);
  2006. }
  2007. /*
  2008. * If a REG_LOGIN succeeded after node is destroyed or node
  2009. * is in re-discovery driver need to cleanup the RPI.
  2010. */
  2011. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  2012. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  2013. !pmb->u.mb.mbxStatus) {
  2014. rpi = pmb->u.mb.un.varWords[0];
  2015. vpi = pmb->u.mb.un.varRegLogin.vpi;
  2016. lpfc_unreg_login(phba, vpi, rpi, pmb);
  2017. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2018. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2019. if (rc != MBX_NOT_FINISHED)
  2020. return;
  2021. }
  2022. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  2023. !(phba->pport->load_flag & FC_UNLOADING) &&
  2024. !pmb->u.mb.mbxStatus) {
  2025. shost = lpfc_shost_from_vport(vport);
  2026. spin_lock_irq(shost->host_lock);
  2027. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2028. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2029. spin_unlock_irq(shost->host_lock);
  2030. }
  2031. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  2032. ndlp = (struct lpfc_nodelist *)pmb->context2;
  2033. lpfc_nlp_put(ndlp);
  2034. pmb->context2 = NULL;
  2035. }
  2036. /* Check security permission status on INIT_LINK mailbox command */
  2037. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  2038. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  2039. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2040. "2860 SLI authentication is required "
  2041. "for INIT_LINK but has not done yet\n");
  2042. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  2043. lpfc_sli4_mbox_cmd_free(phba, pmb);
  2044. else
  2045. mempool_free(pmb, phba->mbox_mem_pool);
  2046. }
  2047. /**
  2048. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2049. * @phba: Pointer to HBA context object.
  2050. *
  2051. * This function is called with no lock held. This function processes all
  2052. * the completed mailbox commands and gives it to upper layers. The interrupt
  2053. * service routine processes mailbox completion interrupt and adds completed
  2054. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2055. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2056. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2057. * function returns the mailbox commands to the upper layer by calling the
  2058. * completion handler function of each mailbox.
  2059. **/
  2060. int
  2061. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2062. {
  2063. MAILBOX_t *pmbox;
  2064. LPFC_MBOXQ_t *pmb;
  2065. int rc;
  2066. LIST_HEAD(cmplq);
  2067. phba->sli.slistat.mbox_event++;
  2068. /* Get all completed mailboxe buffers into the cmplq */
  2069. spin_lock_irq(&phba->hbalock);
  2070. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2071. spin_unlock_irq(&phba->hbalock);
  2072. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2073. do {
  2074. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2075. if (pmb == NULL)
  2076. break;
  2077. pmbox = &pmb->u.mb;
  2078. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2079. if (pmb->vport) {
  2080. lpfc_debugfs_disc_trc(pmb->vport,
  2081. LPFC_DISC_TRC_MBOX_VPORT,
  2082. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2083. (uint32_t)pmbox->mbxCommand,
  2084. pmbox->un.varWords[0],
  2085. pmbox->un.varWords[1]);
  2086. }
  2087. else {
  2088. lpfc_debugfs_disc_trc(phba->pport,
  2089. LPFC_DISC_TRC_MBOX,
  2090. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2091. (uint32_t)pmbox->mbxCommand,
  2092. pmbox->un.varWords[0],
  2093. pmbox->un.varWords[1]);
  2094. }
  2095. }
  2096. /*
  2097. * It is a fatal error if unknown mbox command completion.
  2098. */
  2099. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2100. MBX_SHUTDOWN) {
  2101. /* Unknown mailbox command compl */
  2102. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2103. "(%d):0323 Unknown Mailbox command "
  2104. "x%x (x%x/x%x) Cmpl\n",
  2105. pmb->vport ? pmb->vport->vpi : 0,
  2106. pmbox->mbxCommand,
  2107. lpfc_sli_config_mbox_subsys_get(phba,
  2108. pmb),
  2109. lpfc_sli_config_mbox_opcode_get(phba,
  2110. pmb));
  2111. phba->link_state = LPFC_HBA_ERROR;
  2112. phba->work_hs = HS_FFER3;
  2113. lpfc_handle_eratt(phba);
  2114. continue;
  2115. }
  2116. if (pmbox->mbxStatus) {
  2117. phba->sli.slistat.mbox_stat_err++;
  2118. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2119. /* Mbox cmd cmpl error - RETRYing */
  2120. lpfc_printf_log(phba, KERN_INFO,
  2121. LOG_MBOX | LOG_SLI,
  2122. "(%d):0305 Mbox cmd cmpl "
  2123. "error - RETRYing Data: x%x "
  2124. "(x%x/x%x) x%x x%x x%x\n",
  2125. pmb->vport ? pmb->vport->vpi : 0,
  2126. pmbox->mbxCommand,
  2127. lpfc_sli_config_mbox_subsys_get(phba,
  2128. pmb),
  2129. lpfc_sli_config_mbox_opcode_get(phba,
  2130. pmb),
  2131. pmbox->mbxStatus,
  2132. pmbox->un.varWords[0],
  2133. pmb->vport->port_state);
  2134. pmbox->mbxStatus = 0;
  2135. pmbox->mbxOwner = OWN_HOST;
  2136. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2137. if (rc != MBX_NOT_FINISHED)
  2138. continue;
  2139. }
  2140. }
  2141. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2142. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2143. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2144. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2145. pmb->vport ? pmb->vport->vpi : 0,
  2146. pmbox->mbxCommand,
  2147. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2148. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2149. pmb->mbox_cmpl,
  2150. *((uint32_t *) pmbox),
  2151. pmbox->un.varWords[0],
  2152. pmbox->un.varWords[1],
  2153. pmbox->un.varWords[2],
  2154. pmbox->un.varWords[3],
  2155. pmbox->un.varWords[4],
  2156. pmbox->un.varWords[5],
  2157. pmbox->un.varWords[6],
  2158. pmbox->un.varWords[7]);
  2159. if (pmb->mbox_cmpl)
  2160. pmb->mbox_cmpl(phba,pmb);
  2161. } while (1);
  2162. return 0;
  2163. }
  2164. /**
  2165. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2166. * @phba: Pointer to HBA context object.
  2167. * @pring: Pointer to driver SLI ring object.
  2168. * @tag: buffer tag.
  2169. *
  2170. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2171. * is set in the tag the buffer is posted for a particular exchange,
  2172. * the function will return the buffer without replacing the buffer.
  2173. * If the buffer is for unsolicited ELS or CT traffic, this function
  2174. * returns the buffer and also posts another buffer to the firmware.
  2175. **/
  2176. static struct lpfc_dmabuf *
  2177. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2178. struct lpfc_sli_ring *pring,
  2179. uint32_t tag)
  2180. {
  2181. struct hbq_dmabuf *hbq_entry;
  2182. if (tag & QUE_BUFTAG_BIT)
  2183. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2184. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2185. if (!hbq_entry)
  2186. return NULL;
  2187. return &hbq_entry->dbuf;
  2188. }
  2189. /**
  2190. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2191. * @phba: Pointer to HBA context object.
  2192. * @pring: Pointer to driver SLI ring object.
  2193. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2194. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2195. * @fch_type: the type for the first frame of the sequence.
  2196. *
  2197. * This function is called with no lock held. This function uses the r_ctl and
  2198. * type of the received sequence to find the correct callback function to call
  2199. * to process the sequence.
  2200. **/
  2201. static int
  2202. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2203. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2204. uint32_t fch_type)
  2205. {
  2206. int i;
  2207. /* unSolicited Responses */
  2208. if (pring->prt[0].profile) {
  2209. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2210. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2211. saveq);
  2212. return 1;
  2213. }
  2214. /* We must search, based on rctl / type
  2215. for the right routine */
  2216. for (i = 0; i < pring->num_mask; i++) {
  2217. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2218. (pring->prt[i].type == fch_type)) {
  2219. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2220. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2221. (phba, pring, saveq);
  2222. return 1;
  2223. }
  2224. }
  2225. return 0;
  2226. }
  2227. /**
  2228. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2229. * @phba: Pointer to HBA context object.
  2230. * @pring: Pointer to driver SLI ring object.
  2231. * @saveq: Pointer to the unsolicited iocb.
  2232. *
  2233. * This function is called with no lock held by the ring event handler
  2234. * when there is an unsolicited iocb posted to the response ring by the
  2235. * firmware. This function gets the buffer associated with the iocbs
  2236. * and calls the event handler for the ring. This function handles both
  2237. * qring buffers and hbq buffers.
  2238. * When the function returns 1 the caller can free the iocb object otherwise
  2239. * upper layer functions will free the iocb objects.
  2240. **/
  2241. static int
  2242. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2243. struct lpfc_iocbq *saveq)
  2244. {
  2245. IOCB_t * irsp;
  2246. WORD5 * w5p;
  2247. uint32_t Rctl, Type;
  2248. uint32_t match;
  2249. struct lpfc_iocbq *iocbq;
  2250. struct lpfc_dmabuf *dmzbuf;
  2251. match = 0;
  2252. irsp = &(saveq->iocb);
  2253. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2254. if (pring->lpfc_sli_rcv_async_status)
  2255. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2256. else
  2257. lpfc_printf_log(phba,
  2258. KERN_WARNING,
  2259. LOG_SLI,
  2260. "0316 Ring %d handler: unexpected "
  2261. "ASYNC_STATUS iocb received evt_code "
  2262. "0x%x\n",
  2263. pring->ringno,
  2264. irsp->un.asyncstat.evt_code);
  2265. return 1;
  2266. }
  2267. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2268. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2269. if (irsp->ulpBdeCount > 0) {
  2270. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2271. irsp->un.ulpWord[3]);
  2272. lpfc_in_buf_free(phba, dmzbuf);
  2273. }
  2274. if (irsp->ulpBdeCount > 1) {
  2275. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2276. irsp->unsli3.sli3Words[3]);
  2277. lpfc_in_buf_free(phba, dmzbuf);
  2278. }
  2279. if (irsp->ulpBdeCount > 2) {
  2280. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2281. irsp->unsli3.sli3Words[7]);
  2282. lpfc_in_buf_free(phba, dmzbuf);
  2283. }
  2284. return 1;
  2285. }
  2286. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2287. if (irsp->ulpBdeCount != 0) {
  2288. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2289. irsp->un.ulpWord[3]);
  2290. if (!saveq->context2)
  2291. lpfc_printf_log(phba,
  2292. KERN_ERR,
  2293. LOG_SLI,
  2294. "0341 Ring %d Cannot find buffer for "
  2295. "an unsolicited iocb. tag 0x%x\n",
  2296. pring->ringno,
  2297. irsp->un.ulpWord[3]);
  2298. }
  2299. if (irsp->ulpBdeCount == 2) {
  2300. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2301. irsp->unsli3.sli3Words[7]);
  2302. if (!saveq->context3)
  2303. lpfc_printf_log(phba,
  2304. KERN_ERR,
  2305. LOG_SLI,
  2306. "0342 Ring %d Cannot find buffer for an"
  2307. " unsolicited iocb. tag 0x%x\n",
  2308. pring->ringno,
  2309. irsp->unsli3.sli3Words[7]);
  2310. }
  2311. list_for_each_entry(iocbq, &saveq->list, list) {
  2312. irsp = &(iocbq->iocb);
  2313. if (irsp->ulpBdeCount != 0) {
  2314. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2315. irsp->un.ulpWord[3]);
  2316. if (!iocbq->context2)
  2317. lpfc_printf_log(phba,
  2318. KERN_ERR,
  2319. LOG_SLI,
  2320. "0343 Ring %d Cannot find "
  2321. "buffer for an unsolicited iocb"
  2322. ". tag 0x%x\n", pring->ringno,
  2323. irsp->un.ulpWord[3]);
  2324. }
  2325. if (irsp->ulpBdeCount == 2) {
  2326. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2327. irsp->unsli3.sli3Words[7]);
  2328. if (!iocbq->context3)
  2329. lpfc_printf_log(phba,
  2330. KERN_ERR,
  2331. LOG_SLI,
  2332. "0344 Ring %d Cannot find "
  2333. "buffer for an unsolicited "
  2334. "iocb. tag 0x%x\n",
  2335. pring->ringno,
  2336. irsp->unsli3.sli3Words[7]);
  2337. }
  2338. }
  2339. }
  2340. if (irsp->ulpBdeCount != 0 &&
  2341. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2342. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2343. int found = 0;
  2344. /* search continue save q for same XRI */
  2345. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2346. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2347. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2348. list_add_tail(&saveq->list, &iocbq->list);
  2349. found = 1;
  2350. break;
  2351. }
  2352. }
  2353. if (!found)
  2354. list_add_tail(&saveq->clist,
  2355. &pring->iocb_continue_saveq);
  2356. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2357. list_del_init(&iocbq->clist);
  2358. saveq = iocbq;
  2359. irsp = &(saveq->iocb);
  2360. } else
  2361. return 0;
  2362. }
  2363. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2364. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2365. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2366. Rctl = FC_RCTL_ELS_REQ;
  2367. Type = FC_TYPE_ELS;
  2368. } else {
  2369. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2370. Rctl = w5p->hcsw.Rctl;
  2371. Type = w5p->hcsw.Type;
  2372. /* Firmware Workaround */
  2373. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2374. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2375. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2376. Rctl = FC_RCTL_ELS_REQ;
  2377. Type = FC_TYPE_ELS;
  2378. w5p->hcsw.Rctl = Rctl;
  2379. w5p->hcsw.Type = Type;
  2380. }
  2381. }
  2382. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2383. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2384. "0313 Ring %d handler: unexpected Rctl x%x "
  2385. "Type x%x received\n",
  2386. pring->ringno, Rctl, Type);
  2387. return 1;
  2388. }
  2389. /**
  2390. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2391. * @phba: Pointer to HBA context object.
  2392. * @pring: Pointer to driver SLI ring object.
  2393. * @prspiocb: Pointer to response iocb object.
  2394. *
  2395. * This function looks up the iocb_lookup table to get the command iocb
  2396. * corresponding to the given response iocb using the iotag of the
  2397. * response iocb. This function is called with the hbalock held.
  2398. * This function returns the command iocb object if it finds the command
  2399. * iocb else returns NULL.
  2400. **/
  2401. static struct lpfc_iocbq *
  2402. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2403. struct lpfc_sli_ring *pring,
  2404. struct lpfc_iocbq *prspiocb)
  2405. {
  2406. struct lpfc_iocbq *cmd_iocb = NULL;
  2407. uint16_t iotag;
  2408. iotag = prspiocb->iocb.ulpIoTag;
  2409. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2410. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2411. list_del_init(&cmd_iocb->list);
  2412. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2413. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2414. }
  2415. return cmd_iocb;
  2416. }
  2417. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2418. "0317 iotag x%x is out off "
  2419. "range: max iotag x%x wd0 x%x\n",
  2420. iotag, phba->sli.last_iotag,
  2421. *(((uint32_t *) &prspiocb->iocb) + 7));
  2422. return NULL;
  2423. }
  2424. /**
  2425. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2426. * @phba: Pointer to HBA context object.
  2427. * @pring: Pointer to driver SLI ring object.
  2428. * @iotag: IOCB tag.
  2429. *
  2430. * This function looks up the iocb_lookup table to get the command iocb
  2431. * corresponding to the given iotag. This function is called with the
  2432. * hbalock held.
  2433. * This function returns the command iocb object if it finds the command
  2434. * iocb else returns NULL.
  2435. **/
  2436. static struct lpfc_iocbq *
  2437. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2438. struct lpfc_sli_ring *pring, uint16_t iotag)
  2439. {
  2440. struct lpfc_iocbq *cmd_iocb;
  2441. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2442. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2443. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2444. /* remove from txcmpl queue list */
  2445. list_del_init(&cmd_iocb->list);
  2446. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2447. return cmd_iocb;
  2448. }
  2449. }
  2450. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2451. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2452. iotag, phba->sli.last_iotag);
  2453. return NULL;
  2454. }
  2455. /**
  2456. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2457. * @phba: Pointer to HBA context object.
  2458. * @pring: Pointer to driver SLI ring object.
  2459. * @saveq: Pointer to the response iocb to be processed.
  2460. *
  2461. * This function is called by the ring event handler for non-fcp
  2462. * rings when there is a new response iocb in the response ring.
  2463. * The caller is not required to hold any locks. This function
  2464. * gets the command iocb associated with the response iocb and
  2465. * calls the completion handler for the command iocb. If there
  2466. * is no completion handler, the function will free the resources
  2467. * associated with command iocb. If the response iocb is for
  2468. * an already aborted command iocb, the status of the completion
  2469. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2470. * This function always returns 1.
  2471. **/
  2472. static int
  2473. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2474. struct lpfc_iocbq *saveq)
  2475. {
  2476. struct lpfc_iocbq *cmdiocbp;
  2477. int rc = 1;
  2478. unsigned long iflag;
  2479. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2480. spin_lock_irqsave(&phba->hbalock, iflag);
  2481. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2482. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2483. if (cmdiocbp) {
  2484. if (cmdiocbp->iocb_cmpl) {
  2485. /*
  2486. * If an ELS command failed send an event to mgmt
  2487. * application.
  2488. */
  2489. if (saveq->iocb.ulpStatus &&
  2490. (pring->ringno == LPFC_ELS_RING) &&
  2491. (cmdiocbp->iocb.ulpCommand ==
  2492. CMD_ELS_REQUEST64_CR))
  2493. lpfc_send_els_failure_event(phba,
  2494. cmdiocbp, saveq);
  2495. /*
  2496. * Post all ELS completions to the worker thread.
  2497. * All other are passed to the completion callback.
  2498. */
  2499. if (pring->ringno == LPFC_ELS_RING) {
  2500. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2501. (cmdiocbp->iocb_flag &
  2502. LPFC_DRIVER_ABORTED)) {
  2503. spin_lock_irqsave(&phba->hbalock,
  2504. iflag);
  2505. cmdiocbp->iocb_flag &=
  2506. ~LPFC_DRIVER_ABORTED;
  2507. spin_unlock_irqrestore(&phba->hbalock,
  2508. iflag);
  2509. saveq->iocb.ulpStatus =
  2510. IOSTAT_LOCAL_REJECT;
  2511. saveq->iocb.un.ulpWord[4] =
  2512. IOERR_SLI_ABORTED;
  2513. /* Firmware could still be in progress
  2514. * of DMAing payload, so don't free data
  2515. * buffer till after a hbeat.
  2516. */
  2517. spin_lock_irqsave(&phba->hbalock,
  2518. iflag);
  2519. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2520. spin_unlock_irqrestore(&phba->hbalock,
  2521. iflag);
  2522. }
  2523. if (phba->sli_rev == LPFC_SLI_REV4) {
  2524. if (saveq->iocb_flag &
  2525. LPFC_EXCHANGE_BUSY) {
  2526. /* Set cmdiocb flag for the
  2527. * exchange busy so sgl (xri)
  2528. * will not be released until
  2529. * the abort xri is received
  2530. * from hba.
  2531. */
  2532. spin_lock_irqsave(
  2533. &phba->hbalock, iflag);
  2534. cmdiocbp->iocb_flag |=
  2535. LPFC_EXCHANGE_BUSY;
  2536. spin_unlock_irqrestore(
  2537. &phba->hbalock, iflag);
  2538. }
  2539. if (cmdiocbp->iocb_flag &
  2540. LPFC_DRIVER_ABORTED) {
  2541. /*
  2542. * Clear LPFC_DRIVER_ABORTED
  2543. * bit in case it was driver
  2544. * initiated abort.
  2545. */
  2546. spin_lock_irqsave(
  2547. &phba->hbalock, iflag);
  2548. cmdiocbp->iocb_flag &=
  2549. ~LPFC_DRIVER_ABORTED;
  2550. spin_unlock_irqrestore(
  2551. &phba->hbalock, iflag);
  2552. cmdiocbp->iocb.ulpStatus =
  2553. IOSTAT_LOCAL_REJECT;
  2554. cmdiocbp->iocb.un.ulpWord[4] =
  2555. IOERR_ABORT_REQUESTED;
  2556. /*
  2557. * For SLI4, irsiocb contains
  2558. * NO_XRI in sli_xritag, it
  2559. * shall not affect releasing
  2560. * sgl (xri) process.
  2561. */
  2562. saveq->iocb.ulpStatus =
  2563. IOSTAT_LOCAL_REJECT;
  2564. saveq->iocb.un.ulpWord[4] =
  2565. IOERR_SLI_ABORTED;
  2566. spin_lock_irqsave(
  2567. &phba->hbalock, iflag);
  2568. saveq->iocb_flag |=
  2569. LPFC_DELAY_MEM_FREE;
  2570. spin_unlock_irqrestore(
  2571. &phba->hbalock, iflag);
  2572. }
  2573. }
  2574. }
  2575. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2576. } else
  2577. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2578. } else {
  2579. /*
  2580. * Unknown initiating command based on the response iotag.
  2581. * This could be the case on the ELS ring because of
  2582. * lpfc_els_abort().
  2583. */
  2584. if (pring->ringno != LPFC_ELS_RING) {
  2585. /*
  2586. * Ring <ringno> handler: unexpected completion IoTag
  2587. * <IoTag>
  2588. */
  2589. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2590. "0322 Ring %d handler: "
  2591. "unexpected completion IoTag x%x "
  2592. "Data: x%x x%x x%x x%x\n",
  2593. pring->ringno,
  2594. saveq->iocb.ulpIoTag,
  2595. saveq->iocb.ulpStatus,
  2596. saveq->iocb.un.ulpWord[4],
  2597. saveq->iocb.ulpCommand,
  2598. saveq->iocb.ulpContext);
  2599. }
  2600. }
  2601. return rc;
  2602. }
  2603. /**
  2604. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2605. * @phba: Pointer to HBA context object.
  2606. * @pring: Pointer to driver SLI ring object.
  2607. *
  2608. * This function is called from the iocb ring event handlers when
  2609. * put pointer is ahead of the get pointer for a ring. This function signal
  2610. * an error attention condition to the worker thread and the worker
  2611. * thread will transition the HBA to offline state.
  2612. **/
  2613. static void
  2614. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2615. {
  2616. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2617. /*
  2618. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2619. * rsp ring <portRspMax>
  2620. */
  2621. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2622. "0312 Ring %d handler: portRspPut %d "
  2623. "is bigger than rsp ring %d\n",
  2624. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2625. pring->sli.sli3.numRiocb);
  2626. phba->link_state = LPFC_HBA_ERROR;
  2627. /*
  2628. * All error attention handlers are posted to
  2629. * worker thread
  2630. */
  2631. phba->work_ha |= HA_ERATT;
  2632. phba->work_hs = HS_FFER3;
  2633. lpfc_worker_wake_up(phba);
  2634. return;
  2635. }
  2636. /**
  2637. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2638. * @ptr: Pointer to address of HBA context object.
  2639. *
  2640. * This function is invoked by the Error Attention polling timer when the
  2641. * timer times out. It will check the SLI Error Attention register for
  2642. * possible attention events. If so, it will post an Error Attention event
  2643. * and wake up worker thread to process it. Otherwise, it will set up the
  2644. * Error Attention polling timer for the next poll.
  2645. **/
  2646. void lpfc_poll_eratt(unsigned long ptr)
  2647. {
  2648. struct lpfc_hba *phba;
  2649. uint32_t eratt = 0, rem;
  2650. uint64_t sli_intr, cnt;
  2651. phba = (struct lpfc_hba *)ptr;
  2652. /* Here we will also keep track of interrupts per sec of the hba */
  2653. sli_intr = phba->sli.slistat.sli_intr;
  2654. if (phba->sli.slistat.sli_prev_intr > sli_intr)
  2655. cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
  2656. sli_intr);
  2657. else
  2658. cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
  2659. /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
  2660. rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL);
  2661. phba->sli.slistat.sli_ips = cnt;
  2662. phba->sli.slistat.sli_prev_intr = sli_intr;
  2663. /* Check chip HA register for error event */
  2664. eratt = lpfc_sli_check_eratt(phba);
  2665. if (eratt)
  2666. /* Tell the worker thread there is work to do */
  2667. lpfc_worker_wake_up(phba);
  2668. else
  2669. /* Restart the timer for next eratt poll */
  2670. mod_timer(&phba->eratt_poll,
  2671. jiffies +
  2672. msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  2673. return;
  2674. }
  2675. /**
  2676. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2677. * @phba: Pointer to HBA context object.
  2678. * @pring: Pointer to driver SLI ring object.
  2679. * @mask: Host attention register mask for this ring.
  2680. *
  2681. * This function is called from the interrupt context when there is a ring
  2682. * event for the fcp ring. The caller does not hold any lock.
  2683. * The function processes each response iocb in the response ring until it
  2684. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2685. * LE bit set. The function will call the completion handler of the command iocb
  2686. * if the response iocb indicates a completion for a command iocb or it is
  2687. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2688. * function if this is an unsolicited iocb.
  2689. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2690. * to check it explicitly.
  2691. */
  2692. int
  2693. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2694. struct lpfc_sli_ring *pring, uint32_t mask)
  2695. {
  2696. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2697. IOCB_t *irsp = NULL;
  2698. IOCB_t *entry = NULL;
  2699. struct lpfc_iocbq *cmdiocbq = NULL;
  2700. struct lpfc_iocbq rspiocbq;
  2701. uint32_t status;
  2702. uint32_t portRspPut, portRspMax;
  2703. int rc = 1;
  2704. lpfc_iocb_type type;
  2705. unsigned long iflag;
  2706. uint32_t rsp_cmpl = 0;
  2707. spin_lock_irqsave(&phba->hbalock, iflag);
  2708. pring->stats.iocb_event++;
  2709. /*
  2710. * The next available response entry should never exceed the maximum
  2711. * entries. If it does, treat it as an adapter hardware error.
  2712. */
  2713. portRspMax = pring->sli.sli3.numRiocb;
  2714. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2715. if (unlikely(portRspPut >= portRspMax)) {
  2716. lpfc_sli_rsp_pointers_error(phba, pring);
  2717. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2718. return 1;
  2719. }
  2720. if (phba->fcp_ring_in_use) {
  2721. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2722. return 1;
  2723. } else
  2724. phba->fcp_ring_in_use = 1;
  2725. rmb();
  2726. while (pring->sli.sli3.rspidx != portRspPut) {
  2727. /*
  2728. * Fetch an entry off the ring and copy it into a local data
  2729. * structure. The copy involves a byte-swap since the
  2730. * network byte order and pci byte orders are different.
  2731. */
  2732. entry = lpfc_resp_iocb(phba, pring);
  2733. phba->last_completion_time = jiffies;
  2734. if (++pring->sli.sli3.rspidx >= portRspMax)
  2735. pring->sli.sli3.rspidx = 0;
  2736. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2737. (uint32_t *) &rspiocbq.iocb,
  2738. phba->iocb_rsp_size);
  2739. INIT_LIST_HEAD(&(rspiocbq.list));
  2740. irsp = &rspiocbq.iocb;
  2741. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2742. pring->stats.iocb_rsp++;
  2743. rsp_cmpl++;
  2744. if (unlikely(irsp->ulpStatus)) {
  2745. /*
  2746. * If resource errors reported from HBA, reduce
  2747. * queuedepths of the SCSI device.
  2748. */
  2749. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2750. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2751. IOERR_NO_RESOURCES)) {
  2752. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2753. phba->lpfc_rampdown_queue_depth(phba);
  2754. spin_lock_irqsave(&phba->hbalock, iflag);
  2755. }
  2756. /* Rsp ring <ringno> error: IOCB */
  2757. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2758. "0336 Rsp Ring %d error: IOCB Data: "
  2759. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2760. pring->ringno,
  2761. irsp->un.ulpWord[0],
  2762. irsp->un.ulpWord[1],
  2763. irsp->un.ulpWord[2],
  2764. irsp->un.ulpWord[3],
  2765. irsp->un.ulpWord[4],
  2766. irsp->un.ulpWord[5],
  2767. *(uint32_t *)&irsp->un1,
  2768. *((uint32_t *)&irsp->un1 + 1));
  2769. }
  2770. switch (type) {
  2771. case LPFC_ABORT_IOCB:
  2772. case LPFC_SOL_IOCB:
  2773. /*
  2774. * Idle exchange closed via ABTS from port. No iocb
  2775. * resources need to be recovered.
  2776. */
  2777. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2778. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2779. "0333 IOCB cmd 0x%x"
  2780. " processed. Skipping"
  2781. " completion\n",
  2782. irsp->ulpCommand);
  2783. break;
  2784. }
  2785. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2786. &rspiocbq);
  2787. if (unlikely(!cmdiocbq))
  2788. break;
  2789. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2790. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2791. if (cmdiocbq->iocb_cmpl) {
  2792. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2793. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2794. &rspiocbq);
  2795. spin_lock_irqsave(&phba->hbalock, iflag);
  2796. }
  2797. break;
  2798. case LPFC_UNSOL_IOCB:
  2799. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2800. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2801. spin_lock_irqsave(&phba->hbalock, iflag);
  2802. break;
  2803. default:
  2804. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2805. char adaptermsg[LPFC_MAX_ADPTMSG];
  2806. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2807. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2808. MAX_MSG_DATA);
  2809. dev_warn(&((phba->pcidev)->dev),
  2810. "lpfc%d: %s\n",
  2811. phba->brd_no, adaptermsg);
  2812. } else {
  2813. /* Unknown IOCB command */
  2814. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2815. "0334 Unknown IOCB command "
  2816. "Data: x%x, x%x x%x x%x x%x\n",
  2817. type, irsp->ulpCommand,
  2818. irsp->ulpStatus,
  2819. irsp->ulpIoTag,
  2820. irsp->ulpContext);
  2821. }
  2822. break;
  2823. }
  2824. /*
  2825. * The response IOCB has been processed. Update the ring
  2826. * pointer in SLIM. If the port response put pointer has not
  2827. * been updated, sync the pgp->rspPutInx and fetch the new port
  2828. * response put pointer.
  2829. */
  2830. writel(pring->sli.sli3.rspidx,
  2831. &phba->host_gp[pring->ringno].rspGetInx);
  2832. if (pring->sli.sli3.rspidx == portRspPut)
  2833. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2834. }
  2835. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2836. pring->stats.iocb_rsp_full++;
  2837. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2838. writel(status, phba->CAregaddr);
  2839. readl(phba->CAregaddr);
  2840. }
  2841. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2842. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2843. pring->stats.iocb_cmd_empty++;
  2844. /* Force update of the local copy of cmdGetInx */
  2845. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2846. lpfc_sli_resume_iocb(phba, pring);
  2847. if ((pring->lpfc_sli_cmd_available))
  2848. (pring->lpfc_sli_cmd_available) (phba, pring);
  2849. }
  2850. phba->fcp_ring_in_use = 0;
  2851. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2852. return rc;
  2853. }
  2854. /**
  2855. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2856. * @phba: Pointer to HBA context object.
  2857. * @pring: Pointer to driver SLI ring object.
  2858. * @rspiocbp: Pointer to driver response IOCB object.
  2859. *
  2860. * This function is called from the worker thread when there is a slow-path
  2861. * response IOCB to process. This function chains all the response iocbs until
  2862. * seeing the iocb with the LE bit set. The function will call
  2863. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2864. * completion of a command iocb. The function will call the
  2865. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2866. * The function frees the resources or calls the completion handler if this
  2867. * iocb is an abort completion. The function returns NULL when the response
  2868. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2869. * this function shall chain the iocb on to the iocb_continueq and return the
  2870. * response iocb passed in.
  2871. **/
  2872. static struct lpfc_iocbq *
  2873. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2874. struct lpfc_iocbq *rspiocbp)
  2875. {
  2876. struct lpfc_iocbq *saveq;
  2877. struct lpfc_iocbq *cmdiocbp;
  2878. struct lpfc_iocbq *next_iocb;
  2879. IOCB_t *irsp = NULL;
  2880. uint32_t free_saveq;
  2881. uint8_t iocb_cmd_type;
  2882. lpfc_iocb_type type;
  2883. unsigned long iflag;
  2884. int rc;
  2885. spin_lock_irqsave(&phba->hbalock, iflag);
  2886. /* First add the response iocb to the countinueq list */
  2887. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2888. pring->iocb_continueq_cnt++;
  2889. /* Now, determine whether the list is completed for processing */
  2890. irsp = &rspiocbp->iocb;
  2891. if (irsp->ulpLe) {
  2892. /*
  2893. * By default, the driver expects to free all resources
  2894. * associated with this iocb completion.
  2895. */
  2896. free_saveq = 1;
  2897. saveq = list_get_first(&pring->iocb_continueq,
  2898. struct lpfc_iocbq, list);
  2899. irsp = &(saveq->iocb);
  2900. list_del_init(&pring->iocb_continueq);
  2901. pring->iocb_continueq_cnt = 0;
  2902. pring->stats.iocb_rsp++;
  2903. /*
  2904. * If resource errors reported from HBA, reduce
  2905. * queuedepths of the SCSI device.
  2906. */
  2907. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2908. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  2909. IOERR_NO_RESOURCES)) {
  2910. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2911. phba->lpfc_rampdown_queue_depth(phba);
  2912. spin_lock_irqsave(&phba->hbalock, iflag);
  2913. }
  2914. if (irsp->ulpStatus) {
  2915. /* Rsp ring <ringno> error: IOCB */
  2916. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2917. "0328 Rsp Ring %d error: "
  2918. "IOCB Data: "
  2919. "x%x x%x x%x x%x "
  2920. "x%x x%x x%x x%x "
  2921. "x%x x%x x%x x%x "
  2922. "x%x x%x x%x x%x\n",
  2923. pring->ringno,
  2924. irsp->un.ulpWord[0],
  2925. irsp->un.ulpWord[1],
  2926. irsp->un.ulpWord[2],
  2927. irsp->un.ulpWord[3],
  2928. irsp->un.ulpWord[4],
  2929. irsp->un.ulpWord[5],
  2930. *(((uint32_t *) irsp) + 6),
  2931. *(((uint32_t *) irsp) + 7),
  2932. *(((uint32_t *) irsp) + 8),
  2933. *(((uint32_t *) irsp) + 9),
  2934. *(((uint32_t *) irsp) + 10),
  2935. *(((uint32_t *) irsp) + 11),
  2936. *(((uint32_t *) irsp) + 12),
  2937. *(((uint32_t *) irsp) + 13),
  2938. *(((uint32_t *) irsp) + 14),
  2939. *(((uint32_t *) irsp) + 15));
  2940. }
  2941. /*
  2942. * Fetch the IOCB command type and call the correct completion
  2943. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2944. * get freed back to the lpfc_iocb_list by the discovery
  2945. * kernel thread.
  2946. */
  2947. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2948. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2949. switch (type) {
  2950. case LPFC_SOL_IOCB:
  2951. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2952. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2953. spin_lock_irqsave(&phba->hbalock, iflag);
  2954. break;
  2955. case LPFC_UNSOL_IOCB:
  2956. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2957. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2958. spin_lock_irqsave(&phba->hbalock, iflag);
  2959. if (!rc)
  2960. free_saveq = 0;
  2961. break;
  2962. case LPFC_ABORT_IOCB:
  2963. cmdiocbp = NULL;
  2964. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2965. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2966. saveq);
  2967. if (cmdiocbp) {
  2968. /* Call the specified completion routine */
  2969. if (cmdiocbp->iocb_cmpl) {
  2970. spin_unlock_irqrestore(&phba->hbalock,
  2971. iflag);
  2972. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2973. saveq);
  2974. spin_lock_irqsave(&phba->hbalock,
  2975. iflag);
  2976. } else
  2977. __lpfc_sli_release_iocbq(phba,
  2978. cmdiocbp);
  2979. }
  2980. break;
  2981. case LPFC_UNKNOWN_IOCB:
  2982. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2983. char adaptermsg[LPFC_MAX_ADPTMSG];
  2984. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2985. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2986. MAX_MSG_DATA);
  2987. dev_warn(&((phba->pcidev)->dev),
  2988. "lpfc%d: %s\n",
  2989. phba->brd_no, adaptermsg);
  2990. } else {
  2991. /* Unknown IOCB command */
  2992. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2993. "0335 Unknown IOCB "
  2994. "command Data: x%x "
  2995. "x%x x%x x%x\n",
  2996. irsp->ulpCommand,
  2997. irsp->ulpStatus,
  2998. irsp->ulpIoTag,
  2999. irsp->ulpContext);
  3000. }
  3001. break;
  3002. }
  3003. if (free_saveq) {
  3004. list_for_each_entry_safe(rspiocbp, next_iocb,
  3005. &saveq->list, list) {
  3006. list_del(&rspiocbp->list);
  3007. __lpfc_sli_release_iocbq(phba, rspiocbp);
  3008. }
  3009. __lpfc_sli_release_iocbq(phba, saveq);
  3010. }
  3011. rspiocbp = NULL;
  3012. }
  3013. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3014. return rspiocbp;
  3015. }
  3016. /**
  3017. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  3018. * @phba: Pointer to HBA context object.
  3019. * @pring: Pointer to driver SLI ring object.
  3020. * @mask: Host attention register mask for this ring.
  3021. *
  3022. * This routine wraps the actual slow_ring event process routine from the
  3023. * API jump table function pointer from the lpfc_hba struct.
  3024. **/
  3025. void
  3026. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  3027. struct lpfc_sli_ring *pring, uint32_t mask)
  3028. {
  3029. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  3030. }
  3031. /**
  3032. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  3033. * @phba: Pointer to HBA context object.
  3034. * @pring: Pointer to driver SLI ring object.
  3035. * @mask: Host attention register mask for this ring.
  3036. *
  3037. * This function is called from the worker thread when there is a ring event
  3038. * for non-fcp rings. The caller does not hold any lock. The function will
  3039. * remove each response iocb in the response ring and calls the handle
  3040. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3041. **/
  3042. static void
  3043. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  3044. struct lpfc_sli_ring *pring, uint32_t mask)
  3045. {
  3046. struct lpfc_pgp *pgp;
  3047. IOCB_t *entry;
  3048. IOCB_t *irsp = NULL;
  3049. struct lpfc_iocbq *rspiocbp = NULL;
  3050. uint32_t portRspPut, portRspMax;
  3051. unsigned long iflag;
  3052. uint32_t status;
  3053. pgp = &phba->port_gp[pring->ringno];
  3054. spin_lock_irqsave(&phba->hbalock, iflag);
  3055. pring->stats.iocb_event++;
  3056. /*
  3057. * The next available response entry should never exceed the maximum
  3058. * entries. If it does, treat it as an adapter hardware error.
  3059. */
  3060. portRspMax = pring->sli.sli3.numRiocb;
  3061. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3062. if (portRspPut >= portRspMax) {
  3063. /*
  3064. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3065. * rsp ring <portRspMax>
  3066. */
  3067. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3068. "0303 Ring %d handler: portRspPut %d "
  3069. "is bigger than rsp ring %d\n",
  3070. pring->ringno, portRspPut, portRspMax);
  3071. phba->link_state = LPFC_HBA_ERROR;
  3072. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3073. phba->work_hs = HS_FFER3;
  3074. lpfc_handle_eratt(phba);
  3075. return;
  3076. }
  3077. rmb();
  3078. while (pring->sli.sli3.rspidx != portRspPut) {
  3079. /*
  3080. * Build a completion list and call the appropriate handler.
  3081. * The process is to get the next available response iocb, get
  3082. * a free iocb from the list, copy the response data into the
  3083. * free iocb, insert to the continuation list, and update the
  3084. * next response index to slim. This process makes response
  3085. * iocb's in the ring available to DMA as fast as possible but
  3086. * pays a penalty for a copy operation. Since the iocb is
  3087. * only 32 bytes, this penalty is considered small relative to
  3088. * the PCI reads for register values and a slim write. When
  3089. * the ulpLe field is set, the entire Command has been
  3090. * received.
  3091. */
  3092. entry = lpfc_resp_iocb(phba, pring);
  3093. phba->last_completion_time = jiffies;
  3094. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3095. if (rspiocbp == NULL) {
  3096. printk(KERN_ERR "%s: out of buffers! Failing "
  3097. "completion.\n", __func__);
  3098. break;
  3099. }
  3100. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3101. phba->iocb_rsp_size);
  3102. irsp = &rspiocbp->iocb;
  3103. if (++pring->sli.sli3.rspidx >= portRspMax)
  3104. pring->sli.sli3.rspidx = 0;
  3105. if (pring->ringno == LPFC_ELS_RING) {
  3106. lpfc_debugfs_slow_ring_trc(phba,
  3107. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3108. *(((uint32_t *) irsp) + 4),
  3109. *(((uint32_t *) irsp) + 6),
  3110. *(((uint32_t *) irsp) + 7));
  3111. }
  3112. writel(pring->sli.sli3.rspidx,
  3113. &phba->host_gp[pring->ringno].rspGetInx);
  3114. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3115. /* Handle the response IOCB */
  3116. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3117. spin_lock_irqsave(&phba->hbalock, iflag);
  3118. /*
  3119. * If the port response put pointer has not been updated, sync
  3120. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3121. * response put pointer.
  3122. */
  3123. if (pring->sli.sli3.rspidx == portRspPut) {
  3124. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3125. }
  3126. } /* while (pring->sli.sli3.rspidx != portRspPut) */
  3127. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3128. /* At least one response entry has been freed */
  3129. pring->stats.iocb_rsp_full++;
  3130. /* SET RxRE_RSP in Chip Att register */
  3131. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3132. writel(status, phba->CAregaddr);
  3133. readl(phba->CAregaddr); /* flush */
  3134. }
  3135. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3136. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3137. pring->stats.iocb_cmd_empty++;
  3138. /* Force update of the local copy of cmdGetInx */
  3139. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3140. lpfc_sli_resume_iocb(phba, pring);
  3141. if ((pring->lpfc_sli_cmd_available))
  3142. (pring->lpfc_sli_cmd_available) (phba, pring);
  3143. }
  3144. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3145. return;
  3146. }
  3147. /**
  3148. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3149. * @phba: Pointer to HBA context object.
  3150. * @pring: Pointer to driver SLI ring object.
  3151. * @mask: Host attention register mask for this ring.
  3152. *
  3153. * This function is called from the worker thread when there is a pending
  3154. * ELS response iocb on the driver internal slow-path response iocb worker
  3155. * queue. The caller does not hold any lock. The function will remove each
  3156. * response iocb from the response worker queue and calls the handle
  3157. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3158. **/
  3159. static void
  3160. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3161. struct lpfc_sli_ring *pring, uint32_t mask)
  3162. {
  3163. struct lpfc_iocbq *irspiocbq;
  3164. struct hbq_dmabuf *dmabuf;
  3165. struct lpfc_cq_event *cq_event;
  3166. unsigned long iflag;
  3167. spin_lock_irqsave(&phba->hbalock, iflag);
  3168. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3169. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3170. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3171. /* Get the response iocb from the head of work queue */
  3172. spin_lock_irqsave(&phba->hbalock, iflag);
  3173. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3174. cq_event, struct lpfc_cq_event, list);
  3175. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3176. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3177. case CQE_CODE_COMPL_WQE:
  3178. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3179. cq_event);
  3180. /* Translate ELS WCQE to response IOCBQ */
  3181. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3182. irspiocbq);
  3183. if (irspiocbq)
  3184. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3185. irspiocbq);
  3186. break;
  3187. case CQE_CODE_RECEIVE:
  3188. case CQE_CODE_RECEIVE_V1:
  3189. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3190. cq_event);
  3191. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3192. break;
  3193. default:
  3194. break;
  3195. }
  3196. }
  3197. }
  3198. /**
  3199. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3200. * @phba: Pointer to HBA context object.
  3201. * @pring: Pointer to driver SLI ring object.
  3202. *
  3203. * This function aborts all iocbs in the given ring and frees all the iocb
  3204. * objects in txq. This function issues an abort iocb for all the iocb commands
  3205. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3206. * the return of this function. The caller is not required to hold any locks.
  3207. **/
  3208. void
  3209. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3210. {
  3211. LIST_HEAD(completions);
  3212. struct lpfc_iocbq *iocb, *next_iocb;
  3213. if (pring->ringno == LPFC_ELS_RING) {
  3214. lpfc_fabric_abort_hba(phba);
  3215. }
  3216. /* Error everything on txq and txcmplq
  3217. * First do the txq.
  3218. */
  3219. spin_lock_irq(&phba->hbalock);
  3220. list_splice_init(&pring->txq, &completions);
  3221. /* Next issue ABTS for everything on the txcmplq */
  3222. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3223. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3224. spin_unlock_irq(&phba->hbalock);
  3225. /* Cancel all the IOCBs from the completions list */
  3226. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3227. IOERR_SLI_ABORTED);
  3228. }
  3229. /**
  3230. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3231. * @phba: Pointer to HBA context object.
  3232. *
  3233. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3234. * objects in txq and txcmplq. This function will not issue abort iocbs
  3235. * for all the iocb commands in txcmplq, they will just be returned with
  3236. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3237. * slot has been permanently disabled.
  3238. **/
  3239. void
  3240. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3241. {
  3242. LIST_HEAD(txq);
  3243. LIST_HEAD(txcmplq);
  3244. struct lpfc_sli *psli = &phba->sli;
  3245. struct lpfc_sli_ring *pring;
  3246. /* Currently, only one fcp ring */
  3247. pring = &psli->ring[psli->fcp_ring];
  3248. spin_lock_irq(&phba->hbalock);
  3249. /* Retrieve everything on txq */
  3250. list_splice_init(&pring->txq, &txq);
  3251. /* Retrieve everything on the txcmplq */
  3252. list_splice_init(&pring->txcmplq, &txcmplq);
  3253. /* Indicate the I/O queues are flushed */
  3254. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3255. spin_unlock_irq(&phba->hbalock);
  3256. /* Flush the txq */
  3257. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3258. IOERR_SLI_DOWN);
  3259. /* Flush the txcmpq */
  3260. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3261. IOERR_SLI_DOWN);
  3262. }
  3263. /**
  3264. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3265. * @phba: Pointer to HBA context object.
  3266. * @mask: Bit mask to be checked.
  3267. *
  3268. * This function reads the host status register and compares
  3269. * with the provided bit mask to check if HBA completed
  3270. * the restart. This function will wait in a loop for the
  3271. * HBA to complete restart. If the HBA does not restart within
  3272. * 15 iterations, the function will reset the HBA again. The
  3273. * function returns 1 when HBA fail to restart otherwise returns
  3274. * zero.
  3275. **/
  3276. static int
  3277. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3278. {
  3279. uint32_t status;
  3280. int i = 0;
  3281. int retval = 0;
  3282. /* Read the HBA Host Status Register */
  3283. if (lpfc_readl(phba->HSregaddr, &status))
  3284. return 1;
  3285. /*
  3286. * Check status register every 100ms for 5 retries, then every
  3287. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3288. * every 2.5 sec for 4.
  3289. * Break our of the loop if errors occurred during init.
  3290. */
  3291. while (((status & mask) != mask) &&
  3292. !(status & HS_FFERM) &&
  3293. i++ < 20) {
  3294. if (i <= 5)
  3295. msleep(10);
  3296. else if (i <= 10)
  3297. msleep(500);
  3298. else
  3299. msleep(2500);
  3300. if (i == 15) {
  3301. /* Do post */
  3302. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3303. lpfc_sli_brdrestart(phba);
  3304. }
  3305. /* Read the HBA Host Status Register */
  3306. if (lpfc_readl(phba->HSregaddr, &status)) {
  3307. retval = 1;
  3308. break;
  3309. }
  3310. }
  3311. /* Check to see if any errors occurred during init */
  3312. if ((status & HS_FFERM) || (i >= 20)) {
  3313. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3314. "2751 Adapter failed to restart, "
  3315. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3316. status,
  3317. readl(phba->MBslimaddr + 0xa8),
  3318. readl(phba->MBslimaddr + 0xac));
  3319. phba->link_state = LPFC_HBA_ERROR;
  3320. retval = 1;
  3321. }
  3322. return retval;
  3323. }
  3324. /**
  3325. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3326. * @phba: Pointer to HBA context object.
  3327. * @mask: Bit mask to be checked.
  3328. *
  3329. * This function checks the host status register to check if HBA is
  3330. * ready. This function will wait in a loop for the HBA to be ready
  3331. * If the HBA is not ready , the function will will reset the HBA PCI
  3332. * function again. The function returns 1 when HBA fail to be ready
  3333. * otherwise returns zero.
  3334. **/
  3335. static int
  3336. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3337. {
  3338. uint32_t status;
  3339. int retval = 0;
  3340. /* Read the HBA Host Status Register */
  3341. status = lpfc_sli4_post_status_check(phba);
  3342. if (status) {
  3343. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3344. lpfc_sli_brdrestart(phba);
  3345. status = lpfc_sli4_post_status_check(phba);
  3346. }
  3347. /* Check to see if any errors occurred during init */
  3348. if (status) {
  3349. phba->link_state = LPFC_HBA_ERROR;
  3350. retval = 1;
  3351. } else
  3352. phba->sli4_hba.intr_enable = 0;
  3353. return retval;
  3354. }
  3355. /**
  3356. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3357. * @phba: Pointer to HBA context object.
  3358. * @mask: Bit mask to be checked.
  3359. *
  3360. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3361. * from the API jump table function pointer from the lpfc_hba struct.
  3362. **/
  3363. int
  3364. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3365. {
  3366. return phba->lpfc_sli_brdready(phba, mask);
  3367. }
  3368. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3369. /**
  3370. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3371. * @phba: Pointer to HBA context object.
  3372. *
  3373. * This function is called before resetting an HBA. This function is called
  3374. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3375. **/
  3376. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3377. {
  3378. uint32_t __iomem *resp_buf;
  3379. uint32_t __iomem *mbox_buf;
  3380. volatile uint32_t mbox;
  3381. uint32_t hc_copy, ha_copy, resp_data;
  3382. int i;
  3383. uint8_t hdrtype;
  3384. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3385. if (hdrtype != 0x80 ||
  3386. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3387. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3388. return;
  3389. /*
  3390. * Tell the other part of the chip to suspend temporarily all
  3391. * its DMA activity.
  3392. */
  3393. resp_buf = phba->MBslimaddr;
  3394. /* Disable the error attention */
  3395. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3396. return;
  3397. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3398. readl(phba->HCregaddr); /* flush */
  3399. phba->link_flag |= LS_IGNORE_ERATT;
  3400. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3401. return;
  3402. if (ha_copy & HA_ERATT) {
  3403. /* Clear Chip error bit */
  3404. writel(HA_ERATT, phba->HAregaddr);
  3405. phba->pport->stopped = 1;
  3406. }
  3407. mbox = 0;
  3408. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3409. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3410. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3411. mbox_buf = phba->MBslimaddr;
  3412. writel(mbox, mbox_buf);
  3413. for (i = 0; i < 50; i++) {
  3414. if (lpfc_readl((resp_buf + 1), &resp_data))
  3415. return;
  3416. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3417. mdelay(1);
  3418. else
  3419. break;
  3420. }
  3421. resp_data = 0;
  3422. if (lpfc_readl((resp_buf + 1), &resp_data))
  3423. return;
  3424. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3425. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3426. phba->pport->stopped)
  3427. goto restore_hc;
  3428. else
  3429. goto clear_errat;
  3430. }
  3431. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3432. resp_data = 0;
  3433. for (i = 0; i < 500; i++) {
  3434. if (lpfc_readl(resp_buf, &resp_data))
  3435. return;
  3436. if (resp_data != mbox)
  3437. mdelay(1);
  3438. else
  3439. break;
  3440. }
  3441. clear_errat:
  3442. while (++i < 500) {
  3443. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3444. return;
  3445. if (!(ha_copy & HA_ERATT))
  3446. mdelay(1);
  3447. else
  3448. break;
  3449. }
  3450. if (readl(phba->HAregaddr) & HA_ERATT) {
  3451. writel(HA_ERATT, phba->HAregaddr);
  3452. phba->pport->stopped = 1;
  3453. }
  3454. restore_hc:
  3455. phba->link_flag &= ~LS_IGNORE_ERATT;
  3456. writel(hc_copy, phba->HCregaddr);
  3457. readl(phba->HCregaddr); /* flush */
  3458. }
  3459. /**
  3460. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3461. * @phba: Pointer to HBA context object.
  3462. *
  3463. * This function issues a kill_board mailbox command and waits for
  3464. * the error attention interrupt. This function is called for stopping
  3465. * the firmware processing. The caller is not required to hold any
  3466. * locks. This function calls lpfc_hba_down_post function to free
  3467. * any pending commands after the kill. The function will return 1 when it
  3468. * fails to kill the board else will return 0.
  3469. **/
  3470. int
  3471. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3472. {
  3473. struct lpfc_sli *psli;
  3474. LPFC_MBOXQ_t *pmb;
  3475. uint32_t status;
  3476. uint32_t ha_copy;
  3477. int retval;
  3478. int i = 0;
  3479. psli = &phba->sli;
  3480. /* Kill HBA */
  3481. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3482. "0329 Kill HBA Data: x%x x%x\n",
  3483. phba->pport->port_state, psli->sli_flag);
  3484. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3485. if (!pmb)
  3486. return 1;
  3487. /* Disable the error attention */
  3488. spin_lock_irq(&phba->hbalock);
  3489. if (lpfc_readl(phba->HCregaddr, &status)) {
  3490. spin_unlock_irq(&phba->hbalock);
  3491. mempool_free(pmb, phba->mbox_mem_pool);
  3492. return 1;
  3493. }
  3494. status &= ~HC_ERINT_ENA;
  3495. writel(status, phba->HCregaddr);
  3496. readl(phba->HCregaddr); /* flush */
  3497. phba->link_flag |= LS_IGNORE_ERATT;
  3498. spin_unlock_irq(&phba->hbalock);
  3499. lpfc_kill_board(phba, pmb);
  3500. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3501. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3502. if (retval != MBX_SUCCESS) {
  3503. if (retval != MBX_BUSY)
  3504. mempool_free(pmb, phba->mbox_mem_pool);
  3505. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3506. "2752 KILL_BOARD command failed retval %d\n",
  3507. retval);
  3508. spin_lock_irq(&phba->hbalock);
  3509. phba->link_flag &= ~LS_IGNORE_ERATT;
  3510. spin_unlock_irq(&phba->hbalock);
  3511. return 1;
  3512. }
  3513. spin_lock_irq(&phba->hbalock);
  3514. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3515. spin_unlock_irq(&phba->hbalock);
  3516. mempool_free(pmb, phba->mbox_mem_pool);
  3517. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3518. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3519. * 3 seconds we still set HBA_ERROR state because the status of the
  3520. * board is now undefined.
  3521. */
  3522. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3523. return 1;
  3524. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3525. mdelay(100);
  3526. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3527. return 1;
  3528. }
  3529. del_timer_sync(&psli->mbox_tmo);
  3530. if (ha_copy & HA_ERATT) {
  3531. writel(HA_ERATT, phba->HAregaddr);
  3532. phba->pport->stopped = 1;
  3533. }
  3534. spin_lock_irq(&phba->hbalock);
  3535. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3536. psli->mbox_active = NULL;
  3537. phba->link_flag &= ~LS_IGNORE_ERATT;
  3538. spin_unlock_irq(&phba->hbalock);
  3539. lpfc_hba_down_post(phba);
  3540. phba->link_state = LPFC_HBA_ERROR;
  3541. return ha_copy & HA_ERATT ? 0 : 1;
  3542. }
  3543. /**
  3544. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3545. * @phba: Pointer to HBA context object.
  3546. *
  3547. * This function resets the HBA by writing HC_INITFF to the control
  3548. * register. After the HBA resets, this function resets all the iocb ring
  3549. * indices. This function disables PCI layer parity checking during
  3550. * the reset.
  3551. * This function returns 0 always.
  3552. * The caller is not required to hold any locks.
  3553. **/
  3554. int
  3555. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3556. {
  3557. struct lpfc_sli *psli;
  3558. struct lpfc_sli_ring *pring;
  3559. uint16_t cfg_value;
  3560. int i;
  3561. psli = &phba->sli;
  3562. /* Reset HBA */
  3563. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3564. "0325 Reset HBA Data: x%x x%x\n",
  3565. phba->pport->port_state, psli->sli_flag);
  3566. /* perform board reset */
  3567. phba->fc_eventTag = 0;
  3568. phba->link_events = 0;
  3569. phba->pport->fc_myDID = 0;
  3570. phba->pport->fc_prevDID = 0;
  3571. /* Turn off parity checking and serr during the physical reset */
  3572. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3573. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3574. (cfg_value &
  3575. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3576. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3577. /* Now toggle INITFF bit in the Host Control Register */
  3578. writel(HC_INITFF, phba->HCregaddr);
  3579. mdelay(1);
  3580. readl(phba->HCregaddr); /* flush */
  3581. writel(0, phba->HCregaddr);
  3582. readl(phba->HCregaddr); /* flush */
  3583. /* Restore PCI cmd register */
  3584. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3585. /* Initialize relevant SLI info */
  3586. for (i = 0; i < psli->num_rings; i++) {
  3587. pring = &psli->ring[i];
  3588. pring->flag = 0;
  3589. pring->sli.sli3.rspidx = 0;
  3590. pring->sli.sli3.next_cmdidx = 0;
  3591. pring->sli.sli3.local_getidx = 0;
  3592. pring->sli.sli3.cmdidx = 0;
  3593. pring->missbufcnt = 0;
  3594. }
  3595. phba->link_state = LPFC_WARM_START;
  3596. return 0;
  3597. }
  3598. /**
  3599. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3600. * @phba: Pointer to HBA context object.
  3601. *
  3602. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3603. * checking during resets the device. The caller is not required to hold
  3604. * any locks.
  3605. *
  3606. * This function returns 0 always.
  3607. **/
  3608. int
  3609. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3610. {
  3611. struct lpfc_sli *psli = &phba->sli;
  3612. uint16_t cfg_value;
  3613. int rc;
  3614. /* Reset HBA */
  3615. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3616. "0295 Reset HBA Data: x%x x%x\n",
  3617. phba->pport->port_state, psli->sli_flag);
  3618. /* perform board reset */
  3619. phba->fc_eventTag = 0;
  3620. phba->link_events = 0;
  3621. phba->pport->fc_myDID = 0;
  3622. phba->pport->fc_prevDID = 0;
  3623. spin_lock_irq(&phba->hbalock);
  3624. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3625. phba->fcf.fcf_flag = 0;
  3626. spin_unlock_irq(&phba->hbalock);
  3627. /* Now physically reset the device */
  3628. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3629. "0389 Performing PCI function reset!\n");
  3630. /* Turn off parity checking and serr during the physical reset */
  3631. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3632. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3633. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3634. /* Perform FCoE PCI function reset before freeing queue memory */
  3635. rc = lpfc_pci_function_reset(phba);
  3636. lpfc_sli4_queue_destroy(phba);
  3637. /* Restore PCI cmd register */
  3638. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3639. return rc;
  3640. }
  3641. /**
  3642. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3643. * @phba: Pointer to HBA context object.
  3644. *
  3645. * This function is called in the SLI initialization code path to
  3646. * restart the HBA. The caller is not required to hold any lock.
  3647. * This function writes MBX_RESTART mailbox command to the SLIM and
  3648. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3649. * function to free any pending commands. The function enables
  3650. * POST only during the first initialization. The function returns zero.
  3651. * The function does not guarantee completion of MBX_RESTART mailbox
  3652. * command before the return of this function.
  3653. **/
  3654. static int
  3655. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3656. {
  3657. MAILBOX_t *mb;
  3658. struct lpfc_sli *psli;
  3659. volatile uint32_t word0;
  3660. void __iomem *to_slim;
  3661. uint32_t hba_aer_enabled;
  3662. spin_lock_irq(&phba->hbalock);
  3663. /* Take PCIe device Advanced Error Reporting (AER) state */
  3664. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3665. psli = &phba->sli;
  3666. /* Restart HBA */
  3667. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3668. "0337 Restart HBA Data: x%x x%x\n",
  3669. phba->pport->port_state, psli->sli_flag);
  3670. word0 = 0;
  3671. mb = (MAILBOX_t *) &word0;
  3672. mb->mbxCommand = MBX_RESTART;
  3673. mb->mbxHc = 1;
  3674. lpfc_reset_barrier(phba);
  3675. to_slim = phba->MBslimaddr;
  3676. writel(*(uint32_t *) mb, to_slim);
  3677. readl(to_slim); /* flush */
  3678. /* Only skip post after fc_ffinit is completed */
  3679. if (phba->pport->port_state)
  3680. word0 = 1; /* This is really setting up word1 */
  3681. else
  3682. word0 = 0; /* This is really setting up word1 */
  3683. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3684. writel(*(uint32_t *) mb, to_slim);
  3685. readl(to_slim); /* flush */
  3686. lpfc_sli_brdreset(phba);
  3687. phba->pport->stopped = 0;
  3688. phba->link_state = LPFC_INIT_START;
  3689. phba->hba_flag = 0;
  3690. spin_unlock_irq(&phba->hbalock);
  3691. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3692. psli->stats_start = get_seconds();
  3693. /* Give the INITFF and Post time to settle. */
  3694. mdelay(100);
  3695. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3696. if (hba_aer_enabled)
  3697. pci_disable_pcie_error_reporting(phba->pcidev);
  3698. lpfc_hba_down_post(phba);
  3699. return 0;
  3700. }
  3701. /**
  3702. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3703. * @phba: Pointer to HBA context object.
  3704. *
  3705. * This function is called in the SLI initialization code path to restart
  3706. * a SLI4 HBA. The caller is not required to hold any lock.
  3707. * At the end of the function, it calls lpfc_hba_down_post function to
  3708. * free any pending commands.
  3709. **/
  3710. static int
  3711. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3712. {
  3713. struct lpfc_sli *psli = &phba->sli;
  3714. uint32_t hba_aer_enabled;
  3715. int rc;
  3716. /* Restart HBA */
  3717. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3718. "0296 Restart HBA Data: x%x x%x\n",
  3719. phba->pport->port_state, psli->sli_flag);
  3720. /* Take PCIe device Advanced Error Reporting (AER) state */
  3721. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3722. rc = lpfc_sli4_brdreset(phba);
  3723. spin_lock_irq(&phba->hbalock);
  3724. phba->pport->stopped = 0;
  3725. phba->link_state = LPFC_INIT_START;
  3726. phba->hba_flag = 0;
  3727. spin_unlock_irq(&phba->hbalock);
  3728. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3729. psli->stats_start = get_seconds();
  3730. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3731. if (hba_aer_enabled)
  3732. pci_disable_pcie_error_reporting(phba->pcidev);
  3733. lpfc_hba_down_post(phba);
  3734. return rc;
  3735. }
  3736. /**
  3737. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3738. * @phba: Pointer to HBA context object.
  3739. *
  3740. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3741. * API jump table function pointer from the lpfc_hba struct.
  3742. **/
  3743. int
  3744. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3745. {
  3746. return phba->lpfc_sli_brdrestart(phba);
  3747. }
  3748. /**
  3749. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3750. * @phba: Pointer to HBA context object.
  3751. *
  3752. * This function is called after a HBA restart to wait for successful
  3753. * restart of the HBA. Successful restart of the HBA is indicated by
  3754. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3755. * iteration, the function will restart the HBA again. The function returns
  3756. * zero if HBA successfully restarted else returns negative error code.
  3757. **/
  3758. static int
  3759. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3760. {
  3761. uint32_t status, i = 0;
  3762. /* Read the HBA Host Status Register */
  3763. if (lpfc_readl(phba->HSregaddr, &status))
  3764. return -EIO;
  3765. /* Check status register to see what current state is */
  3766. i = 0;
  3767. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3768. /* Check every 10ms for 10 retries, then every 100ms for 90
  3769. * retries, then every 1 sec for 50 retires for a total of
  3770. * ~60 seconds before reset the board again and check every
  3771. * 1 sec for 50 retries. The up to 60 seconds before the
  3772. * board ready is required by the Falcon FIPS zeroization
  3773. * complete, and any reset the board in between shall cause
  3774. * restart of zeroization, further delay the board ready.
  3775. */
  3776. if (i++ >= 200) {
  3777. /* Adapter failed to init, timeout, status reg
  3778. <status> */
  3779. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3780. "0436 Adapter failed to init, "
  3781. "timeout, status reg x%x, "
  3782. "FW Data: A8 x%x AC x%x\n", status,
  3783. readl(phba->MBslimaddr + 0xa8),
  3784. readl(phba->MBslimaddr + 0xac));
  3785. phba->link_state = LPFC_HBA_ERROR;
  3786. return -ETIMEDOUT;
  3787. }
  3788. /* Check to see if any errors occurred during init */
  3789. if (status & HS_FFERM) {
  3790. /* ERROR: During chipset initialization */
  3791. /* Adapter failed to init, chipset, status reg
  3792. <status> */
  3793. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3794. "0437 Adapter failed to init, "
  3795. "chipset, status reg x%x, "
  3796. "FW Data: A8 x%x AC x%x\n", status,
  3797. readl(phba->MBslimaddr + 0xa8),
  3798. readl(phba->MBslimaddr + 0xac));
  3799. phba->link_state = LPFC_HBA_ERROR;
  3800. return -EIO;
  3801. }
  3802. if (i <= 10)
  3803. msleep(10);
  3804. else if (i <= 100)
  3805. msleep(100);
  3806. else
  3807. msleep(1000);
  3808. if (i == 150) {
  3809. /* Do post */
  3810. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3811. lpfc_sli_brdrestart(phba);
  3812. }
  3813. /* Read the HBA Host Status Register */
  3814. if (lpfc_readl(phba->HSregaddr, &status))
  3815. return -EIO;
  3816. }
  3817. /* Check to see if any errors occurred during init */
  3818. if (status & HS_FFERM) {
  3819. /* ERROR: During chipset initialization */
  3820. /* Adapter failed to init, chipset, status reg <status> */
  3821. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3822. "0438 Adapter failed to init, chipset, "
  3823. "status reg x%x, "
  3824. "FW Data: A8 x%x AC x%x\n", status,
  3825. readl(phba->MBslimaddr + 0xa8),
  3826. readl(phba->MBslimaddr + 0xac));
  3827. phba->link_state = LPFC_HBA_ERROR;
  3828. return -EIO;
  3829. }
  3830. /* Clear all interrupt enable conditions */
  3831. writel(0, phba->HCregaddr);
  3832. readl(phba->HCregaddr); /* flush */
  3833. /* setup host attn register */
  3834. writel(0xffffffff, phba->HAregaddr);
  3835. readl(phba->HAregaddr); /* flush */
  3836. return 0;
  3837. }
  3838. /**
  3839. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3840. *
  3841. * This function calculates and returns the number of HBQs required to be
  3842. * configured.
  3843. **/
  3844. int
  3845. lpfc_sli_hbq_count(void)
  3846. {
  3847. return ARRAY_SIZE(lpfc_hbq_defs);
  3848. }
  3849. /**
  3850. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3851. *
  3852. * This function adds the number of hbq entries in every HBQ to get
  3853. * the total number of hbq entries required for the HBA and returns
  3854. * the total count.
  3855. **/
  3856. static int
  3857. lpfc_sli_hbq_entry_count(void)
  3858. {
  3859. int hbq_count = lpfc_sli_hbq_count();
  3860. int count = 0;
  3861. int i;
  3862. for (i = 0; i < hbq_count; ++i)
  3863. count += lpfc_hbq_defs[i]->entry_count;
  3864. return count;
  3865. }
  3866. /**
  3867. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3868. *
  3869. * This function calculates amount of memory required for all hbq entries
  3870. * to be configured and returns the total memory required.
  3871. **/
  3872. int
  3873. lpfc_sli_hbq_size(void)
  3874. {
  3875. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3876. }
  3877. /**
  3878. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3879. * @phba: Pointer to HBA context object.
  3880. *
  3881. * This function is called during the SLI initialization to configure
  3882. * all the HBQs and post buffers to the HBQ. The caller is not
  3883. * required to hold any locks. This function will return zero if successful
  3884. * else it will return negative error code.
  3885. **/
  3886. static int
  3887. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3888. {
  3889. int hbq_count = lpfc_sli_hbq_count();
  3890. LPFC_MBOXQ_t *pmb;
  3891. MAILBOX_t *pmbox;
  3892. uint32_t hbqno;
  3893. uint32_t hbq_entry_index;
  3894. /* Get a Mailbox buffer to setup mailbox
  3895. * commands for HBA initialization
  3896. */
  3897. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3898. if (!pmb)
  3899. return -ENOMEM;
  3900. pmbox = &pmb->u.mb;
  3901. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3902. phba->link_state = LPFC_INIT_MBX_CMDS;
  3903. phba->hbq_in_use = 1;
  3904. hbq_entry_index = 0;
  3905. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3906. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3907. phba->hbqs[hbqno].hbqPutIdx = 0;
  3908. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3909. phba->hbqs[hbqno].entry_count =
  3910. lpfc_hbq_defs[hbqno]->entry_count;
  3911. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3912. hbq_entry_index, pmb);
  3913. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3914. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3915. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3916. mbxStatus <status>, ring <num> */
  3917. lpfc_printf_log(phba, KERN_ERR,
  3918. LOG_SLI | LOG_VPORT,
  3919. "1805 Adapter failed to init. "
  3920. "Data: x%x x%x x%x\n",
  3921. pmbox->mbxCommand,
  3922. pmbox->mbxStatus, hbqno);
  3923. phba->link_state = LPFC_HBA_ERROR;
  3924. mempool_free(pmb, phba->mbox_mem_pool);
  3925. return -ENXIO;
  3926. }
  3927. }
  3928. phba->hbq_count = hbq_count;
  3929. mempool_free(pmb, phba->mbox_mem_pool);
  3930. /* Initially populate or replenish the HBQs */
  3931. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3932. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3933. return 0;
  3934. }
  3935. /**
  3936. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3937. * @phba: Pointer to HBA context object.
  3938. *
  3939. * This function is called during the SLI initialization to configure
  3940. * all the HBQs and post buffers to the HBQ. The caller is not
  3941. * required to hold any locks. This function will return zero if successful
  3942. * else it will return negative error code.
  3943. **/
  3944. static int
  3945. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3946. {
  3947. phba->hbq_in_use = 1;
  3948. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3949. phba->hbq_count = 1;
  3950. /* Initially populate or replenish the HBQs */
  3951. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3952. return 0;
  3953. }
  3954. /**
  3955. * lpfc_sli_config_port - Issue config port mailbox command
  3956. * @phba: Pointer to HBA context object.
  3957. * @sli_mode: sli mode - 2/3
  3958. *
  3959. * This function is called by the sli intialization code path
  3960. * to issue config_port mailbox command. This function restarts the
  3961. * HBA firmware and issues a config_port mailbox command to configure
  3962. * the SLI interface in the sli mode specified by sli_mode
  3963. * variable. The caller is not required to hold any locks.
  3964. * The function returns 0 if successful, else returns negative error
  3965. * code.
  3966. **/
  3967. int
  3968. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3969. {
  3970. LPFC_MBOXQ_t *pmb;
  3971. uint32_t resetcount = 0, rc = 0, done = 0;
  3972. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3973. if (!pmb) {
  3974. phba->link_state = LPFC_HBA_ERROR;
  3975. return -ENOMEM;
  3976. }
  3977. phba->sli_rev = sli_mode;
  3978. while (resetcount < 2 && !done) {
  3979. spin_lock_irq(&phba->hbalock);
  3980. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3981. spin_unlock_irq(&phba->hbalock);
  3982. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3983. lpfc_sli_brdrestart(phba);
  3984. rc = lpfc_sli_chipset_init(phba);
  3985. if (rc)
  3986. break;
  3987. spin_lock_irq(&phba->hbalock);
  3988. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3989. spin_unlock_irq(&phba->hbalock);
  3990. resetcount++;
  3991. /* Call pre CONFIG_PORT mailbox command initialization. A
  3992. * value of 0 means the call was successful. Any other
  3993. * nonzero value is a failure, but if ERESTART is returned,
  3994. * the driver may reset the HBA and try again.
  3995. */
  3996. rc = lpfc_config_port_prep(phba);
  3997. if (rc == -ERESTART) {
  3998. phba->link_state = LPFC_LINK_UNKNOWN;
  3999. continue;
  4000. } else if (rc)
  4001. break;
  4002. phba->link_state = LPFC_INIT_MBX_CMDS;
  4003. lpfc_config_port(phba, pmb);
  4004. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4005. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  4006. LPFC_SLI3_HBQ_ENABLED |
  4007. LPFC_SLI3_CRP_ENABLED |
  4008. LPFC_SLI3_BG_ENABLED |
  4009. LPFC_SLI3_DSS_ENABLED);
  4010. if (rc != MBX_SUCCESS) {
  4011. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4012. "0442 Adapter failed to init, mbxCmd x%x "
  4013. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  4014. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  4015. spin_lock_irq(&phba->hbalock);
  4016. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  4017. spin_unlock_irq(&phba->hbalock);
  4018. rc = -ENXIO;
  4019. } else {
  4020. /* Allow asynchronous mailbox command to go through */
  4021. spin_lock_irq(&phba->hbalock);
  4022. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  4023. spin_unlock_irq(&phba->hbalock);
  4024. done = 1;
  4025. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  4026. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  4027. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4028. "3110 Port did not grant ASABT\n");
  4029. }
  4030. }
  4031. if (!done) {
  4032. rc = -EINVAL;
  4033. goto do_prep_failed;
  4034. }
  4035. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  4036. if (!pmb->u.mb.un.varCfgPort.cMA) {
  4037. rc = -ENXIO;
  4038. goto do_prep_failed;
  4039. }
  4040. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  4041. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  4042. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  4043. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  4044. phba->max_vpi : phba->max_vports;
  4045. } else
  4046. phba->max_vpi = 0;
  4047. phba->fips_level = 0;
  4048. phba->fips_spec_rev = 0;
  4049. if (pmb->u.mb.un.varCfgPort.gdss) {
  4050. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  4051. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  4052. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  4053. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4054. "2850 Security Crypto Active. FIPS x%d "
  4055. "(Spec Rev: x%d)",
  4056. phba->fips_level, phba->fips_spec_rev);
  4057. }
  4058. if (pmb->u.mb.un.varCfgPort.sec_err) {
  4059. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4060. "2856 Config Port Security Crypto "
  4061. "Error: x%x ",
  4062. pmb->u.mb.un.varCfgPort.sec_err);
  4063. }
  4064. if (pmb->u.mb.un.varCfgPort.gerbm)
  4065. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  4066. if (pmb->u.mb.un.varCfgPort.gcrp)
  4067. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  4068. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  4069. phba->port_gp = phba->mbox->us.s3_pgp.port;
  4070. if (phba->cfg_enable_bg) {
  4071. if (pmb->u.mb.un.varCfgPort.gbg)
  4072. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  4073. else
  4074. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4075. "0443 Adapter did not grant "
  4076. "BlockGuard\n");
  4077. }
  4078. } else {
  4079. phba->hbq_get = NULL;
  4080. phba->port_gp = phba->mbox->us.s2.port;
  4081. phba->max_vpi = 0;
  4082. }
  4083. do_prep_failed:
  4084. mempool_free(pmb, phba->mbox_mem_pool);
  4085. return rc;
  4086. }
  4087. /**
  4088. * lpfc_sli_hba_setup - SLI intialization function
  4089. * @phba: Pointer to HBA context object.
  4090. *
  4091. * This function is the main SLI intialization function. This function
  4092. * is called by the HBA intialization code, HBA reset code and HBA
  4093. * error attention handler code. Caller is not required to hold any
  4094. * locks. This function issues config_port mailbox command to configure
  4095. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4096. * calls the config_port_post function to issue init_link mailbox
  4097. * command and to start the discovery. The function will return zero
  4098. * if successful, else it will return negative error code.
  4099. **/
  4100. int
  4101. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4102. {
  4103. uint32_t rc;
  4104. int mode = 3, i;
  4105. int longs;
  4106. switch (lpfc_sli_mode) {
  4107. case 2:
  4108. if (phba->cfg_enable_npiv) {
  4109. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4110. "1824 NPIV enabled: Override lpfc_sli_mode "
  4111. "parameter (%d) to auto (0).\n",
  4112. lpfc_sli_mode);
  4113. break;
  4114. }
  4115. mode = 2;
  4116. break;
  4117. case 0:
  4118. case 3:
  4119. break;
  4120. default:
  4121. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4122. "1819 Unrecognized lpfc_sli_mode "
  4123. "parameter: %d.\n", lpfc_sli_mode);
  4124. break;
  4125. }
  4126. rc = lpfc_sli_config_port(phba, mode);
  4127. if (rc && lpfc_sli_mode == 3)
  4128. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4129. "1820 Unable to select SLI-3. "
  4130. "Not supported by adapter.\n");
  4131. if (rc && mode != 2)
  4132. rc = lpfc_sli_config_port(phba, 2);
  4133. if (rc)
  4134. goto lpfc_sli_hba_setup_error;
  4135. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4136. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4137. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4138. if (!rc) {
  4139. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4140. "2709 This device supports "
  4141. "Advanced Error Reporting (AER)\n");
  4142. spin_lock_irq(&phba->hbalock);
  4143. phba->hba_flag |= HBA_AER_ENABLED;
  4144. spin_unlock_irq(&phba->hbalock);
  4145. } else {
  4146. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4147. "2708 This device does not support "
  4148. "Advanced Error Reporting (AER)\n");
  4149. phba->cfg_aer_support = 0;
  4150. }
  4151. }
  4152. if (phba->sli_rev == 3) {
  4153. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4154. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4155. } else {
  4156. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4157. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4158. phba->sli3_options = 0;
  4159. }
  4160. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4161. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4162. phba->sli_rev, phba->max_vpi);
  4163. rc = lpfc_sli_ring_map(phba);
  4164. if (rc)
  4165. goto lpfc_sli_hba_setup_error;
  4166. /* Initialize VPIs. */
  4167. if (phba->sli_rev == LPFC_SLI_REV3) {
  4168. /*
  4169. * The VPI bitmask and physical ID array are allocated
  4170. * and initialized once only - at driver load. A port
  4171. * reset doesn't need to reinitialize this memory.
  4172. */
  4173. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4174. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4175. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4176. GFP_KERNEL);
  4177. if (!phba->vpi_bmask) {
  4178. rc = -ENOMEM;
  4179. goto lpfc_sli_hba_setup_error;
  4180. }
  4181. phba->vpi_ids = kzalloc(
  4182. (phba->max_vpi+1) * sizeof(uint16_t),
  4183. GFP_KERNEL);
  4184. if (!phba->vpi_ids) {
  4185. kfree(phba->vpi_bmask);
  4186. rc = -ENOMEM;
  4187. goto lpfc_sli_hba_setup_error;
  4188. }
  4189. for (i = 0; i < phba->max_vpi; i++)
  4190. phba->vpi_ids[i] = i;
  4191. }
  4192. }
  4193. /* Init HBQs */
  4194. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4195. rc = lpfc_sli_hbq_setup(phba);
  4196. if (rc)
  4197. goto lpfc_sli_hba_setup_error;
  4198. }
  4199. spin_lock_irq(&phba->hbalock);
  4200. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4201. spin_unlock_irq(&phba->hbalock);
  4202. rc = lpfc_config_port_post(phba);
  4203. if (rc)
  4204. goto lpfc_sli_hba_setup_error;
  4205. return rc;
  4206. lpfc_sli_hba_setup_error:
  4207. phba->link_state = LPFC_HBA_ERROR;
  4208. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4209. "0445 Firmware initialization failed\n");
  4210. return rc;
  4211. }
  4212. /**
  4213. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4214. * @phba: Pointer to HBA context object.
  4215. * @mboxq: mailbox pointer.
  4216. * This function issue a dump mailbox command to read config region
  4217. * 23 and parse the records in the region and populate driver
  4218. * data structure.
  4219. **/
  4220. static int
  4221. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4222. {
  4223. LPFC_MBOXQ_t *mboxq;
  4224. struct lpfc_dmabuf *mp;
  4225. struct lpfc_mqe *mqe;
  4226. uint32_t data_length;
  4227. int rc;
  4228. /* Program the default value of vlan_id and fc_map */
  4229. phba->valid_vlan = 0;
  4230. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4231. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4232. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4233. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4234. if (!mboxq)
  4235. return -ENOMEM;
  4236. mqe = &mboxq->u.mqe;
  4237. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4238. rc = -ENOMEM;
  4239. goto out_free_mboxq;
  4240. }
  4241. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4242. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4243. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4244. "(%d):2571 Mailbox cmd x%x Status x%x "
  4245. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4246. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4247. "CQ: x%x x%x x%x x%x\n",
  4248. mboxq->vport ? mboxq->vport->vpi : 0,
  4249. bf_get(lpfc_mqe_command, mqe),
  4250. bf_get(lpfc_mqe_status, mqe),
  4251. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4252. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4253. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4254. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4255. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4256. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4257. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4258. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4259. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4260. mboxq->mcqe.word0,
  4261. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4262. mboxq->mcqe.trailer);
  4263. if (rc) {
  4264. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4265. kfree(mp);
  4266. rc = -EIO;
  4267. goto out_free_mboxq;
  4268. }
  4269. data_length = mqe->un.mb_words[5];
  4270. if (data_length > DMP_RGN23_SIZE) {
  4271. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4272. kfree(mp);
  4273. rc = -EIO;
  4274. goto out_free_mboxq;
  4275. }
  4276. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4277. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4278. kfree(mp);
  4279. rc = 0;
  4280. out_free_mboxq:
  4281. mempool_free(mboxq, phba->mbox_mem_pool);
  4282. return rc;
  4283. }
  4284. /**
  4285. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4286. * @phba: pointer to lpfc hba data structure.
  4287. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4288. * @vpd: pointer to the memory to hold resulting port vpd data.
  4289. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4290. * On output, the number of data bytes in @vpd.
  4291. *
  4292. * This routine executes a READ_REV SLI4 mailbox command. In
  4293. * addition, this routine gets the port vpd data.
  4294. *
  4295. * Return codes
  4296. * 0 - successful
  4297. * -ENOMEM - could not allocated memory.
  4298. **/
  4299. static int
  4300. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4301. uint8_t *vpd, uint32_t *vpd_size)
  4302. {
  4303. int rc = 0;
  4304. uint32_t dma_size;
  4305. struct lpfc_dmabuf *dmabuf;
  4306. struct lpfc_mqe *mqe;
  4307. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4308. if (!dmabuf)
  4309. return -ENOMEM;
  4310. /*
  4311. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4312. * mailbox command.
  4313. */
  4314. dma_size = *vpd_size;
  4315. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4316. dma_size,
  4317. &dmabuf->phys,
  4318. GFP_KERNEL);
  4319. if (!dmabuf->virt) {
  4320. kfree(dmabuf);
  4321. return -ENOMEM;
  4322. }
  4323. memset(dmabuf->virt, 0, dma_size);
  4324. /*
  4325. * The SLI4 implementation of READ_REV conflicts at word1,
  4326. * bits 31:16 and SLI4 adds vpd functionality not present
  4327. * in SLI3. This code corrects the conflicts.
  4328. */
  4329. lpfc_read_rev(phba, mboxq);
  4330. mqe = &mboxq->u.mqe;
  4331. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4332. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4333. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4334. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4335. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4336. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4337. if (rc) {
  4338. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4339. dmabuf->virt, dmabuf->phys);
  4340. kfree(dmabuf);
  4341. return -EIO;
  4342. }
  4343. /*
  4344. * The available vpd length cannot be bigger than the
  4345. * DMA buffer passed to the port. Catch the less than
  4346. * case and update the caller's size.
  4347. */
  4348. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4349. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4350. memcpy(vpd, dmabuf->virt, *vpd_size);
  4351. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4352. dmabuf->virt, dmabuf->phys);
  4353. kfree(dmabuf);
  4354. return 0;
  4355. }
  4356. /**
  4357. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4358. * @phba: pointer to lpfc hba data structure.
  4359. *
  4360. * This routine retrieves SLI4 device physical port name this PCI function
  4361. * is attached to.
  4362. *
  4363. * Return codes
  4364. * 0 - successful
  4365. * otherwise - failed to retrieve physical port name
  4366. **/
  4367. static int
  4368. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4369. {
  4370. LPFC_MBOXQ_t *mboxq;
  4371. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4372. struct lpfc_controller_attribute *cntl_attr;
  4373. struct lpfc_mbx_get_port_name *get_port_name;
  4374. void *virtaddr = NULL;
  4375. uint32_t alloclen, reqlen;
  4376. uint32_t shdr_status, shdr_add_status;
  4377. union lpfc_sli4_cfg_shdr *shdr;
  4378. char cport_name = 0;
  4379. int rc;
  4380. /* We assume nothing at this point */
  4381. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4382. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4383. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4384. if (!mboxq)
  4385. return -ENOMEM;
  4386. /* obtain link type and link number via READ_CONFIG */
  4387. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4388. lpfc_sli4_read_config(phba);
  4389. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4390. goto retrieve_ppname;
  4391. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4392. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4393. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4394. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4395. LPFC_SLI4_MBX_NEMBED);
  4396. if (alloclen < reqlen) {
  4397. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4398. "3084 Allocated DMA memory size (%d) is "
  4399. "less than the requested DMA memory size "
  4400. "(%d)\n", alloclen, reqlen);
  4401. rc = -ENOMEM;
  4402. goto out_free_mboxq;
  4403. }
  4404. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4405. virtaddr = mboxq->sge_array->addr[0];
  4406. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4407. shdr = &mbx_cntl_attr->cfg_shdr;
  4408. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4409. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4410. if (shdr_status || shdr_add_status || rc) {
  4411. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4412. "3085 Mailbox x%x (x%x/x%x) failed, "
  4413. "rc:x%x, status:x%x, add_status:x%x\n",
  4414. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4415. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4416. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4417. rc, shdr_status, shdr_add_status);
  4418. rc = -ENXIO;
  4419. goto out_free_mboxq;
  4420. }
  4421. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4422. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4423. phba->sli4_hba.lnk_info.lnk_tp =
  4424. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4425. phba->sli4_hba.lnk_info.lnk_no =
  4426. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4427. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4428. "3086 lnk_type:%d, lnk_numb:%d\n",
  4429. phba->sli4_hba.lnk_info.lnk_tp,
  4430. phba->sli4_hba.lnk_info.lnk_no);
  4431. retrieve_ppname:
  4432. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4433. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4434. sizeof(struct lpfc_mbx_get_port_name) -
  4435. sizeof(struct lpfc_sli4_cfg_mhdr),
  4436. LPFC_SLI4_MBX_EMBED);
  4437. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4438. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4439. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4440. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4441. phba->sli4_hba.lnk_info.lnk_tp);
  4442. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4443. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4444. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4445. if (shdr_status || shdr_add_status || rc) {
  4446. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4447. "3087 Mailbox x%x (x%x/x%x) failed: "
  4448. "rc:x%x, status:x%x, add_status:x%x\n",
  4449. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4450. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4451. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4452. rc, shdr_status, shdr_add_status);
  4453. rc = -ENXIO;
  4454. goto out_free_mboxq;
  4455. }
  4456. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4457. case LPFC_LINK_NUMBER_0:
  4458. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4459. &get_port_name->u.response);
  4460. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4461. break;
  4462. case LPFC_LINK_NUMBER_1:
  4463. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4464. &get_port_name->u.response);
  4465. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4466. break;
  4467. case LPFC_LINK_NUMBER_2:
  4468. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4469. &get_port_name->u.response);
  4470. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4471. break;
  4472. case LPFC_LINK_NUMBER_3:
  4473. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4474. &get_port_name->u.response);
  4475. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4476. break;
  4477. default:
  4478. break;
  4479. }
  4480. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4481. phba->Port[0] = cport_name;
  4482. phba->Port[1] = '\0';
  4483. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4484. "3091 SLI get port name: %s\n", phba->Port);
  4485. }
  4486. out_free_mboxq:
  4487. if (rc != MBX_TIMEOUT) {
  4488. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4489. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4490. else
  4491. mempool_free(mboxq, phba->mbox_mem_pool);
  4492. }
  4493. return rc;
  4494. }
  4495. /**
  4496. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4497. * @phba: pointer to lpfc hba data structure.
  4498. *
  4499. * This routine is called to explicitly arm the SLI4 device's completion and
  4500. * event queues
  4501. **/
  4502. static void
  4503. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4504. {
  4505. int fcp_eqidx;
  4506. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4507. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4508. fcp_eqidx = 0;
  4509. if (phba->sli4_hba.fcp_cq) {
  4510. do {
  4511. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4512. LPFC_QUEUE_REARM);
  4513. } while (++fcp_eqidx < phba->cfg_fcp_io_channel);
  4514. }
  4515. if (phba->sli4_hba.hba_eq) {
  4516. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel;
  4517. fcp_eqidx++)
  4518. lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx],
  4519. LPFC_QUEUE_REARM);
  4520. }
  4521. }
  4522. /**
  4523. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4524. * @phba: Pointer to HBA context object.
  4525. * @type: The resource extent type.
  4526. * @extnt_count: buffer to hold port available extent count.
  4527. * @extnt_size: buffer to hold element count per extent.
  4528. *
  4529. * This function calls the port and retrievs the number of available
  4530. * extents and their size for a particular extent type.
  4531. *
  4532. * Returns: 0 if successful. Nonzero otherwise.
  4533. **/
  4534. int
  4535. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4536. uint16_t *extnt_count, uint16_t *extnt_size)
  4537. {
  4538. int rc = 0;
  4539. uint32_t length;
  4540. uint32_t mbox_tmo;
  4541. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4542. LPFC_MBOXQ_t *mbox;
  4543. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4544. if (!mbox)
  4545. return -ENOMEM;
  4546. /* Find out how many extents are available for this resource type */
  4547. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4548. sizeof(struct lpfc_sli4_cfg_mhdr));
  4549. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4550. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4551. length, LPFC_SLI4_MBX_EMBED);
  4552. /* Send an extents count of 0 - the GET doesn't use it. */
  4553. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4554. LPFC_SLI4_MBX_EMBED);
  4555. if (unlikely(rc)) {
  4556. rc = -EIO;
  4557. goto err_exit;
  4558. }
  4559. if (!phba->sli4_hba.intr_enable)
  4560. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4561. else {
  4562. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4563. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4564. }
  4565. if (unlikely(rc)) {
  4566. rc = -EIO;
  4567. goto err_exit;
  4568. }
  4569. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4570. if (bf_get(lpfc_mbox_hdr_status,
  4571. &rsrc_info->header.cfg_shdr.response)) {
  4572. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4573. "2930 Failed to get resource extents "
  4574. "Status 0x%x Add'l Status 0x%x\n",
  4575. bf_get(lpfc_mbox_hdr_status,
  4576. &rsrc_info->header.cfg_shdr.response),
  4577. bf_get(lpfc_mbox_hdr_add_status,
  4578. &rsrc_info->header.cfg_shdr.response));
  4579. rc = -EIO;
  4580. goto err_exit;
  4581. }
  4582. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4583. &rsrc_info->u.rsp);
  4584. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4585. &rsrc_info->u.rsp);
  4586. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4587. "3162 Retrieved extents type-%d from port: count:%d, "
  4588. "size:%d\n", type, *extnt_count, *extnt_size);
  4589. err_exit:
  4590. mempool_free(mbox, phba->mbox_mem_pool);
  4591. return rc;
  4592. }
  4593. /**
  4594. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4595. * @phba: Pointer to HBA context object.
  4596. * @type: The extent type to check.
  4597. *
  4598. * This function reads the current available extents from the port and checks
  4599. * if the extent count or extent size has changed since the last access.
  4600. * Callers use this routine post port reset to understand if there is a
  4601. * extent reprovisioning requirement.
  4602. *
  4603. * Returns:
  4604. * -Error: error indicates problem.
  4605. * 1: Extent count or size has changed.
  4606. * 0: No changes.
  4607. **/
  4608. static int
  4609. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4610. {
  4611. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4612. uint16_t size_diff, rsrc_ext_size;
  4613. int rc = 0;
  4614. struct lpfc_rsrc_blks *rsrc_entry;
  4615. struct list_head *rsrc_blk_list = NULL;
  4616. size_diff = 0;
  4617. curr_ext_cnt = 0;
  4618. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4619. &rsrc_ext_cnt,
  4620. &rsrc_ext_size);
  4621. if (unlikely(rc))
  4622. return -EIO;
  4623. switch (type) {
  4624. case LPFC_RSC_TYPE_FCOE_RPI:
  4625. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4626. break;
  4627. case LPFC_RSC_TYPE_FCOE_VPI:
  4628. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4629. break;
  4630. case LPFC_RSC_TYPE_FCOE_XRI:
  4631. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4632. break;
  4633. case LPFC_RSC_TYPE_FCOE_VFI:
  4634. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4635. break;
  4636. default:
  4637. break;
  4638. }
  4639. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4640. curr_ext_cnt++;
  4641. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4642. size_diff++;
  4643. }
  4644. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4645. rc = 1;
  4646. return rc;
  4647. }
  4648. /**
  4649. * lpfc_sli4_cfg_post_extnts -
  4650. * @phba: Pointer to HBA context object.
  4651. * @extnt_cnt - number of available extents.
  4652. * @type - the extent type (rpi, xri, vfi, vpi).
  4653. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4654. * @mbox - pointer to the caller's allocated mailbox structure.
  4655. *
  4656. * This function executes the extents allocation request. It also
  4657. * takes care of the amount of memory needed to allocate or get the
  4658. * allocated extents. It is the caller's responsibility to evaluate
  4659. * the response.
  4660. *
  4661. * Returns:
  4662. * -Error: Error value describes the condition found.
  4663. * 0: if successful
  4664. **/
  4665. static int
  4666. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4667. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4668. {
  4669. int rc = 0;
  4670. uint32_t req_len;
  4671. uint32_t emb_len;
  4672. uint32_t alloc_len, mbox_tmo;
  4673. /* Calculate the total requested length of the dma memory */
  4674. req_len = extnt_cnt * sizeof(uint16_t);
  4675. /*
  4676. * Calculate the size of an embedded mailbox. The uint32_t
  4677. * accounts for extents-specific word.
  4678. */
  4679. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4680. sizeof(uint32_t);
  4681. /*
  4682. * Presume the allocation and response will fit into an embedded
  4683. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4684. */
  4685. *emb = LPFC_SLI4_MBX_EMBED;
  4686. if (req_len > emb_len) {
  4687. req_len = extnt_cnt * sizeof(uint16_t) +
  4688. sizeof(union lpfc_sli4_cfg_shdr) +
  4689. sizeof(uint32_t);
  4690. *emb = LPFC_SLI4_MBX_NEMBED;
  4691. }
  4692. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4693. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4694. req_len, *emb);
  4695. if (alloc_len < req_len) {
  4696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4697. "2982 Allocated DMA memory size (x%x) is "
  4698. "less than the requested DMA memory "
  4699. "size (x%x)\n", alloc_len, req_len);
  4700. return -ENOMEM;
  4701. }
  4702. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4703. if (unlikely(rc))
  4704. return -EIO;
  4705. if (!phba->sli4_hba.intr_enable)
  4706. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4707. else {
  4708. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4709. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4710. }
  4711. if (unlikely(rc))
  4712. rc = -EIO;
  4713. return rc;
  4714. }
  4715. /**
  4716. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4717. * @phba: Pointer to HBA context object.
  4718. * @type: The resource extent type to allocate.
  4719. *
  4720. * This function allocates the number of elements for the specified
  4721. * resource type.
  4722. **/
  4723. static int
  4724. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4725. {
  4726. bool emb = false;
  4727. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4728. uint16_t rsrc_id, rsrc_start, j, k;
  4729. uint16_t *ids;
  4730. int i, rc;
  4731. unsigned long longs;
  4732. unsigned long *bmask;
  4733. struct lpfc_rsrc_blks *rsrc_blks;
  4734. LPFC_MBOXQ_t *mbox;
  4735. uint32_t length;
  4736. struct lpfc_id_range *id_array = NULL;
  4737. void *virtaddr = NULL;
  4738. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4739. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4740. struct list_head *ext_blk_list;
  4741. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4742. &rsrc_cnt,
  4743. &rsrc_size);
  4744. if (unlikely(rc))
  4745. return -EIO;
  4746. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4747. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4748. "3009 No available Resource Extents "
  4749. "for resource type 0x%x: Count: 0x%x, "
  4750. "Size 0x%x\n", type, rsrc_cnt,
  4751. rsrc_size);
  4752. return -ENOMEM;
  4753. }
  4754. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4755. "2903 Post resource extents type-0x%x: "
  4756. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4757. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4758. if (!mbox)
  4759. return -ENOMEM;
  4760. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4761. if (unlikely(rc)) {
  4762. rc = -EIO;
  4763. goto err_exit;
  4764. }
  4765. /*
  4766. * Figure out where the response is located. Then get local pointers
  4767. * to the response data. The port does not guarantee to respond to
  4768. * all extents counts request so update the local variable with the
  4769. * allocated count from the port.
  4770. */
  4771. if (emb == LPFC_SLI4_MBX_EMBED) {
  4772. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4773. id_array = &rsrc_ext->u.rsp.id[0];
  4774. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4775. } else {
  4776. virtaddr = mbox->sge_array->addr[0];
  4777. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4778. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4779. id_array = &n_rsrc->id;
  4780. }
  4781. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4782. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4783. /*
  4784. * Based on the resource size and count, correct the base and max
  4785. * resource values.
  4786. */
  4787. length = sizeof(struct lpfc_rsrc_blks);
  4788. switch (type) {
  4789. case LPFC_RSC_TYPE_FCOE_RPI:
  4790. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4791. sizeof(unsigned long),
  4792. GFP_KERNEL);
  4793. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4794. rc = -ENOMEM;
  4795. goto err_exit;
  4796. }
  4797. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4798. sizeof(uint16_t),
  4799. GFP_KERNEL);
  4800. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4801. kfree(phba->sli4_hba.rpi_bmask);
  4802. rc = -ENOMEM;
  4803. goto err_exit;
  4804. }
  4805. /*
  4806. * The next_rpi was initialized with the maximum available
  4807. * count but the port may allocate a smaller number. Catch
  4808. * that case and update the next_rpi.
  4809. */
  4810. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4811. /* Initialize local ptrs for common extent processing later. */
  4812. bmask = phba->sli4_hba.rpi_bmask;
  4813. ids = phba->sli4_hba.rpi_ids;
  4814. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4815. break;
  4816. case LPFC_RSC_TYPE_FCOE_VPI:
  4817. phba->vpi_bmask = kzalloc(longs *
  4818. sizeof(unsigned long),
  4819. GFP_KERNEL);
  4820. if (unlikely(!phba->vpi_bmask)) {
  4821. rc = -ENOMEM;
  4822. goto err_exit;
  4823. }
  4824. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4825. sizeof(uint16_t),
  4826. GFP_KERNEL);
  4827. if (unlikely(!phba->vpi_ids)) {
  4828. kfree(phba->vpi_bmask);
  4829. rc = -ENOMEM;
  4830. goto err_exit;
  4831. }
  4832. /* Initialize local ptrs for common extent processing later. */
  4833. bmask = phba->vpi_bmask;
  4834. ids = phba->vpi_ids;
  4835. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4836. break;
  4837. case LPFC_RSC_TYPE_FCOE_XRI:
  4838. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4839. sizeof(unsigned long),
  4840. GFP_KERNEL);
  4841. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4842. rc = -ENOMEM;
  4843. goto err_exit;
  4844. }
  4845. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4846. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4847. sizeof(uint16_t),
  4848. GFP_KERNEL);
  4849. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4850. kfree(phba->sli4_hba.xri_bmask);
  4851. rc = -ENOMEM;
  4852. goto err_exit;
  4853. }
  4854. /* Initialize local ptrs for common extent processing later. */
  4855. bmask = phba->sli4_hba.xri_bmask;
  4856. ids = phba->sli4_hba.xri_ids;
  4857. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4858. break;
  4859. case LPFC_RSC_TYPE_FCOE_VFI:
  4860. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4861. sizeof(unsigned long),
  4862. GFP_KERNEL);
  4863. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4864. rc = -ENOMEM;
  4865. goto err_exit;
  4866. }
  4867. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4868. sizeof(uint16_t),
  4869. GFP_KERNEL);
  4870. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4871. kfree(phba->sli4_hba.vfi_bmask);
  4872. rc = -ENOMEM;
  4873. goto err_exit;
  4874. }
  4875. /* Initialize local ptrs for common extent processing later. */
  4876. bmask = phba->sli4_hba.vfi_bmask;
  4877. ids = phba->sli4_hba.vfi_ids;
  4878. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4879. break;
  4880. default:
  4881. /* Unsupported Opcode. Fail call. */
  4882. id_array = NULL;
  4883. bmask = NULL;
  4884. ids = NULL;
  4885. ext_blk_list = NULL;
  4886. goto err_exit;
  4887. }
  4888. /*
  4889. * Complete initializing the extent configuration with the
  4890. * allocated ids assigned to this function. The bitmask serves
  4891. * as an index into the array and manages the available ids. The
  4892. * array just stores the ids communicated to the port via the wqes.
  4893. */
  4894. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4895. if ((i % 2) == 0)
  4896. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4897. &id_array[k]);
  4898. else
  4899. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4900. &id_array[k]);
  4901. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4902. if (unlikely(!rsrc_blks)) {
  4903. rc = -ENOMEM;
  4904. kfree(bmask);
  4905. kfree(ids);
  4906. goto err_exit;
  4907. }
  4908. rsrc_blks->rsrc_start = rsrc_id;
  4909. rsrc_blks->rsrc_size = rsrc_size;
  4910. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4911. rsrc_start = rsrc_id;
  4912. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4913. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4914. lpfc_sli4_get_els_iocb_cnt(phba);
  4915. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4916. ids[j] = rsrc_id;
  4917. rsrc_id++;
  4918. j++;
  4919. }
  4920. /* Entire word processed. Get next word.*/
  4921. if ((i % 2) == 1)
  4922. k++;
  4923. }
  4924. err_exit:
  4925. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4926. return rc;
  4927. }
  4928. /**
  4929. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4930. * @phba: Pointer to HBA context object.
  4931. * @type: the extent's type.
  4932. *
  4933. * This function deallocates all extents of a particular resource type.
  4934. * SLI4 does not allow for deallocating a particular extent range. It
  4935. * is the caller's responsibility to release all kernel memory resources.
  4936. **/
  4937. static int
  4938. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4939. {
  4940. int rc;
  4941. uint32_t length, mbox_tmo = 0;
  4942. LPFC_MBOXQ_t *mbox;
  4943. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4944. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4945. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4946. if (!mbox)
  4947. return -ENOMEM;
  4948. /*
  4949. * This function sends an embedded mailbox because it only sends the
  4950. * the resource type. All extents of this type are released by the
  4951. * port.
  4952. */
  4953. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4954. sizeof(struct lpfc_sli4_cfg_mhdr));
  4955. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4956. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4957. length, LPFC_SLI4_MBX_EMBED);
  4958. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4959. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4960. LPFC_SLI4_MBX_EMBED);
  4961. if (unlikely(rc)) {
  4962. rc = -EIO;
  4963. goto out_free_mbox;
  4964. }
  4965. if (!phba->sli4_hba.intr_enable)
  4966. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4967. else {
  4968. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4969. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4970. }
  4971. if (unlikely(rc)) {
  4972. rc = -EIO;
  4973. goto out_free_mbox;
  4974. }
  4975. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4976. if (bf_get(lpfc_mbox_hdr_status,
  4977. &dealloc_rsrc->header.cfg_shdr.response)) {
  4978. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4979. "2919 Failed to release resource extents "
  4980. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4981. "Resource memory not released.\n",
  4982. type,
  4983. bf_get(lpfc_mbox_hdr_status,
  4984. &dealloc_rsrc->header.cfg_shdr.response),
  4985. bf_get(lpfc_mbox_hdr_add_status,
  4986. &dealloc_rsrc->header.cfg_shdr.response));
  4987. rc = -EIO;
  4988. goto out_free_mbox;
  4989. }
  4990. /* Release kernel memory resources for the specific type. */
  4991. switch (type) {
  4992. case LPFC_RSC_TYPE_FCOE_VPI:
  4993. kfree(phba->vpi_bmask);
  4994. kfree(phba->vpi_ids);
  4995. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4996. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4997. &phba->lpfc_vpi_blk_list, list) {
  4998. list_del_init(&rsrc_blk->list);
  4999. kfree(rsrc_blk);
  5000. }
  5001. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5002. break;
  5003. case LPFC_RSC_TYPE_FCOE_XRI:
  5004. kfree(phba->sli4_hba.xri_bmask);
  5005. kfree(phba->sli4_hba.xri_ids);
  5006. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5007. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  5008. list_del_init(&rsrc_blk->list);
  5009. kfree(rsrc_blk);
  5010. }
  5011. break;
  5012. case LPFC_RSC_TYPE_FCOE_VFI:
  5013. kfree(phba->sli4_hba.vfi_bmask);
  5014. kfree(phba->sli4_hba.vfi_ids);
  5015. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5016. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5017. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  5018. list_del_init(&rsrc_blk->list);
  5019. kfree(rsrc_blk);
  5020. }
  5021. break;
  5022. case LPFC_RSC_TYPE_FCOE_RPI:
  5023. /* RPI bitmask and physical id array are cleaned up earlier. */
  5024. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  5025. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  5026. list_del_init(&rsrc_blk->list);
  5027. kfree(rsrc_blk);
  5028. }
  5029. break;
  5030. default:
  5031. break;
  5032. }
  5033. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5034. out_free_mbox:
  5035. mempool_free(mbox, phba->mbox_mem_pool);
  5036. return rc;
  5037. }
  5038. /**
  5039. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  5040. * @phba: Pointer to HBA context object.
  5041. *
  5042. * This function allocates all SLI4 resource identifiers.
  5043. **/
  5044. int
  5045. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  5046. {
  5047. int i, rc, error = 0;
  5048. uint16_t count, base;
  5049. unsigned long longs;
  5050. if (!phba->sli4_hba.rpi_hdrs_in_use)
  5051. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  5052. if (phba->sli4_hba.extents_in_use) {
  5053. /*
  5054. * The port supports resource extents. The XRI, VPI, VFI, RPI
  5055. * resource extent count must be read and allocated before
  5056. * provisioning the resource id arrays.
  5057. */
  5058. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5059. LPFC_IDX_RSRC_RDY) {
  5060. /*
  5061. * Extent-based resources are set - the driver could
  5062. * be in a port reset. Figure out if any corrective
  5063. * actions need to be taken.
  5064. */
  5065. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5066. LPFC_RSC_TYPE_FCOE_VFI);
  5067. if (rc != 0)
  5068. error++;
  5069. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5070. LPFC_RSC_TYPE_FCOE_VPI);
  5071. if (rc != 0)
  5072. error++;
  5073. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5074. LPFC_RSC_TYPE_FCOE_XRI);
  5075. if (rc != 0)
  5076. error++;
  5077. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5078. LPFC_RSC_TYPE_FCOE_RPI);
  5079. if (rc != 0)
  5080. error++;
  5081. /*
  5082. * It's possible that the number of resources
  5083. * provided to this port instance changed between
  5084. * resets. Detect this condition and reallocate
  5085. * resources. Otherwise, there is no action.
  5086. */
  5087. if (error) {
  5088. lpfc_printf_log(phba, KERN_INFO,
  5089. LOG_MBOX | LOG_INIT,
  5090. "2931 Detected extent resource "
  5091. "change. Reallocating all "
  5092. "extents.\n");
  5093. rc = lpfc_sli4_dealloc_extent(phba,
  5094. LPFC_RSC_TYPE_FCOE_VFI);
  5095. rc = lpfc_sli4_dealloc_extent(phba,
  5096. LPFC_RSC_TYPE_FCOE_VPI);
  5097. rc = lpfc_sli4_dealloc_extent(phba,
  5098. LPFC_RSC_TYPE_FCOE_XRI);
  5099. rc = lpfc_sli4_dealloc_extent(phba,
  5100. LPFC_RSC_TYPE_FCOE_RPI);
  5101. } else
  5102. return 0;
  5103. }
  5104. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5105. if (unlikely(rc))
  5106. goto err_exit;
  5107. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5108. if (unlikely(rc))
  5109. goto err_exit;
  5110. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5111. if (unlikely(rc))
  5112. goto err_exit;
  5113. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5114. if (unlikely(rc))
  5115. goto err_exit;
  5116. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5117. LPFC_IDX_RSRC_RDY);
  5118. return rc;
  5119. } else {
  5120. /*
  5121. * The port does not support resource extents. The XRI, VPI,
  5122. * VFI, RPI resource ids were determined from READ_CONFIG.
  5123. * Just allocate the bitmasks and provision the resource id
  5124. * arrays. If a port reset is active, the resources don't
  5125. * need any action - just exit.
  5126. */
  5127. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5128. LPFC_IDX_RSRC_RDY) {
  5129. lpfc_sli4_dealloc_resource_identifiers(phba);
  5130. lpfc_sli4_remove_rpis(phba);
  5131. }
  5132. /* RPIs. */
  5133. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5134. if (count <= 0) {
  5135. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5136. "3279 Invalid provisioning of "
  5137. "rpi:%d\n", count);
  5138. rc = -EINVAL;
  5139. goto err_exit;
  5140. }
  5141. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5142. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5143. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5144. sizeof(unsigned long),
  5145. GFP_KERNEL);
  5146. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5147. rc = -ENOMEM;
  5148. goto err_exit;
  5149. }
  5150. phba->sli4_hba.rpi_ids = kzalloc(count *
  5151. sizeof(uint16_t),
  5152. GFP_KERNEL);
  5153. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5154. rc = -ENOMEM;
  5155. goto free_rpi_bmask;
  5156. }
  5157. for (i = 0; i < count; i++)
  5158. phba->sli4_hba.rpi_ids[i] = base + i;
  5159. /* VPIs. */
  5160. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5161. if (count <= 0) {
  5162. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5163. "3280 Invalid provisioning of "
  5164. "vpi:%d\n", count);
  5165. rc = -EINVAL;
  5166. goto free_rpi_ids;
  5167. }
  5168. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5169. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5170. phba->vpi_bmask = kzalloc(longs *
  5171. sizeof(unsigned long),
  5172. GFP_KERNEL);
  5173. if (unlikely(!phba->vpi_bmask)) {
  5174. rc = -ENOMEM;
  5175. goto free_rpi_ids;
  5176. }
  5177. phba->vpi_ids = kzalloc(count *
  5178. sizeof(uint16_t),
  5179. GFP_KERNEL);
  5180. if (unlikely(!phba->vpi_ids)) {
  5181. rc = -ENOMEM;
  5182. goto free_vpi_bmask;
  5183. }
  5184. for (i = 0; i < count; i++)
  5185. phba->vpi_ids[i] = base + i;
  5186. /* XRIs. */
  5187. count = phba->sli4_hba.max_cfg_param.max_xri;
  5188. if (count <= 0) {
  5189. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5190. "3281 Invalid provisioning of "
  5191. "xri:%d\n", count);
  5192. rc = -EINVAL;
  5193. goto free_vpi_ids;
  5194. }
  5195. base = phba->sli4_hba.max_cfg_param.xri_base;
  5196. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5197. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5198. sizeof(unsigned long),
  5199. GFP_KERNEL);
  5200. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5201. rc = -ENOMEM;
  5202. goto free_vpi_ids;
  5203. }
  5204. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5205. phba->sli4_hba.xri_ids = kzalloc(count *
  5206. sizeof(uint16_t),
  5207. GFP_KERNEL);
  5208. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5209. rc = -ENOMEM;
  5210. goto free_xri_bmask;
  5211. }
  5212. for (i = 0; i < count; i++)
  5213. phba->sli4_hba.xri_ids[i] = base + i;
  5214. /* VFIs. */
  5215. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5216. if (count <= 0) {
  5217. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5218. "3282 Invalid provisioning of "
  5219. "vfi:%d\n", count);
  5220. rc = -EINVAL;
  5221. goto free_xri_ids;
  5222. }
  5223. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5224. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5225. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5226. sizeof(unsigned long),
  5227. GFP_KERNEL);
  5228. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5229. rc = -ENOMEM;
  5230. goto free_xri_ids;
  5231. }
  5232. phba->sli4_hba.vfi_ids = kzalloc(count *
  5233. sizeof(uint16_t),
  5234. GFP_KERNEL);
  5235. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5236. rc = -ENOMEM;
  5237. goto free_vfi_bmask;
  5238. }
  5239. for (i = 0; i < count; i++)
  5240. phba->sli4_hba.vfi_ids[i] = base + i;
  5241. /*
  5242. * Mark all resources ready. An HBA reset doesn't need
  5243. * to reset the initialization.
  5244. */
  5245. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5246. LPFC_IDX_RSRC_RDY);
  5247. return 0;
  5248. }
  5249. free_vfi_bmask:
  5250. kfree(phba->sli4_hba.vfi_bmask);
  5251. free_xri_ids:
  5252. kfree(phba->sli4_hba.xri_ids);
  5253. free_xri_bmask:
  5254. kfree(phba->sli4_hba.xri_bmask);
  5255. free_vpi_ids:
  5256. kfree(phba->vpi_ids);
  5257. free_vpi_bmask:
  5258. kfree(phba->vpi_bmask);
  5259. free_rpi_ids:
  5260. kfree(phba->sli4_hba.rpi_ids);
  5261. free_rpi_bmask:
  5262. kfree(phba->sli4_hba.rpi_bmask);
  5263. err_exit:
  5264. return rc;
  5265. }
  5266. /**
  5267. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5268. * @phba: Pointer to HBA context object.
  5269. *
  5270. * This function allocates the number of elements for the specified
  5271. * resource type.
  5272. **/
  5273. int
  5274. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5275. {
  5276. if (phba->sli4_hba.extents_in_use) {
  5277. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5278. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5279. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5280. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5281. } else {
  5282. kfree(phba->vpi_bmask);
  5283. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  5284. kfree(phba->vpi_ids);
  5285. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5286. kfree(phba->sli4_hba.xri_bmask);
  5287. kfree(phba->sli4_hba.xri_ids);
  5288. kfree(phba->sli4_hba.vfi_bmask);
  5289. kfree(phba->sli4_hba.vfi_ids);
  5290. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5291. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5292. }
  5293. return 0;
  5294. }
  5295. /**
  5296. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5297. * @phba: Pointer to HBA context object.
  5298. * @type: The resource extent type.
  5299. * @extnt_count: buffer to hold port extent count response
  5300. * @extnt_size: buffer to hold port extent size response.
  5301. *
  5302. * This function calls the port to read the host allocated extents
  5303. * for a particular type.
  5304. **/
  5305. int
  5306. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5307. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5308. {
  5309. bool emb;
  5310. int rc = 0;
  5311. uint16_t curr_blks = 0;
  5312. uint32_t req_len, emb_len;
  5313. uint32_t alloc_len, mbox_tmo;
  5314. struct list_head *blk_list_head;
  5315. struct lpfc_rsrc_blks *rsrc_blk;
  5316. LPFC_MBOXQ_t *mbox;
  5317. void *virtaddr = NULL;
  5318. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5319. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5320. union lpfc_sli4_cfg_shdr *shdr;
  5321. switch (type) {
  5322. case LPFC_RSC_TYPE_FCOE_VPI:
  5323. blk_list_head = &phba->lpfc_vpi_blk_list;
  5324. break;
  5325. case LPFC_RSC_TYPE_FCOE_XRI:
  5326. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5327. break;
  5328. case LPFC_RSC_TYPE_FCOE_VFI:
  5329. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5330. break;
  5331. case LPFC_RSC_TYPE_FCOE_RPI:
  5332. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5333. break;
  5334. default:
  5335. return -EIO;
  5336. }
  5337. /* Count the number of extents currently allocatd for this type. */
  5338. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5339. if (curr_blks == 0) {
  5340. /*
  5341. * The GET_ALLOCATED mailbox does not return the size,
  5342. * just the count. The size should be just the size
  5343. * stored in the current allocated block and all sizes
  5344. * for an extent type are the same so set the return
  5345. * value now.
  5346. */
  5347. *extnt_size = rsrc_blk->rsrc_size;
  5348. }
  5349. curr_blks++;
  5350. }
  5351. /* Calculate the total requested length of the dma memory. */
  5352. req_len = curr_blks * sizeof(uint16_t);
  5353. /*
  5354. * Calculate the size of an embedded mailbox. The uint32_t
  5355. * accounts for extents-specific word.
  5356. */
  5357. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5358. sizeof(uint32_t);
  5359. /*
  5360. * Presume the allocation and response will fit into an embedded
  5361. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5362. */
  5363. emb = LPFC_SLI4_MBX_EMBED;
  5364. req_len = emb_len;
  5365. if (req_len > emb_len) {
  5366. req_len = curr_blks * sizeof(uint16_t) +
  5367. sizeof(union lpfc_sli4_cfg_shdr) +
  5368. sizeof(uint32_t);
  5369. emb = LPFC_SLI4_MBX_NEMBED;
  5370. }
  5371. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5372. if (!mbox)
  5373. return -ENOMEM;
  5374. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5375. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5376. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5377. req_len, emb);
  5378. if (alloc_len < req_len) {
  5379. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5380. "2983 Allocated DMA memory size (x%x) is "
  5381. "less than the requested DMA memory "
  5382. "size (x%x)\n", alloc_len, req_len);
  5383. rc = -ENOMEM;
  5384. goto err_exit;
  5385. }
  5386. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5387. if (unlikely(rc)) {
  5388. rc = -EIO;
  5389. goto err_exit;
  5390. }
  5391. if (!phba->sli4_hba.intr_enable)
  5392. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5393. else {
  5394. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5395. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5396. }
  5397. if (unlikely(rc)) {
  5398. rc = -EIO;
  5399. goto err_exit;
  5400. }
  5401. /*
  5402. * Figure out where the response is located. Then get local pointers
  5403. * to the response data. The port does not guarantee to respond to
  5404. * all extents counts request so update the local variable with the
  5405. * allocated count from the port.
  5406. */
  5407. if (emb == LPFC_SLI4_MBX_EMBED) {
  5408. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5409. shdr = &rsrc_ext->header.cfg_shdr;
  5410. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5411. } else {
  5412. virtaddr = mbox->sge_array->addr[0];
  5413. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5414. shdr = &n_rsrc->cfg_shdr;
  5415. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5416. }
  5417. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5418. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5419. "2984 Failed to read allocated resources "
  5420. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5421. type,
  5422. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5423. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5424. rc = -EIO;
  5425. goto err_exit;
  5426. }
  5427. err_exit:
  5428. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5429. return rc;
  5430. }
  5431. /**
  5432. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5433. * @phba: pointer to lpfc hba data structure.
  5434. *
  5435. * This routine walks the list of els buffers that have been allocated and
  5436. * repost them to the port by using SGL block post. This is needed after a
  5437. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5438. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5439. * SGL block post mailbox commands to post them to the port. For single els
  5440. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5441. * mailbox command for posting.
  5442. *
  5443. * Returns: 0 = success, non-zero failure.
  5444. **/
  5445. static int
  5446. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5447. {
  5448. struct lpfc_sglq *sglq_entry = NULL;
  5449. struct lpfc_sglq *sglq_entry_next = NULL;
  5450. struct lpfc_sglq *sglq_entry_first = NULL;
  5451. int status, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5452. int last_xritag = NO_XRI;
  5453. LIST_HEAD(prep_sgl_list);
  5454. LIST_HEAD(blck_sgl_list);
  5455. LIST_HEAD(allc_sgl_list);
  5456. LIST_HEAD(post_sgl_list);
  5457. LIST_HEAD(free_sgl_list);
  5458. spin_lock_irq(&phba->hbalock);
  5459. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5460. spin_unlock_irq(&phba->hbalock);
  5461. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5462. &allc_sgl_list, list) {
  5463. list_del_init(&sglq_entry->list);
  5464. block_cnt++;
  5465. if ((last_xritag != NO_XRI) &&
  5466. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5467. /* a hole in xri block, form a sgl posting block */
  5468. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5469. post_cnt = block_cnt - 1;
  5470. /* prepare list for next posting block */
  5471. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5472. block_cnt = 1;
  5473. } else {
  5474. /* prepare list for next posting block */
  5475. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5476. /* enough sgls for non-embed sgl mbox command */
  5477. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5478. list_splice_init(&prep_sgl_list,
  5479. &blck_sgl_list);
  5480. post_cnt = block_cnt;
  5481. block_cnt = 0;
  5482. }
  5483. }
  5484. num_posted++;
  5485. /* keep track of last sgl's xritag */
  5486. last_xritag = sglq_entry->sli4_xritag;
  5487. /* end of repost sgl list condition for els buffers */
  5488. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5489. if (post_cnt == 0) {
  5490. list_splice_init(&prep_sgl_list,
  5491. &blck_sgl_list);
  5492. post_cnt = block_cnt;
  5493. } else if (block_cnt == 1) {
  5494. status = lpfc_sli4_post_sgl(phba,
  5495. sglq_entry->phys, 0,
  5496. sglq_entry->sli4_xritag);
  5497. if (!status) {
  5498. /* successful, put sgl to posted list */
  5499. list_add_tail(&sglq_entry->list,
  5500. &post_sgl_list);
  5501. } else {
  5502. /* Failure, put sgl to free list */
  5503. lpfc_printf_log(phba, KERN_WARNING,
  5504. LOG_SLI,
  5505. "3159 Failed to post els "
  5506. "sgl, xritag:x%x\n",
  5507. sglq_entry->sli4_xritag);
  5508. list_add_tail(&sglq_entry->list,
  5509. &free_sgl_list);
  5510. spin_lock_irq(&phba->hbalock);
  5511. phba->sli4_hba.els_xri_cnt--;
  5512. spin_unlock_irq(&phba->hbalock);
  5513. }
  5514. }
  5515. }
  5516. /* continue until a nembed page worth of sgls */
  5517. if (post_cnt == 0)
  5518. continue;
  5519. /* post the els buffer list sgls as a block */
  5520. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5521. post_cnt);
  5522. if (!status) {
  5523. /* success, put sgl list to posted sgl list */
  5524. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5525. } else {
  5526. /* Failure, put sgl list to free sgl list */
  5527. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5528. struct lpfc_sglq,
  5529. list);
  5530. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5531. "3160 Failed to post els sgl-list, "
  5532. "xritag:x%x-x%x\n",
  5533. sglq_entry_first->sli4_xritag,
  5534. (sglq_entry_first->sli4_xritag +
  5535. post_cnt - 1));
  5536. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5537. spin_lock_irq(&phba->hbalock);
  5538. phba->sli4_hba.els_xri_cnt -= post_cnt;
  5539. spin_unlock_irq(&phba->hbalock);
  5540. }
  5541. /* don't reset xirtag due to hole in xri block */
  5542. if (block_cnt == 0)
  5543. last_xritag = NO_XRI;
  5544. /* reset els sgl post count for next round of posting */
  5545. post_cnt = 0;
  5546. }
  5547. /* free the els sgls failed to post */
  5548. lpfc_free_sgl_list(phba, &free_sgl_list);
  5549. /* push els sgls posted to the availble list */
  5550. if (!list_empty(&post_sgl_list)) {
  5551. spin_lock_irq(&phba->hbalock);
  5552. list_splice_init(&post_sgl_list,
  5553. &phba->sli4_hba.lpfc_sgl_list);
  5554. spin_unlock_irq(&phba->hbalock);
  5555. } else {
  5556. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5557. "3161 Failure to post els sgl to port.\n");
  5558. return -EIO;
  5559. }
  5560. return 0;
  5561. }
  5562. /**
  5563. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5564. * @phba: Pointer to HBA context object.
  5565. *
  5566. * This function is the main SLI4 device intialization PCI function. This
  5567. * function is called by the HBA intialization code, HBA reset code and
  5568. * HBA error attention handler code. Caller is not required to hold any
  5569. * locks.
  5570. **/
  5571. int
  5572. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5573. {
  5574. int rc;
  5575. LPFC_MBOXQ_t *mboxq;
  5576. struct lpfc_mqe *mqe;
  5577. uint8_t *vpd;
  5578. uint32_t vpd_size;
  5579. uint32_t ftr_rsp = 0;
  5580. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5581. struct lpfc_vport *vport = phba->pport;
  5582. struct lpfc_dmabuf *mp;
  5583. /* Perform a PCI function reset to start from clean */
  5584. rc = lpfc_pci_function_reset(phba);
  5585. if (unlikely(rc))
  5586. return -ENODEV;
  5587. /* Check the HBA Host Status Register for readyness */
  5588. rc = lpfc_sli4_post_status_check(phba);
  5589. if (unlikely(rc))
  5590. return -ENODEV;
  5591. else {
  5592. spin_lock_irq(&phba->hbalock);
  5593. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5594. spin_unlock_irq(&phba->hbalock);
  5595. }
  5596. /*
  5597. * Allocate a single mailbox container for initializing the
  5598. * port.
  5599. */
  5600. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5601. if (!mboxq)
  5602. return -ENOMEM;
  5603. /* Issue READ_REV to collect vpd and FW information. */
  5604. vpd_size = SLI4_PAGE_SIZE;
  5605. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5606. if (!vpd) {
  5607. rc = -ENOMEM;
  5608. goto out_free_mbox;
  5609. }
  5610. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5611. if (unlikely(rc)) {
  5612. kfree(vpd);
  5613. goto out_free_mbox;
  5614. }
  5615. mqe = &mboxq->u.mqe;
  5616. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5617. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5618. phba->hba_flag |= HBA_FCOE_MODE;
  5619. else
  5620. phba->hba_flag &= ~HBA_FCOE_MODE;
  5621. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5622. LPFC_DCBX_CEE_MODE)
  5623. phba->hba_flag |= HBA_FIP_SUPPORT;
  5624. else
  5625. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5626. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5627. if (phba->sli_rev != LPFC_SLI_REV4) {
  5628. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5629. "0376 READ_REV Error. SLI Level %d "
  5630. "FCoE enabled %d\n",
  5631. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5632. rc = -EIO;
  5633. kfree(vpd);
  5634. goto out_free_mbox;
  5635. }
  5636. /*
  5637. * Continue initialization with default values even if driver failed
  5638. * to read FCoE param config regions, only read parameters if the
  5639. * board is FCoE
  5640. */
  5641. if (phba->hba_flag & HBA_FCOE_MODE &&
  5642. lpfc_sli4_read_fcoe_params(phba))
  5643. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5644. "2570 Failed to read FCoE parameters\n");
  5645. /*
  5646. * Retrieve sli4 device physical port name, failure of doing it
  5647. * is considered as non-fatal.
  5648. */
  5649. rc = lpfc_sli4_retrieve_pport_name(phba);
  5650. if (!rc)
  5651. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5652. "3080 Successful retrieving SLI4 device "
  5653. "physical port name: %s.\n", phba->Port);
  5654. /*
  5655. * Evaluate the read rev and vpd data. Populate the driver
  5656. * state with the results. If this routine fails, the failure
  5657. * is not fatal as the driver will use generic values.
  5658. */
  5659. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5660. if (unlikely(!rc)) {
  5661. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5662. "0377 Error %d parsing vpd. "
  5663. "Using defaults.\n", rc);
  5664. rc = 0;
  5665. }
  5666. kfree(vpd);
  5667. /* Save information as VPD data */
  5668. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5669. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5670. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5671. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5672. &mqe->un.read_rev);
  5673. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5674. &mqe->un.read_rev);
  5675. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5676. &mqe->un.read_rev);
  5677. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5678. &mqe->un.read_rev);
  5679. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5680. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5681. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5682. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5683. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5684. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5685. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5686. "(%d):0380 READ_REV Status x%x "
  5687. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5688. mboxq->vport ? mboxq->vport->vpi : 0,
  5689. bf_get(lpfc_mqe_status, mqe),
  5690. phba->vpd.rev.opFwName,
  5691. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5692. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5693. /*
  5694. * Discover the port's supported feature set and match it against the
  5695. * hosts requests.
  5696. */
  5697. lpfc_request_features(phba, mboxq);
  5698. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5699. if (unlikely(rc)) {
  5700. rc = -EIO;
  5701. goto out_free_mbox;
  5702. }
  5703. /*
  5704. * The port must support FCP initiator mode as this is the
  5705. * only mode running in the host.
  5706. */
  5707. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5708. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5709. "0378 No support for fcpi mode.\n");
  5710. ftr_rsp++;
  5711. }
  5712. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5713. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5714. else
  5715. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5716. /*
  5717. * If the port cannot support the host's requested features
  5718. * then turn off the global config parameters to disable the
  5719. * feature in the driver. This is not a fatal error.
  5720. */
  5721. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5722. if (phba->cfg_enable_bg) {
  5723. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5724. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5725. else
  5726. ftr_rsp++;
  5727. }
  5728. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5729. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5730. ftr_rsp++;
  5731. if (ftr_rsp) {
  5732. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5733. "0379 Feature Mismatch Data: x%08x %08x "
  5734. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5735. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5736. phba->cfg_enable_npiv, phba->max_vpi);
  5737. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5738. phba->cfg_enable_bg = 0;
  5739. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5740. phba->cfg_enable_npiv = 0;
  5741. }
  5742. /* These SLI3 features are assumed in SLI4 */
  5743. spin_lock_irq(&phba->hbalock);
  5744. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5745. spin_unlock_irq(&phba->hbalock);
  5746. /*
  5747. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5748. * calls depends on these resources to complete port setup.
  5749. */
  5750. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5751. if (rc) {
  5752. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5753. "2920 Failed to alloc Resource IDs "
  5754. "rc = x%x\n", rc);
  5755. goto out_free_mbox;
  5756. }
  5757. /* Read the port's service parameters. */
  5758. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5759. if (rc) {
  5760. phba->link_state = LPFC_HBA_ERROR;
  5761. rc = -ENOMEM;
  5762. goto out_free_mbox;
  5763. }
  5764. mboxq->vport = vport;
  5765. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5766. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5767. if (rc == MBX_SUCCESS) {
  5768. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5769. rc = 0;
  5770. }
  5771. /*
  5772. * This memory was allocated by the lpfc_read_sparam routine. Release
  5773. * it to the mbuf pool.
  5774. */
  5775. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5776. kfree(mp);
  5777. mboxq->context1 = NULL;
  5778. if (unlikely(rc)) {
  5779. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5780. "0382 READ_SPARAM command failed "
  5781. "status %d, mbxStatus x%x\n",
  5782. rc, bf_get(lpfc_mqe_status, mqe));
  5783. phba->link_state = LPFC_HBA_ERROR;
  5784. rc = -EIO;
  5785. goto out_free_mbox;
  5786. }
  5787. lpfc_update_vport_wwn(vport);
  5788. /* Update the fc_host data structures with new wwn. */
  5789. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5790. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5791. /* update host els and scsi xri-sgl sizes and mappings */
  5792. rc = lpfc_sli4_xri_sgl_update(phba);
  5793. if (unlikely(rc)) {
  5794. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5795. "1400 Failed to update xri-sgl size and "
  5796. "mapping: %d\n", rc);
  5797. goto out_free_mbox;
  5798. }
  5799. /* register the els sgl pool to the port */
  5800. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5801. if (unlikely(rc)) {
  5802. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5803. "0582 Error %d during els sgl post "
  5804. "operation\n", rc);
  5805. rc = -ENODEV;
  5806. goto out_free_mbox;
  5807. }
  5808. /* register the allocated scsi sgl pool to the port */
  5809. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5810. if (unlikely(rc)) {
  5811. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5812. "0383 Error %d during scsi sgl post "
  5813. "operation\n", rc);
  5814. /* Some Scsi buffers were moved to the abort scsi list */
  5815. /* A pci function reset will repost them */
  5816. rc = -ENODEV;
  5817. goto out_free_mbox;
  5818. }
  5819. /* Post the rpi header region to the device. */
  5820. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5821. if (unlikely(rc)) {
  5822. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5823. "0393 Error %d during rpi post operation\n",
  5824. rc);
  5825. rc = -ENODEV;
  5826. goto out_free_mbox;
  5827. }
  5828. lpfc_sli4_node_prep(phba);
  5829. /* Create all the SLI4 queues */
  5830. rc = lpfc_sli4_queue_create(phba);
  5831. if (rc) {
  5832. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5833. "3089 Failed to allocate queues\n");
  5834. rc = -ENODEV;
  5835. goto out_stop_timers;
  5836. }
  5837. /* Set up all the queues to the device */
  5838. rc = lpfc_sli4_queue_setup(phba);
  5839. if (unlikely(rc)) {
  5840. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5841. "0381 Error %d during queue setup.\n ", rc);
  5842. goto out_destroy_queue;
  5843. }
  5844. /* Arm the CQs and then EQs on device */
  5845. lpfc_sli4_arm_cqeq_intr(phba);
  5846. /* Indicate device interrupt mode */
  5847. phba->sli4_hba.intr_enable = 1;
  5848. /* Allow asynchronous mailbox command to go through */
  5849. spin_lock_irq(&phba->hbalock);
  5850. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5851. spin_unlock_irq(&phba->hbalock);
  5852. /* Post receive buffers to the device */
  5853. lpfc_sli4_rb_setup(phba);
  5854. /* Reset HBA FCF states after HBA reset */
  5855. phba->fcf.fcf_flag = 0;
  5856. phba->fcf.current_rec.flag = 0;
  5857. /* Start the ELS watchdog timer */
  5858. mod_timer(&vport->els_tmofunc,
  5859. jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
  5860. /* Start heart beat timer */
  5861. mod_timer(&phba->hb_tmofunc,
  5862. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  5863. phba->hb_outstanding = 0;
  5864. phba->last_completion_time = jiffies;
  5865. /* Start error attention (ERATT) polling timer */
  5866. mod_timer(&phba->eratt_poll,
  5867. jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
  5868. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5869. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5870. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5871. if (!rc) {
  5872. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5873. "2829 This device supports "
  5874. "Advanced Error Reporting (AER)\n");
  5875. spin_lock_irq(&phba->hbalock);
  5876. phba->hba_flag |= HBA_AER_ENABLED;
  5877. spin_unlock_irq(&phba->hbalock);
  5878. } else {
  5879. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5880. "2830 This device does not support "
  5881. "Advanced Error Reporting (AER)\n");
  5882. phba->cfg_aer_support = 0;
  5883. }
  5884. rc = 0;
  5885. }
  5886. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5887. /*
  5888. * The FC Port needs to register FCFI (index 0)
  5889. */
  5890. lpfc_reg_fcfi(phba, mboxq);
  5891. mboxq->vport = phba->pport;
  5892. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5893. if (rc != MBX_SUCCESS)
  5894. goto out_unset_queue;
  5895. rc = 0;
  5896. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5897. &mboxq->u.mqe.un.reg_fcfi);
  5898. /* Check if the port is configured to be disabled */
  5899. lpfc_sli_read_link_ste(phba);
  5900. }
  5901. /*
  5902. * The port is ready, set the host's link state to LINK_DOWN
  5903. * in preparation for link interrupts.
  5904. */
  5905. spin_lock_irq(&phba->hbalock);
  5906. phba->link_state = LPFC_LINK_DOWN;
  5907. spin_unlock_irq(&phba->hbalock);
  5908. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5909. (phba->hba_flag & LINK_DISABLED)) {
  5910. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5911. "3103 Adapter Link is disabled.\n");
  5912. lpfc_down_link(phba, mboxq);
  5913. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5914. if (rc != MBX_SUCCESS) {
  5915. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5916. "3104 Adapter failed to issue "
  5917. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5918. goto out_unset_queue;
  5919. }
  5920. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5921. /* don't perform init_link on SLI4 FC port loopback test */
  5922. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  5923. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5924. if (rc)
  5925. goto out_unset_queue;
  5926. }
  5927. }
  5928. mempool_free(mboxq, phba->mbox_mem_pool);
  5929. return rc;
  5930. out_unset_queue:
  5931. /* Unset all the queues set up in this routine when error out */
  5932. lpfc_sli4_queue_unset(phba);
  5933. out_destroy_queue:
  5934. lpfc_sli4_queue_destroy(phba);
  5935. out_stop_timers:
  5936. lpfc_stop_hba_timers(phba);
  5937. out_free_mbox:
  5938. mempool_free(mboxq, phba->mbox_mem_pool);
  5939. return rc;
  5940. }
  5941. /**
  5942. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5943. * @ptr: context object - pointer to hba structure.
  5944. *
  5945. * This is the callback function for mailbox timer. The mailbox
  5946. * timer is armed when a new mailbox command is issued and the timer
  5947. * is deleted when the mailbox complete. The function is called by
  5948. * the kernel timer code when a mailbox does not complete within
  5949. * expected time. This function wakes up the worker thread to
  5950. * process the mailbox timeout and returns. All the processing is
  5951. * done by the worker thread function lpfc_mbox_timeout_handler.
  5952. **/
  5953. void
  5954. lpfc_mbox_timeout(unsigned long ptr)
  5955. {
  5956. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5957. unsigned long iflag;
  5958. uint32_t tmo_posted;
  5959. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5960. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5961. if (!tmo_posted)
  5962. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5963. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5964. if (!tmo_posted)
  5965. lpfc_worker_wake_up(phba);
  5966. return;
  5967. }
  5968. /**
  5969. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5970. * @phba: Pointer to HBA context object.
  5971. *
  5972. * This function is called from worker thread when a mailbox command times out.
  5973. * The caller is not required to hold any locks. This function will reset the
  5974. * HBA and recover all the pending commands.
  5975. **/
  5976. void
  5977. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5978. {
  5979. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5980. MAILBOX_t *mb = &pmbox->u.mb;
  5981. struct lpfc_sli *psli = &phba->sli;
  5982. struct lpfc_sli_ring *pring;
  5983. /* Check the pmbox pointer first. There is a race condition
  5984. * between the mbox timeout handler getting executed in the
  5985. * worklist and the mailbox actually completing. When this
  5986. * race condition occurs, the mbox_active will be NULL.
  5987. */
  5988. spin_lock_irq(&phba->hbalock);
  5989. if (pmbox == NULL) {
  5990. lpfc_printf_log(phba, KERN_WARNING,
  5991. LOG_MBOX | LOG_SLI,
  5992. "0353 Active Mailbox cleared - mailbox timeout "
  5993. "exiting\n");
  5994. spin_unlock_irq(&phba->hbalock);
  5995. return;
  5996. }
  5997. /* Mbox cmd <mbxCommand> timeout */
  5998. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5999. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  6000. mb->mbxCommand,
  6001. phba->pport->port_state,
  6002. phba->sli.sli_flag,
  6003. phba->sli.mbox_active);
  6004. spin_unlock_irq(&phba->hbalock);
  6005. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  6006. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  6007. * it to fail all outstanding SCSI IO.
  6008. */
  6009. spin_lock_irq(&phba->pport->work_port_lock);
  6010. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  6011. spin_unlock_irq(&phba->pport->work_port_lock);
  6012. spin_lock_irq(&phba->hbalock);
  6013. phba->link_state = LPFC_LINK_UNKNOWN;
  6014. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6015. spin_unlock_irq(&phba->hbalock);
  6016. pring = &psli->ring[psli->fcp_ring];
  6017. lpfc_sli_abort_iocb_ring(phba, pring);
  6018. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6019. "0345 Resetting board due to mailbox timeout\n");
  6020. /* Reset the HBA device */
  6021. lpfc_reset_hba(phba);
  6022. }
  6023. /**
  6024. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  6025. * @phba: Pointer to HBA context object.
  6026. * @pmbox: Pointer to mailbox object.
  6027. * @flag: Flag indicating how the mailbox need to be processed.
  6028. *
  6029. * This function is called by discovery code and HBA management code
  6030. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  6031. * function gets the hbalock to protect the data structures.
  6032. * The mailbox command can be submitted in polling mode, in which case
  6033. * this function will wait in a polling loop for the completion of the
  6034. * mailbox.
  6035. * If the mailbox is submitted in no_wait mode (not polling) the
  6036. * function will submit the command and returns immediately without waiting
  6037. * for the mailbox completion. The no_wait is supported only when HBA
  6038. * is in SLI2/SLI3 mode - interrupts are enabled.
  6039. * The SLI interface allows only one mailbox pending at a time. If the
  6040. * mailbox is issued in polling mode and there is already a mailbox
  6041. * pending, then the function will return an error. If the mailbox is issued
  6042. * in NO_WAIT mode and there is a mailbox pending already, the function
  6043. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  6044. * The sli layer owns the mailbox object until the completion of mailbox
  6045. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  6046. * return codes the caller owns the mailbox command after the return of
  6047. * the function.
  6048. **/
  6049. static int
  6050. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  6051. uint32_t flag)
  6052. {
  6053. MAILBOX_t *mbx;
  6054. struct lpfc_sli *psli = &phba->sli;
  6055. uint32_t status, evtctr;
  6056. uint32_t ha_copy, hc_copy;
  6057. int i;
  6058. unsigned long timeout;
  6059. unsigned long drvr_flag = 0;
  6060. uint32_t word0, ldata;
  6061. void __iomem *to_slim;
  6062. int processing_queue = 0;
  6063. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6064. if (!pmbox) {
  6065. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6066. /* processing mbox queue from intr_handler */
  6067. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6068. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6069. return MBX_SUCCESS;
  6070. }
  6071. processing_queue = 1;
  6072. pmbox = lpfc_mbox_get(phba);
  6073. if (!pmbox) {
  6074. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6075. return MBX_SUCCESS;
  6076. }
  6077. }
  6078. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  6079. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  6080. if(!pmbox->vport) {
  6081. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6082. lpfc_printf_log(phba, KERN_ERR,
  6083. LOG_MBOX | LOG_VPORT,
  6084. "1806 Mbox x%x failed. No vport\n",
  6085. pmbox->u.mb.mbxCommand);
  6086. dump_stack();
  6087. goto out_not_finished;
  6088. }
  6089. }
  6090. /* If the PCI channel is in offline state, do not post mbox. */
  6091. if (unlikely(pci_channel_offline(phba->pcidev))) {
  6092. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6093. goto out_not_finished;
  6094. }
  6095. /* If HBA has a deferred error attention, fail the iocb. */
  6096. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  6097. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6098. goto out_not_finished;
  6099. }
  6100. psli = &phba->sli;
  6101. mbx = &pmbox->u.mb;
  6102. status = MBX_SUCCESS;
  6103. if (phba->link_state == LPFC_HBA_ERROR) {
  6104. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6105. /* Mbox command <mbxCommand> cannot issue */
  6106. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6107. "(%d):0311 Mailbox command x%x cannot "
  6108. "issue Data: x%x x%x\n",
  6109. pmbox->vport ? pmbox->vport->vpi : 0,
  6110. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6111. goto out_not_finished;
  6112. }
  6113. if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6114. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6115. !(hc_copy & HC_MBINT_ENA)) {
  6116. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6117. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6118. "(%d):2528 Mailbox command x%x cannot "
  6119. "issue Data: x%x x%x\n",
  6120. pmbox->vport ? pmbox->vport->vpi : 0,
  6121. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6122. goto out_not_finished;
  6123. }
  6124. }
  6125. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6126. /* Polling for a mbox command when another one is already active
  6127. * is not allowed in SLI. Also, the driver must have established
  6128. * SLI2 mode to queue and process multiple mbox commands.
  6129. */
  6130. if (flag & MBX_POLL) {
  6131. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6132. /* Mbox command <mbxCommand> cannot issue */
  6133. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6134. "(%d):2529 Mailbox command x%x "
  6135. "cannot issue Data: x%x x%x\n",
  6136. pmbox->vport ? pmbox->vport->vpi : 0,
  6137. pmbox->u.mb.mbxCommand,
  6138. psli->sli_flag, flag);
  6139. goto out_not_finished;
  6140. }
  6141. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6142. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6143. /* Mbox command <mbxCommand> cannot issue */
  6144. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6145. "(%d):2530 Mailbox command x%x "
  6146. "cannot issue Data: x%x x%x\n",
  6147. pmbox->vport ? pmbox->vport->vpi : 0,
  6148. pmbox->u.mb.mbxCommand,
  6149. psli->sli_flag, flag);
  6150. goto out_not_finished;
  6151. }
  6152. /* Another mailbox command is still being processed, queue this
  6153. * command to be processed later.
  6154. */
  6155. lpfc_mbox_put(phba, pmbox);
  6156. /* Mbox cmd issue - BUSY */
  6157. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6158. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6159. "x%x x%x x%x x%x\n",
  6160. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6161. mbx->mbxCommand, phba->pport->port_state,
  6162. psli->sli_flag, flag);
  6163. psli->slistat.mbox_busy++;
  6164. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6165. if (pmbox->vport) {
  6166. lpfc_debugfs_disc_trc(pmbox->vport,
  6167. LPFC_DISC_TRC_MBOX_VPORT,
  6168. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6169. (uint32_t)mbx->mbxCommand,
  6170. mbx->un.varWords[0], mbx->un.varWords[1]);
  6171. }
  6172. else {
  6173. lpfc_debugfs_disc_trc(phba->pport,
  6174. LPFC_DISC_TRC_MBOX,
  6175. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6176. (uint32_t)mbx->mbxCommand,
  6177. mbx->un.varWords[0], mbx->un.varWords[1]);
  6178. }
  6179. return MBX_BUSY;
  6180. }
  6181. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6182. /* If we are not polling, we MUST be in SLI2 mode */
  6183. if (flag != MBX_POLL) {
  6184. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6185. (mbx->mbxCommand != MBX_KILL_BOARD)) {
  6186. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6187. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6188. /* Mbox command <mbxCommand> cannot issue */
  6189. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6190. "(%d):2531 Mailbox command x%x "
  6191. "cannot issue Data: x%x x%x\n",
  6192. pmbox->vport ? pmbox->vport->vpi : 0,
  6193. pmbox->u.mb.mbxCommand,
  6194. psli->sli_flag, flag);
  6195. goto out_not_finished;
  6196. }
  6197. /* timeout active mbox command */
  6198. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6199. 1000);
  6200. mod_timer(&psli->mbox_tmo, jiffies + timeout);
  6201. }
  6202. /* Mailbox cmd <cmd> issue */
  6203. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6204. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6205. "x%x\n",
  6206. pmbox->vport ? pmbox->vport->vpi : 0,
  6207. mbx->mbxCommand, phba->pport->port_state,
  6208. psli->sli_flag, flag);
  6209. if (mbx->mbxCommand != MBX_HEARTBEAT) {
  6210. if (pmbox->vport) {
  6211. lpfc_debugfs_disc_trc(pmbox->vport,
  6212. LPFC_DISC_TRC_MBOX_VPORT,
  6213. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6214. (uint32_t)mbx->mbxCommand,
  6215. mbx->un.varWords[0], mbx->un.varWords[1]);
  6216. }
  6217. else {
  6218. lpfc_debugfs_disc_trc(phba->pport,
  6219. LPFC_DISC_TRC_MBOX,
  6220. "MBOX Send: cmd:x%x mb:x%x x%x",
  6221. (uint32_t)mbx->mbxCommand,
  6222. mbx->un.varWords[0], mbx->un.varWords[1]);
  6223. }
  6224. }
  6225. psli->slistat.mbox_cmd++;
  6226. evtctr = psli->slistat.mbox_event;
  6227. /* next set own bit for the adapter and copy over command word */
  6228. mbx->mbxOwner = OWN_CHIP;
  6229. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6230. /* Populate mbox extension offset word. */
  6231. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6232. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6233. = (uint8_t *)phba->mbox_ext
  6234. - (uint8_t *)phba->mbox;
  6235. }
  6236. /* Copy the mailbox extension data */
  6237. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6238. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6239. (uint8_t *)phba->mbox_ext,
  6240. pmbox->in_ext_byte_len);
  6241. }
  6242. /* Copy command data to host SLIM area */
  6243. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6244. } else {
  6245. /* Populate mbox extension offset word. */
  6246. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6247. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  6248. = MAILBOX_HBA_EXT_OFFSET;
  6249. /* Copy the mailbox extension data */
  6250. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6251. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6252. MAILBOX_HBA_EXT_OFFSET,
  6253. pmbox->context2, pmbox->in_ext_byte_len);
  6254. }
  6255. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6256. /* copy command data into host mbox for cmpl */
  6257. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  6258. }
  6259. /* First copy mbox command data to HBA SLIM, skip past first
  6260. word */
  6261. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6262. lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
  6263. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6264. /* Next copy over first word, with mbxOwner set */
  6265. ldata = *((uint32_t *)mbx);
  6266. to_slim = phba->MBslimaddr;
  6267. writel(ldata, to_slim);
  6268. readl(to_slim); /* flush */
  6269. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6270. /* switch over to host mailbox */
  6271. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6272. }
  6273. }
  6274. wmb();
  6275. switch (flag) {
  6276. case MBX_NOWAIT:
  6277. /* Set up reference to mailbox command */
  6278. psli->mbox_active = pmbox;
  6279. /* Interrupt board to do it */
  6280. writel(CA_MBATT, phba->CAregaddr);
  6281. readl(phba->CAregaddr); /* flush */
  6282. /* Don't wait for it to finish, just return */
  6283. break;
  6284. case MBX_POLL:
  6285. /* Set up null reference to mailbox command */
  6286. psli->mbox_active = NULL;
  6287. /* Interrupt board to do it */
  6288. writel(CA_MBATT, phba->CAregaddr);
  6289. readl(phba->CAregaddr); /* flush */
  6290. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6291. /* First read mbox status word */
  6292. word0 = *((uint32_t *)phba->mbox);
  6293. word0 = le32_to_cpu(word0);
  6294. } else {
  6295. /* First read mbox status word */
  6296. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6297. spin_unlock_irqrestore(&phba->hbalock,
  6298. drvr_flag);
  6299. goto out_not_finished;
  6300. }
  6301. }
  6302. /* Read the HBA Host Attention Register */
  6303. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6304. spin_unlock_irqrestore(&phba->hbalock,
  6305. drvr_flag);
  6306. goto out_not_finished;
  6307. }
  6308. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6309. 1000) + jiffies;
  6310. i = 0;
  6311. /* Wait for command to complete */
  6312. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6313. (!(ha_copy & HA_MBATT) &&
  6314. (phba->link_state > LPFC_WARM_START))) {
  6315. if (time_after(jiffies, timeout)) {
  6316. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6317. spin_unlock_irqrestore(&phba->hbalock,
  6318. drvr_flag);
  6319. goto out_not_finished;
  6320. }
  6321. /* Check if we took a mbox interrupt while we were
  6322. polling */
  6323. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6324. && (evtctr != psli->slistat.mbox_event))
  6325. break;
  6326. if (i++ > 10) {
  6327. spin_unlock_irqrestore(&phba->hbalock,
  6328. drvr_flag);
  6329. msleep(1);
  6330. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6331. }
  6332. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6333. /* First copy command data */
  6334. word0 = *((uint32_t *)phba->mbox);
  6335. word0 = le32_to_cpu(word0);
  6336. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  6337. MAILBOX_t *slimmb;
  6338. uint32_t slimword0;
  6339. /* Check real SLIM for any errors */
  6340. slimword0 = readl(phba->MBslimaddr);
  6341. slimmb = (MAILBOX_t *) & slimword0;
  6342. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6343. && slimmb->mbxStatus) {
  6344. psli->sli_flag &=
  6345. ~LPFC_SLI_ACTIVE;
  6346. word0 = slimword0;
  6347. }
  6348. }
  6349. } else {
  6350. /* First copy command data */
  6351. word0 = readl(phba->MBslimaddr);
  6352. }
  6353. /* Read the HBA Host Attention Register */
  6354. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6355. spin_unlock_irqrestore(&phba->hbalock,
  6356. drvr_flag);
  6357. goto out_not_finished;
  6358. }
  6359. }
  6360. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6361. /* copy results back to user */
  6362. lpfc_sli_pcimem_bcopy(phba->mbox, mbx, MAILBOX_CMD_SIZE);
  6363. /* Copy the mailbox extension data */
  6364. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6365. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6366. pmbox->context2,
  6367. pmbox->out_ext_byte_len);
  6368. }
  6369. } else {
  6370. /* First copy command data */
  6371. lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
  6372. MAILBOX_CMD_SIZE);
  6373. /* Copy the mailbox extension data */
  6374. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6375. lpfc_memcpy_from_slim(pmbox->context2,
  6376. phba->MBslimaddr +
  6377. MAILBOX_HBA_EXT_OFFSET,
  6378. pmbox->out_ext_byte_len);
  6379. }
  6380. }
  6381. writel(HA_MBATT, phba->HAregaddr);
  6382. readl(phba->HAregaddr); /* flush */
  6383. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6384. status = mbx->mbxStatus;
  6385. }
  6386. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6387. return status;
  6388. out_not_finished:
  6389. if (processing_queue) {
  6390. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6391. lpfc_mbox_cmpl_put(phba, pmbox);
  6392. }
  6393. return MBX_NOT_FINISHED;
  6394. }
  6395. /**
  6396. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6397. * @phba: Pointer to HBA context object.
  6398. *
  6399. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6400. * the driver internal pending mailbox queue. It will then try to wait out the
  6401. * possible outstanding mailbox command before return.
  6402. *
  6403. * Returns:
  6404. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6405. * the outstanding mailbox command timed out.
  6406. **/
  6407. static int
  6408. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6409. {
  6410. struct lpfc_sli *psli = &phba->sli;
  6411. int rc = 0;
  6412. unsigned long timeout = 0;
  6413. /* Mark the asynchronous mailbox command posting as blocked */
  6414. spin_lock_irq(&phba->hbalock);
  6415. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6416. /* Determine how long we might wait for the active mailbox
  6417. * command to be gracefully completed by firmware.
  6418. */
  6419. if (phba->sli.mbox_active)
  6420. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6421. phba->sli.mbox_active) *
  6422. 1000) + jiffies;
  6423. spin_unlock_irq(&phba->hbalock);
  6424. /* Wait for the outstnading mailbox command to complete */
  6425. while (phba->sli.mbox_active) {
  6426. /* Check active mailbox complete status every 2ms */
  6427. msleep(2);
  6428. if (time_after(jiffies, timeout)) {
  6429. /* Timeout, marked the outstanding cmd not complete */
  6430. rc = 1;
  6431. break;
  6432. }
  6433. }
  6434. /* Can not cleanly block async mailbox command, fails it */
  6435. if (rc) {
  6436. spin_lock_irq(&phba->hbalock);
  6437. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6438. spin_unlock_irq(&phba->hbalock);
  6439. }
  6440. return rc;
  6441. }
  6442. /**
  6443. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6444. * @phba: Pointer to HBA context object.
  6445. *
  6446. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6447. * commands from the driver internal pending mailbox queue. It makes sure
  6448. * that there is no outstanding mailbox command before resuming posting
  6449. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6450. * mailbox command, it will try to wait it out before resuming asynchronous
  6451. * mailbox command posting.
  6452. **/
  6453. static void
  6454. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6455. {
  6456. struct lpfc_sli *psli = &phba->sli;
  6457. spin_lock_irq(&phba->hbalock);
  6458. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6459. /* Asynchronous mailbox posting is not blocked, do nothing */
  6460. spin_unlock_irq(&phba->hbalock);
  6461. return;
  6462. }
  6463. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6464. * successful or timeout, after timing-out the outstanding mailbox
  6465. * command shall always be removed, so just unblock posting async
  6466. * mailbox command and resume
  6467. */
  6468. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6469. spin_unlock_irq(&phba->hbalock);
  6470. /* wake up worker thread to post asynchronlous mailbox command */
  6471. lpfc_worker_wake_up(phba);
  6472. }
  6473. /**
  6474. * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
  6475. * @phba: Pointer to HBA context object.
  6476. * @mboxq: Pointer to mailbox object.
  6477. *
  6478. * The function waits for the bootstrap mailbox register ready bit from
  6479. * port for twice the regular mailbox command timeout value.
  6480. *
  6481. * 0 - no timeout on waiting for bootstrap mailbox register ready.
  6482. * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
  6483. **/
  6484. static int
  6485. lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6486. {
  6487. uint32_t db_ready;
  6488. unsigned long timeout;
  6489. struct lpfc_register bmbx_reg;
  6490. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6491. * 1000) + jiffies;
  6492. do {
  6493. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6494. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6495. if (!db_ready)
  6496. msleep(2);
  6497. if (time_after(jiffies, timeout))
  6498. return MBXERR_ERROR;
  6499. } while (!db_ready);
  6500. return 0;
  6501. }
  6502. /**
  6503. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6504. * @phba: Pointer to HBA context object.
  6505. * @mboxq: Pointer to mailbox object.
  6506. *
  6507. * The function posts a mailbox to the port. The mailbox is expected
  6508. * to be comletely filled in and ready for the port to operate on it.
  6509. * This routine executes a synchronous completion operation on the
  6510. * mailbox by polling for its completion.
  6511. *
  6512. * The caller must not be holding any locks when calling this routine.
  6513. *
  6514. * Returns:
  6515. * MBX_SUCCESS - mailbox posted successfully
  6516. * Any of the MBX error values.
  6517. **/
  6518. static int
  6519. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6520. {
  6521. int rc = MBX_SUCCESS;
  6522. unsigned long iflag;
  6523. uint32_t mcqe_status;
  6524. uint32_t mbx_cmnd;
  6525. struct lpfc_sli *psli = &phba->sli;
  6526. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6527. struct lpfc_bmbx_create *mbox_rgn;
  6528. struct dma_address *dma_address;
  6529. /*
  6530. * Only one mailbox can be active to the bootstrap mailbox region
  6531. * at a time and there is no queueing provided.
  6532. */
  6533. spin_lock_irqsave(&phba->hbalock, iflag);
  6534. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6535. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6536. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6537. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6538. "cannot issue Data: x%x x%x\n",
  6539. mboxq->vport ? mboxq->vport->vpi : 0,
  6540. mboxq->u.mb.mbxCommand,
  6541. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6542. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6543. psli->sli_flag, MBX_POLL);
  6544. return MBXERR_ERROR;
  6545. }
  6546. /* The server grabs the token and owns it until release */
  6547. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6548. phba->sli.mbox_active = mboxq;
  6549. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6550. /* wait for bootstrap mbox register for readyness */
  6551. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6552. if (rc)
  6553. goto exit;
  6554. /*
  6555. * Initialize the bootstrap memory region to avoid stale data areas
  6556. * in the mailbox post. Then copy the caller's mailbox contents to
  6557. * the bmbx mailbox region.
  6558. */
  6559. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6560. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6561. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6562. sizeof(struct lpfc_mqe));
  6563. /* Post the high mailbox dma address to the port and wait for ready. */
  6564. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6565. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6566. /* wait for bootstrap mbox register for hi-address write done */
  6567. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6568. if (rc)
  6569. goto exit;
  6570. /* Post the low mailbox dma address to the port. */
  6571. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6572. /* wait for bootstrap mbox register for low address write done */
  6573. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  6574. if (rc)
  6575. goto exit;
  6576. /*
  6577. * Read the CQ to ensure the mailbox has completed.
  6578. * If so, update the mailbox status so that the upper layers
  6579. * can complete the request normally.
  6580. */
  6581. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6582. sizeof(struct lpfc_mqe));
  6583. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6584. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6585. sizeof(struct lpfc_mcqe));
  6586. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6587. /*
  6588. * When the CQE status indicates a failure and the mailbox status
  6589. * indicates success then copy the CQE status into the mailbox status
  6590. * (and prefix it with x4000).
  6591. */
  6592. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6593. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6594. bf_set(lpfc_mqe_status, mb,
  6595. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6596. rc = MBXERR_ERROR;
  6597. } else
  6598. lpfc_sli4_swap_str(phba, mboxq);
  6599. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6600. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6601. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6602. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6603. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6604. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6605. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6606. bf_get(lpfc_mqe_status, mb),
  6607. mb->un.mb_words[0], mb->un.mb_words[1],
  6608. mb->un.mb_words[2], mb->un.mb_words[3],
  6609. mb->un.mb_words[4], mb->un.mb_words[5],
  6610. mb->un.mb_words[6], mb->un.mb_words[7],
  6611. mb->un.mb_words[8], mb->un.mb_words[9],
  6612. mb->un.mb_words[10], mb->un.mb_words[11],
  6613. mb->un.mb_words[12], mboxq->mcqe.word0,
  6614. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6615. mboxq->mcqe.trailer);
  6616. exit:
  6617. /* We are holding the token, no needed for lock when release */
  6618. spin_lock_irqsave(&phba->hbalock, iflag);
  6619. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6620. phba->sli.mbox_active = NULL;
  6621. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6622. return rc;
  6623. }
  6624. /**
  6625. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6626. * @phba: Pointer to HBA context object.
  6627. * @pmbox: Pointer to mailbox object.
  6628. * @flag: Flag indicating how the mailbox need to be processed.
  6629. *
  6630. * This function is called by discovery code and HBA management code to submit
  6631. * a mailbox command to firmware with SLI-4 interface spec.
  6632. *
  6633. * Return codes the caller owns the mailbox command after the return of the
  6634. * function.
  6635. **/
  6636. static int
  6637. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6638. uint32_t flag)
  6639. {
  6640. struct lpfc_sli *psli = &phba->sli;
  6641. unsigned long iflags;
  6642. int rc;
  6643. /* dump from issue mailbox command if setup */
  6644. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6645. rc = lpfc_mbox_dev_check(phba);
  6646. if (unlikely(rc)) {
  6647. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6648. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6649. "cannot issue Data: x%x x%x\n",
  6650. mboxq->vport ? mboxq->vport->vpi : 0,
  6651. mboxq->u.mb.mbxCommand,
  6652. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6653. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6654. psli->sli_flag, flag);
  6655. goto out_not_finished;
  6656. }
  6657. /* Detect polling mode and jump to a handler */
  6658. if (!phba->sli4_hba.intr_enable) {
  6659. if (flag == MBX_POLL)
  6660. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6661. else
  6662. rc = -EIO;
  6663. if (rc != MBX_SUCCESS)
  6664. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6665. "(%d):2541 Mailbox command x%x "
  6666. "(x%x/x%x) failure: "
  6667. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6668. "Data: x%x x%x\n,",
  6669. mboxq->vport ? mboxq->vport->vpi : 0,
  6670. mboxq->u.mb.mbxCommand,
  6671. lpfc_sli_config_mbox_subsys_get(phba,
  6672. mboxq),
  6673. lpfc_sli_config_mbox_opcode_get(phba,
  6674. mboxq),
  6675. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6676. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6677. bf_get(lpfc_mcqe_ext_status,
  6678. &mboxq->mcqe),
  6679. psli->sli_flag, flag);
  6680. return rc;
  6681. } else if (flag == MBX_POLL) {
  6682. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6683. "(%d):2542 Try to issue mailbox command "
  6684. "x%x (x%x/x%x) synchronously ahead of async"
  6685. "mailbox command queue: x%x x%x\n",
  6686. mboxq->vport ? mboxq->vport->vpi : 0,
  6687. mboxq->u.mb.mbxCommand,
  6688. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6689. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6690. psli->sli_flag, flag);
  6691. /* Try to block the asynchronous mailbox posting */
  6692. rc = lpfc_sli4_async_mbox_block(phba);
  6693. if (!rc) {
  6694. /* Successfully blocked, now issue sync mbox cmd */
  6695. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6696. if (rc != MBX_SUCCESS)
  6697. lpfc_printf_log(phba, KERN_WARNING,
  6698. LOG_MBOX | LOG_SLI,
  6699. "(%d):2597 Sync Mailbox command "
  6700. "x%x (x%x/x%x) failure: "
  6701. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6702. "Data: x%x x%x\n,",
  6703. mboxq->vport ? mboxq->vport->vpi : 0,
  6704. mboxq->u.mb.mbxCommand,
  6705. lpfc_sli_config_mbox_subsys_get(phba,
  6706. mboxq),
  6707. lpfc_sli_config_mbox_opcode_get(phba,
  6708. mboxq),
  6709. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6710. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6711. bf_get(lpfc_mcqe_ext_status,
  6712. &mboxq->mcqe),
  6713. psli->sli_flag, flag);
  6714. /* Unblock the async mailbox posting afterward */
  6715. lpfc_sli4_async_mbox_unblock(phba);
  6716. }
  6717. return rc;
  6718. }
  6719. /* Now, interrupt mode asynchrous mailbox command */
  6720. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6721. if (rc) {
  6722. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6723. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6724. "cannot issue Data: x%x x%x\n",
  6725. mboxq->vport ? mboxq->vport->vpi : 0,
  6726. mboxq->u.mb.mbxCommand,
  6727. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6728. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6729. psli->sli_flag, flag);
  6730. goto out_not_finished;
  6731. }
  6732. /* Put the mailbox command to the driver internal FIFO */
  6733. psli->slistat.mbox_busy++;
  6734. spin_lock_irqsave(&phba->hbalock, iflags);
  6735. lpfc_mbox_put(phba, mboxq);
  6736. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6737. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6738. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6739. "x%x (x%x/x%x) x%x x%x x%x\n",
  6740. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6741. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6742. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6743. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6744. phba->pport->port_state,
  6745. psli->sli_flag, MBX_NOWAIT);
  6746. /* Wake up worker thread to transport mailbox command from head */
  6747. lpfc_worker_wake_up(phba);
  6748. return MBX_BUSY;
  6749. out_not_finished:
  6750. return MBX_NOT_FINISHED;
  6751. }
  6752. /**
  6753. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6754. * @phba: Pointer to HBA context object.
  6755. *
  6756. * This function is called by worker thread to send a mailbox command to
  6757. * SLI4 HBA firmware.
  6758. *
  6759. **/
  6760. int
  6761. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6762. {
  6763. struct lpfc_sli *psli = &phba->sli;
  6764. LPFC_MBOXQ_t *mboxq;
  6765. int rc = MBX_SUCCESS;
  6766. unsigned long iflags;
  6767. struct lpfc_mqe *mqe;
  6768. uint32_t mbx_cmnd;
  6769. /* Check interrupt mode before post async mailbox command */
  6770. if (unlikely(!phba->sli4_hba.intr_enable))
  6771. return MBX_NOT_FINISHED;
  6772. /* Check for mailbox command service token */
  6773. spin_lock_irqsave(&phba->hbalock, iflags);
  6774. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6775. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6776. return MBX_NOT_FINISHED;
  6777. }
  6778. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6779. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6780. return MBX_NOT_FINISHED;
  6781. }
  6782. if (unlikely(phba->sli.mbox_active)) {
  6783. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6784. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6785. "0384 There is pending active mailbox cmd\n");
  6786. return MBX_NOT_FINISHED;
  6787. }
  6788. /* Take the mailbox command service token */
  6789. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6790. /* Get the next mailbox command from head of queue */
  6791. mboxq = lpfc_mbox_get(phba);
  6792. /* If no more mailbox command waiting for post, we're done */
  6793. if (!mboxq) {
  6794. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6795. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6796. return MBX_SUCCESS;
  6797. }
  6798. phba->sli.mbox_active = mboxq;
  6799. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6800. /* Check device readiness for posting mailbox command */
  6801. rc = lpfc_mbox_dev_check(phba);
  6802. if (unlikely(rc))
  6803. /* Driver clean routine will clean up pending mailbox */
  6804. goto out_not_finished;
  6805. /* Prepare the mbox command to be posted */
  6806. mqe = &mboxq->u.mqe;
  6807. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6808. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6809. mod_timer(&psli->mbox_tmo, (jiffies +
  6810. msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
  6811. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6812. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6813. "x%x x%x\n",
  6814. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6815. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6816. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6817. phba->pport->port_state, psli->sli_flag);
  6818. if (mbx_cmnd != MBX_HEARTBEAT) {
  6819. if (mboxq->vport) {
  6820. lpfc_debugfs_disc_trc(mboxq->vport,
  6821. LPFC_DISC_TRC_MBOX_VPORT,
  6822. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6823. mbx_cmnd, mqe->un.mb_words[0],
  6824. mqe->un.mb_words[1]);
  6825. } else {
  6826. lpfc_debugfs_disc_trc(phba->pport,
  6827. LPFC_DISC_TRC_MBOX,
  6828. "MBOX Send: cmd:x%x mb:x%x x%x",
  6829. mbx_cmnd, mqe->un.mb_words[0],
  6830. mqe->un.mb_words[1]);
  6831. }
  6832. }
  6833. psli->slistat.mbox_cmd++;
  6834. /* Post the mailbox command to the port */
  6835. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6836. if (rc != MBX_SUCCESS) {
  6837. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6838. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6839. "cannot issue Data: x%x x%x\n",
  6840. mboxq->vport ? mboxq->vport->vpi : 0,
  6841. mboxq->u.mb.mbxCommand,
  6842. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6843. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6844. psli->sli_flag, MBX_NOWAIT);
  6845. goto out_not_finished;
  6846. }
  6847. return rc;
  6848. out_not_finished:
  6849. spin_lock_irqsave(&phba->hbalock, iflags);
  6850. if (phba->sli.mbox_active) {
  6851. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6852. __lpfc_mbox_cmpl_put(phba, mboxq);
  6853. /* Release the token */
  6854. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6855. phba->sli.mbox_active = NULL;
  6856. }
  6857. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6858. return MBX_NOT_FINISHED;
  6859. }
  6860. /**
  6861. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6862. * @phba: Pointer to HBA context object.
  6863. * @pmbox: Pointer to mailbox object.
  6864. * @flag: Flag indicating how the mailbox need to be processed.
  6865. *
  6866. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6867. * the API jump table function pointer from the lpfc_hba struct.
  6868. *
  6869. * Return codes the caller owns the mailbox command after the return of the
  6870. * function.
  6871. **/
  6872. int
  6873. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6874. {
  6875. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6876. }
  6877. /**
  6878. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6879. * @phba: The hba struct for which this call is being executed.
  6880. * @dev_grp: The HBA PCI-Device group number.
  6881. *
  6882. * This routine sets up the mbox interface API function jump table in @phba
  6883. * struct.
  6884. * Returns: 0 - success, -ENODEV - failure.
  6885. **/
  6886. int
  6887. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6888. {
  6889. switch (dev_grp) {
  6890. case LPFC_PCI_DEV_LP:
  6891. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6892. phba->lpfc_sli_handle_slow_ring_event =
  6893. lpfc_sli_handle_slow_ring_event_s3;
  6894. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6895. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6896. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6897. break;
  6898. case LPFC_PCI_DEV_OC:
  6899. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6900. phba->lpfc_sli_handle_slow_ring_event =
  6901. lpfc_sli_handle_slow_ring_event_s4;
  6902. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6903. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6904. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6905. break;
  6906. default:
  6907. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6908. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6909. dev_grp);
  6910. return -ENODEV;
  6911. break;
  6912. }
  6913. return 0;
  6914. }
  6915. /**
  6916. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6917. * @phba: Pointer to HBA context object.
  6918. * @pring: Pointer to driver SLI ring object.
  6919. * @piocb: Pointer to address of newly added command iocb.
  6920. *
  6921. * This function is called with hbalock held to add a command
  6922. * iocb to the txq when SLI layer cannot submit the command iocb
  6923. * to the ring.
  6924. **/
  6925. void
  6926. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6927. struct lpfc_iocbq *piocb)
  6928. {
  6929. /* Insert the caller's iocb in the txq tail for later processing. */
  6930. list_add_tail(&piocb->list, &pring->txq);
  6931. }
  6932. /**
  6933. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6934. * @phba: Pointer to HBA context object.
  6935. * @pring: Pointer to driver SLI ring object.
  6936. * @piocb: Pointer to address of newly added command iocb.
  6937. *
  6938. * This function is called with hbalock held before a new
  6939. * iocb is submitted to the firmware. This function checks
  6940. * txq to flush the iocbs in txq to Firmware before
  6941. * submitting new iocbs to the Firmware.
  6942. * If there are iocbs in the txq which need to be submitted
  6943. * to firmware, lpfc_sli_next_iocb returns the first element
  6944. * of the txq after dequeuing it from txq.
  6945. * If there is no iocb in the txq then the function will return
  6946. * *piocb and *piocb is set to NULL. Caller needs to check
  6947. * *piocb to find if there are more commands in the txq.
  6948. **/
  6949. static struct lpfc_iocbq *
  6950. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6951. struct lpfc_iocbq **piocb)
  6952. {
  6953. struct lpfc_iocbq * nextiocb;
  6954. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6955. if (!nextiocb) {
  6956. nextiocb = *piocb;
  6957. *piocb = NULL;
  6958. }
  6959. return nextiocb;
  6960. }
  6961. /**
  6962. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6963. * @phba: Pointer to HBA context object.
  6964. * @ring_number: SLI ring number to issue iocb on.
  6965. * @piocb: Pointer to command iocb.
  6966. * @flag: Flag indicating if this command can be put into txq.
  6967. *
  6968. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6969. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6970. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6971. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6972. * this function allows only iocbs for posting buffers. This function finds
  6973. * next available slot in the command ring and posts the command to the
  6974. * available slot and writes the port attention register to request HBA start
  6975. * processing new iocb. If there is no slot available in the ring and
  6976. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6977. * the function returns IOCB_BUSY.
  6978. *
  6979. * This function is called with hbalock held. The function will return success
  6980. * after it successfully submit the iocb to firmware or after adding to the
  6981. * txq.
  6982. **/
  6983. static int
  6984. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6985. struct lpfc_iocbq *piocb, uint32_t flag)
  6986. {
  6987. struct lpfc_iocbq *nextiocb;
  6988. IOCB_t *iocb;
  6989. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6990. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6991. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6992. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6993. lpfc_printf_log(phba, KERN_ERR,
  6994. LOG_SLI | LOG_VPORT,
  6995. "1807 IOCB x%x failed. No vport\n",
  6996. piocb->iocb.ulpCommand);
  6997. dump_stack();
  6998. return IOCB_ERROR;
  6999. }
  7000. /* If the PCI channel is in offline state, do not post iocbs. */
  7001. if (unlikely(pci_channel_offline(phba->pcidev)))
  7002. return IOCB_ERROR;
  7003. /* If HBA has a deferred error attention, fail the iocb. */
  7004. if (unlikely(phba->hba_flag & DEFER_ERATT))
  7005. return IOCB_ERROR;
  7006. /*
  7007. * We should never get an IOCB if we are in a < LINK_DOWN state
  7008. */
  7009. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  7010. return IOCB_ERROR;
  7011. /*
  7012. * Check to see if we are blocking IOCB processing because of a
  7013. * outstanding event.
  7014. */
  7015. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  7016. goto iocb_busy;
  7017. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  7018. /*
  7019. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  7020. * can be issued if the link is not up.
  7021. */
  7022. switch (piocb->iocb.ulpCommand) {
  7023. case CMD_GEN_REQUEST64_CR:
  7024. case CMD_GEN_REQUEST64_CX:
  7025. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  7026. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  7027. FC_RCTL_DD_UNSOL_CMD) ||
  7028. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  7029. MENLO_TRANSPORT_TYPE))
  7030. goto iocb_busy;
  7031. break;
  7032. case CMD_QUE_RING_BUF_CN:
  7033. case CMD_QUE_RING_BUF64_CN:
  7034. /*
  7035. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  7036. * completion, iocb_cmpl MUST be 0.
  7037. */
  7038. if (piocb->iocb_cmpl)
  7039. piocb->iocb_cmpl = NULL;
  7040. /*FALLTHROUGH*/
  7041. case CMD_CREATE_XRI_CR:
  7042. case CMD_CLOSE_XRI_CN:
  7043. case CMD_CLOSE_XRI_CX:
  7044. break;
  7045. default:
  7046. goto iocb_busy;
  7047. }
  7048. /*
  7049. * For FCP commands, we must be in a state where we can process link
  7050. * attention events.
  7051. */
  7052. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  7053. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  7054. goto iocb_busy;
  7055. }
  7056. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  7057. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  7058. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  7059. if (iocb)
  7060. lpfc_sli_update_ring(phba, pring);
  7061. else
  7062. lpfc_sli_update_full_ring(phba, pring);
  7063. if (!piocb)
  7064. return IOCB_SUCCESS;
  7065. goto out_busy;
  7066. iocb_busy:
  7067. pring->stats.iocb_cmd_delay++;
  7068. out_busy:
  7069. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7070. __lpfc_sli_ringtx_put(phba, pring, piocb);
  7071. return IOCB_SUCCESS;
  7072. }
  7073. return IOCB_BUSY;
  7074. }
  7075. /**
  7076. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  7077. * @phba: Pointer to HBA context object.
  7078. * @piocb: Pointer to command iocb.
  7079. * @sglq: Pointer to the scatter gather queue object.
  7080. *
  7081. * This routine converts the bpl or bde that is in the IOCB
  7082. * to a sgl list for the sli4 hardware. The physical address
  7083. * of the bpl/bde is converted back to a virtual address.
  7084. * If the IOCB contains a BPL then the list of BDE's is
  7085. * converted to sli4_sge's. If the IOCB contains a single
  7086. * BDE then it is converted to a single sli_sge.
  7087. * The IOCB is still in cpu endianess so the contents of
  7088. * the bpl can be used without byte swapping.
  7089. *
  7090. * Returns valid XRI = Success, NO_XRI = Failure.
  7091. **/
  7092. static uint16_t
  7093. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  7094. struct lpfc_sglq *sglq)
  7095. {
  7096. uint16_t xritag = NO_XRI;
  7097. struct ulp_bde64 *bpl = NULL;
  7098. struct ulp_bde64 bde;
  7099. struct sli4_sge *sgl = NULL;
  7100. struct lpfc_dmabuf *dmabuf;
  7101. IOCB_t *icmd;
  7102. int numBdes = 0;
  7103. int i = 0;
  7104. uint32_t offset = 0; /* accumulated offset in the sg request list */
  7105. int inbound = 0; /* number of sg reply entries inbound from firmware */
  7106. if (!piocbq || !sglq)
  7107. return xritag;
  7108. sgl = (struct sli4_sge *)sglq->sgl;
  7109. icmd = &piocbq->iocb;
  7110. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  7111. return sglq->sli4_xritag;
  7112. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7113. numBdes = icmd->un.genreq64.bdl.bdeSize /
  7114. sizeof(struct ulp_bde64);
  7115. /* The addrHigh and addrLow fields within the IOCB
  7116. * have not been byteswapped yet so there is no
  7117. * need to swap them back.
  7118. */
  7119. if (piocbq->context3)
  7120. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7121. else
  7122. return xritag;
  7123. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7124. if (!bpl)
  7125. return xritag;
  7126. for (i = 0; i < numBdes; i++) {
  7127. /* Should already be byte swapped. */
  7128. sgl->addr_hi = bpl->addrHigh;
  7129. sgl->addr_lo = bpl->addrLow;
  7130. sgl->word2 = le32_to_cpu(sgl->word2);
  7131. if ((i+1) == numBdes)
  7132. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7133. else
  7134. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7135. /* swap the size field back to the cpu so we
  7136. * can assign it to the sgl.
  7137. */
  7138. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7139. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7140. /* The offsets in the sgl need to be accumulated
  7141. * separately for the request and reply lists.
  7142. * The request is always first, the reply follows.
  7143. */
  7144. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7145. /* add up the reply sg entries */
  7146. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7147. inbound++;
  7148. /* first inbound? reset the offset */
  7149. if (inbound == 1)
  7150. offset = 0;
  7151. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7152. bf_set(lpfc_sli4_sge_type, sgl,
  7153. LPFC_SGE_TYPE_DATA);
  7154. offset += bde.tus.f.bdeSize;
  7155. }
  7156. sgl->word2 = cpu_to_le32(sgl->word2);
  7157. bpl++;
  7158. sgl++;
  7159. }
  7160. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7161. /* The addrHigh and addrLow fields of the BDE have not
  7162. * been byteswapped yet so they need to be swapped
  7163. * before putting them in the sgl.
  7164. */
  7165. sgl->addr_hi =
  7166. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7167. sgl->addr_lo =
  7168. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7169. sgl->word2 = le32_to_cpu(sgl->word2);
  7170. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7171. sgl->word2 = cpu_to_le32(sgl->word2);
  7172. sgl->sge_len =
  7173. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7174. }
  7175. return sglq->sli4_xritag;
  7176. }
  7177. /**
  7178. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  7179. * @phba: Pointer to HBA context object.
  7180. *
  7181. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  7182. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  7183. * held.
  7184. *
  7185. * Return: index into SLI4 fast-path FCP queue index.
  7186. **/
  7187. static inline uint32_t
  7188. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  7189. {
  7190. int i;
  7191. if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU)
  7192. i = smp_processor_id();
  7193. else
  7194. i = atomic_add_return(1, &phba->fcp_qidx);
  7195. i = (i % phba->cfg_fcp_io_channel);
  7196. return i;
  7197. }
  7198. /**
  7199. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7200. * @phba: Pointer to HBA context object.
  7201. * @piocb: Pointer to command iocb.
  7202. * @wqe: Pointer to the work queue entry.
  7203. *
  7204. * This routine converts the iocb command to its Work Queue Entry
  7205. * equivalent. The wqe pointer should not have any fields set when
  7206. * this routine is called because it will memcpy over them.
  7207. * This routine does not set the CQ_ID or the WQEC bits in the
  7208. * wqe.
  7209. *
  7210. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7211. **/
  7212. static int
  7213. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7214. union lpfc_wqe *wqe)
  7215. {
  7216. uint32_t xmit_len = 0, total_len = 0;
  7217. uint8_t ct = 0;
  7218. uint32_t fip;
  7219. uint32_t abort_tag;
  7220. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7221. uint8_t cmnd;
  7222. uint16_t xritag;
  7223. uint16_t abrt_iotag;
  7224. struct lpfc_iocbq *abrtiocbq;
  7225. struct ulp_bde64 *bpl = NULL;
  7226. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7227. int numBdes, i;
  7228. struct ulp_bde64 bde;
  7229. struct lpfc_nodelist *ndlp;
  7230. uint32_t *pcmd;
  7231. uint32_t if_type;
  7232. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7233. /* The fcp commands will set command type */
  7234. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7235. command_type = FCP_COMMAND;
  7236. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7237. command_type = ELS_COMMAND_FIP;
  7238. else
  7239. command_type = ELS_COMMAND_NON_FIP;
  7240. /* Some of the fields are in the right position already */
  7241. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7242. abort_tag = (uint32_t) iocbq->iotag;
  7243. xritag = iocbq->sli4_xritag;
  7244. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7245. /* words0-2 bpl convert bde */
  7246. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7247. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7248. sizeof(struct ulp_bde64);
  7249. bpl = (struct ulp_bde64 *)
  7250. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7251. if (!bpl)
  7252. return IOCB_ERROR;
  7253. /* Should already be byte swapped. */
  7254. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7255. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7256. /* swap the size field back to the cpu so we
  7257. * can assign it to the sgl.
  7258. */
  7259. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7260. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7261. total_len = 0;
  7262. for (i = 0; i < numBdes; i++) {
  7263. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7264. total_len += bde.tus.f.bdeSize;
  7265. }
  7266. } else
  7267. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7268. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7269. cmnd = iocbq->iocb.ulpCommand;
  7270. switch (iocbq->iocb.ulpCommand) {
  7271. case CMD_ELS_REQUEST64_CR:
  7272. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7273. ndlp = iocbq->context_un.ndlp;
  7274. else
  7275. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7276. if (!iocbq->iocb.ulpLe) {
  7277. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7278. "2007 Only Limited Edition cmd Format"
  7279. " supported 0x%x\n",
  7280. iocbq->iocb.ulpCommand);
  7281. return IOCB_ERROR;
  7282. }
  7283. wqe->els_req.payload_len = xmit_len;
  7284. /* Els_reguest64 has a TMO */
  7285. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7286. iocbq->iocb.ulpTimeout);
  7287. /* Need a VF for word 4 set the vf bit*/
  7288. bf_set(els_req64_vf, &wqe->els_req, 0);
  7289. /* And a VFID for word 12 */
  7290. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7291. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7292. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7293. iocbq->iocb.ulpContext);
  7294. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7295. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7296. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7297. if (command_type == ELS_COMMAND_FIP)
  7298. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7299. >> LPFC_FIP_ELS_ID_SHIFT);
  7300. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7301. iocbq->context2)->virt);
  7302. if_type = bf_get(lpfc_sli_intf_if_type,
  7303. &phba->sli4_hba.sli_intf);
  7304. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7305. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7306. *pcmd == ELS_CMD_SCR ||
  7307. *pcmd == ELS_CMD_FDISC ||
  7308. *pcmd == ELS_CMD_LOGO ||
  7309. *pcmd == ELS_CMD_PLOGI)) {
  7310. bf_set(els_req64_sp, &wqe->els_req, 1);
  7311. bf_set(els_req64_sid, &wqe->els_req,
  7312. iocbq->vport->fc_myDID);
  7313. if ((*pcmd == ELS_CMD_FLOGI) &&
  7314. !(phba->fc_topology ==
  7315. LPFC_TOPOLOGY_LOOP))
  7316. bf_set(els_req64_sid, &wqe->els_req, 0);
  7317. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7318. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7319. phba->vpi_ids[iocbq->vport->vpi]);
  7320. } else if (pcmd && iocbq->context1) {
  7321. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7322. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7323. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7324. }
  7325. }
  7326. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7327. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7328. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7329. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7330. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7331. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7332. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7333. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7334. break;
  7335. case CMD_XMIT_SEQUENCE64_CX:
  7336. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7337. iocbq->iocb.un.ulpWord[3]);
  7338. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7339. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7340. /* The entire sequence is transmitted for this IOCB */
  7341. xmit_len = total_len;
  7342. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7343. if (phba->link_flag & LS_LOOPBACK_MODE)
  7344. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7345. case CMD_XMIT_SEQUENCE64_CR:
  7346. /* word3 iocb=io_tag32 wqe=reserved */
  7347. wqe->xmit_sequence.rsvd3 = 0;
  7348. /* word4 relative_offset memcpy */
  7349. /* word5 r_ctl/df_ctl memcpy */
  7350. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7351. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7352. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7353. LPFC_WQE_IOD_WRITE);
  7354. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7355. LPFC_WQE_LENLOC_WORD12);
  7356. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7357. wqe->xmit_sequence.xmit_len = xmit_len;
  7358. command_type = OTHER_COMMAND;
  7359. break;
  7360. case CMD_XMIT_BCAST64_CN:
  7361. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7362. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7363. /* word4 iocb=rsvd wqe=rsvd */
  7364. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7365. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7366. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7367. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7368. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7369. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7370. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7371. LPFC_WQE_LENLOC_WORD3);
  7372. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7373. break;
  7374. case CMD_FCP_IWRITE64_CR:
  7375. command_type = FCP_COMMAND_DATA_OUT;
  7376. /* word3 iocb=iotag wqe=payload_offset_len */
  7377. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7378. wqe->fcp_iwrite.payload_offset_len =
  7379. xmit_len + sizeof(struct fcp_rsp);
  7380. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7381. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7382. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7383. iocbq->iocb.ulpFCP2Rcvy);
  7384. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7385. /* Always open the exchange */
  7386. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7387. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7388. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7389. LPFC_WQE_LENLOC_WORD4);
  7390. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7391. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7392. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7393. break;
  7394. case CMD_FCP_IREAD64_CR:
  7395. /* word3 iocb=iotag wqe=payload_offset_len */
  7396. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7397. wqe->fcp_iread.payload_offset_len =
  7398. xmit_len + sizeof(struct fcp_rsp);
  7399. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7400. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7401. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7402. iocbq->iocb.ulpFCP2Rcvy);
  7403. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7404. /* Always open the exchange */
  7405. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7406. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7407. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7408. LPFC_WQE_LENLOC_WORD4);
  7409. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7410. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7411. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7412. break;
  7413. case CMD_FCP_ICMND64_CR:
  7414. /* word3 iocb=IO_TAG wqe=reserved */
  7415. wqe->fcp_icmd.rsrvd3 = 0;
  7416. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7417. /* Always open the exchange */
  7418. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7419. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7420. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7421. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7422. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7423. LPFC_WQE_LENLOC_NONE);
  7424. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7425. bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
  7426. iocbq->iocb.ulpFCP2Rcvy);
  7427. break;
  7428. case CMD_GEN_REQUEST64_CR:
  7429. /* For this command calculate the xmit length of the
  7430. * request bde.
  7431. */
  7432. xmit_len = 0;
  7433. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7434. sizeof(struct ulp_bde64);
  7435. for (i = 0; i < numBdes; i++) {
  7436. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7437. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7438. break;
  7439. xmit_len += bde.tus.f.bdeSize;
  7440. }
  7441. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7442. wqe->gen_req.request_payload_len = xmit_len;
  7443. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7444. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7445. /* word6 context tag copied in memcpy */
  7446. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7447. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7448. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7449. "2015 Invalid CT %x command 0x%x\n",
  7450. ct, iocbq->iocb.ulpCommand);
  7451. return IOCB_ERROR;
  7452. }
  7453. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7454. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7455. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7456. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7457. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7458. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7459. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7460. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7461. command_type = OTHER_COMMAND;
  7462. break;
  7463. case CMD_XMIT_ELS_RSP64_CX:
  7464. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7465. /* words0-2 BDE memcpy */
  7466. /* word3 iocb=iotag32 wqe=response_payload_len */
  7467. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7468. /* word4 */
  7469. wqe->xmit_els_rsp.word4 = 0;
  7470. /* word5 iocb=rsvd wge=did */
  7471. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7472. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7473. if_type = bf_get(lpfc_sli_intf_if_type,
  7474. &phba->sli4_hba.sli_intf);
  7475. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7476. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7477. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7478. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7479. iocbq->vport->fc_myDID);
  7480. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7481. bf_set(wqe_els_did,
  7482. &wqe->xmit_els_rsp.wqe_dest, 0);
  7483. }
  7484. }
  7485. }
  7486. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7487. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7488. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7489. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7490. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7491. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7492. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7493. phba->vpi_ids[iocbq->vport->vpi]);
  7494. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7495. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7496. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7497. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7498. LPFC_WQE_LENLOC_WORD3);
  7499. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7500. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7501. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7502. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7503. iocbq->context2)->virt);
  7504. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7505. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7506. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7507. iocbq->vport->fc_myDID);
  7508. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7509. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7510. phba->vpi_ids[phba->pport->vpi]);
  7511. }
  7512. command_type = OTHER_COMMAND;
  7513. break;
  7514. case CMD_CLOSE_XRI_CN:
  7515. case CMD_ABORT_XRI_CN:
  7516. case CMD_ABORT_XRI_CX:
  7517. /* words 0-2 memcpy should be 0 rserved */
  7518. /* port will send abts */
  7519. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7520. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7521. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7522. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7523. } else
  7524. fip = 0;
  7525. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7526. /*
  7527. * The link is down, or the command was ELS_FIP
  7528. * so the fw does not need to send abts
  7529. * on the wire.
  7530. */
  7531. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7532. else
  7533. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7534. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7535. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7536. wqe->abort_cmd.rsrvd5 = 0;
  7537. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7538. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7539. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7540. /*
  7541. * The abort handler will send us CMD_ABORT_XRI_CN or
  7542. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7543. */
  7544. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7545. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7546. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7547. LPFC_WQE_LENLOC_NONE);
  7548. cmnd = CMD_ABORT_XRI_CX;
  7549. command_type = OTHER_COMMAND;
  7550. xritag = 0;
  7551. break;
  7552. case CMD_XMIT_BLS_RSP64_CX:
  7553. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7554. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7555. * we re-construct this WQE here based on information in
  7556. * iocbq from scratch.
  7557. */
  7558. memset(wqe, 0, sizeof(union lpfc_wqe));
  7559. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7560. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7561. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7562. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7563. LPFC_ABTS_UNSOL_INT) {
  7564. /* ABTS sent by initiator to CT exchange, the
  7565. * RX_ID field will be filled with the newly
  7566. * allocated responder XRI.
  7567. */
  7568. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7569. iocbq->sli4_xritag);
  7570. } else {
  7571. /* ABTS sent by responder to CT exchange, the
  7572. * RX_ID field will be filled with the responder
  7573. * RX_ID from ABTS.
  7574. */
  7575. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7576. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7577. }
  7578. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7579. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7580. /* Use CT=VPI */
  7581. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7582. ndlp->nlp_DID);
  7583. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7584. iocbq->iocb.ulpContext);
  7585. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7586. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7587. phba->vpi_ids[phba->pport->vpi]);
  7588. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7589. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7590. LPFC_WQE_LENLOC_NONE);
  7591. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7592. command_type = OTHER_COMMAND;
  7593. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7594. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7595. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7596. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7597. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7598. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7599. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7600. }
  7601. break;
  7602. case CMD_XRI_ABORTED_CX:
  7603. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7604. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7605. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7606. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7607. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7608. default:
  7609. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7610. "2014 Invalid command 0x%x\n",
  7611. iocbq->iocb.ulpCommand);
  7612. return IOCB_ERROR;
  7613. break;
  7614. }
  7615. if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
  7616. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
  7617. else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
  7618. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
  7619. else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
  7620. bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
  7621. iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
  7622. LPFC_IO_DIF_INSERT);
  7623. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7624. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7625. wqe->generic.wqe_com.abort_tag = abort_tag;
  7626. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7627. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7628. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7629. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7630. return 0;
  7631. }
  7632. /**
  7633. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7634. * @phba: Pointer to HBA context object.
  7635. * @ring_number: SLI ring number to issue iocb on.
  7636. * @piocb: Pointer to command iocb.
  7637. * @flag: Flag indicating if this command can be put into txq.
  7638. *
  7639. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7640. * an iocb command to an HBA with SLI-4 interface spec.
  7641. *
  7642. * This function is called with hbalock held. The function will return success
  7643. * after it successfully submit the iocb to firmware or after adding to the
  7644. * txq.
  7645. **/
  7646. static int
  7647. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7648. struct lpfc_iocbq *piocb, uint32_t flag)
  7649. {
  7650. struct lpfc_sglq *sglq;
  7651. union lpfc_wqe wqe;
  7652. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7653. if (piocb->sli4_xritag == NO_XRI) {
  7654. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7655. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7656. sglq = NULL;
  7657. else {
  7658. if (!list_empty(&pring->txq)) {
  7659. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7660. __lpfc_sli_ringtx_put(phba,
  7661. pring, piocb);
  7662. return IOCB_SUCCESS;
  7663. } else {
  7664. return IOCB_BUSY;
  7665. }
  7666. } else {
  7667. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7668. if (!sglq) {
  7669. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7670. __lpfc_sli_ringtx_put(phba,
  7671. pring,
  7672. piocb);
  7673. return IOCB_SUCCESS;
  7674. } else
  7675. return IOCB_BUSY;
  7676. }
  7677. }
  7678. }
  7679. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7680. /* These IO's already have an XRI and a mapped sgl. */
  7681. sglq = NULL;
  7682. } else {
  7683. /*
  7684. * This is a continuation of a commandi,(CX) so this
  7685. * sglq is on the active list
  7686. */
  7687. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
  7688. if (!sglq)
  7689. return IOCB_ERROR;
  7690. }
  7691. if (sglq) {
  7692. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7693. piocb->sli4_xritag = sglq->sli4_xritag;
  7694. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7695. return IOCB_ERROR;
  7696. }
  7697. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7698. return IOCB_ERROR;
  7699. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7700. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7701. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7702. &wqe))
  7703. return IOCB_ERROR;
  7704. } else {
  7705. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7706. return IOCB_ERROR;
  7707. }
  7708. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7709. return 0;
  7710. }
  7711. /**
  7712. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7713. *
  7714. * This routine wraps the actual lockless version for issusing IOCB function
  7715. * pointer from the lpfc_hba struct.
  7716. *
  7717. * Return codes:
  7718. * IOCB_ERROR - Error
  7719. * IOCB_SUCCESS - Success
  7720. * IOCB_BUSY - Busy
  7721. **/
  7722. int
  7723. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7724. struct lpfc_iocbq *piocb, uint32_t flag)
  7725. {
  7726. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7727. }
  7728. /**
  7729. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7730. * @phba: The hba struct for which this call is being executed.
  7731. * @dev_grp: The HBA PCI-Device group number.
  7732. *
  7733. * This routine sets up the SLI interface API function jump table in @phba
  7734. * struct.
  7735. * Returns: 0 - success, -ENODEV - failure.
  7736. **/
  7737. int
  7738. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7739. {
  7740. switch (dev_grp) {
  7741. case LPFC_PCI_DEV_LP:
  7742. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7743. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7744. break;
  7745. case LPFC_PCI_DEV_OC:
  7746. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7747. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7748. break;
  7749. default:
  7750. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7751. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7752. dev_grp);
  7753. return -ENODEV;
  7754. break;
  7755. }
  7756. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7757. return 0;
  7758. }
  7759. /**
  7760. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7761. * @phba: Pointer to HBA context object.
  7762. * @pring: Pointer to driver SLI ring object.
  7763. * @piocb: Pointer to command iocb.
  7764. * @flag: Flag indicating if this command can be put into txq.
  7765. *
  7766. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7767. * function. This function gets the hbalock and calls
  7768. * __lpfc_sli_issue_iocb function and will return the error returned
  7769. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7770. * functions which do not hold hbalock.
  7771. **/
  7772. int
  7773. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7774. struct lpfc_iocbq *piocb, uint32_t flag)
  7775. {
  7776. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  7777. struct lpfc_sli_ring *pring;
  7778. struct lpfc_queue *fpeq;
  7779. struct lpfc_eqe *eqe;
  7780. unsigned long iflags;
  7781. int rc, idx;
  7782. if (phba->sli_rev == LPFC_SLI_REV4) {
  7783. if (piocb->iocb_flag & LPFC_IO_FCP) {
  7784. if (unlikely(!phba->sli4_hba.fcp_wq))
  7785. return IOCB_ERROR;
  7786. idx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7787. piocb->fcp_wqidx = idx;
  7788. ring_number = MAX_SLI3_CONFIGURED_RINGS + idx;
  7789. pring = &phba->sli.ring[ring_number];
  7790. spin_lock_irqsave(&pring->ring_lock, iflags);
  7791. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7792. flag);
  7793. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  7794. if (lpfc_fcp_look_ahead) {
  7795. fcp_eq_hdl = &phba->sli4_hba.fcp_eq_hdl[idx];
  7796. if (atomic_dec_and_test(&fcp_eq_hdl->
  7797. fcp_eq_in_use)) {
  7798. /* Get associated EQ with this index */
  7799. fpeq = phba->sli4_hba.hba_eq[idx];
  7800. /* Turn off interrupts from this EQ */
  7801. lpfc_sli4_eq_clr_intr(fpeq);
  7802. /*
  7803. * Process all the events on FCP EQ
  7804. */
  7805. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  7806. lpfc_sli4_hba_handle_eqe(phba,
  7807. eqe, idx);
  7808. fpeq->EQ_processed++;
  7809. }
  7810. /* Always clear and re-arm the EQ */
  7811. lpfc_sli4_eq_release(fpeq,
  7812. LPFC_QUEUE_REARM);
  7813. }
  7814. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  7815. }
  7816. } else {
  7817. pring = &phba->sli.ring[ring_number];
  7818. spin_lock_irqsave(&pring->ring_lock, iflags);
  7819. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb,
  7820. flag);
  7821. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  7822. }
  7823. } else {
  7824. /* For now, SLI2/3 will still use hbalock */
  7825. spin_lock_irqsave(&phba->hbalock, iflags);
  7826. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7827. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7828. }
  7829. return rc;
  7830. }
  7831. /**
  7832. * lpfc_extra_ring_setup - Extra ring setup function
  7833. * @phba: Pointer to HBA context object.
  7834. *
  7835. * This function is called while driver attaches with the
  7836. * HBA to setup the extra ring. The extra ring is used
  7837. * only when driver needs to support target mode functionality
  7838. * or IP over FC functionalities.
  7839. *
  7840. * This function is called with no lock held.
  7841. **/
  7842. static int
  7843. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7844. {
  7845. struct lpfc_sli *psli;
  7846. struct lpfc_sli_ring *pring;
  7847. psli = &phba->sli;
  7848. /* Adjust cmd/rsp ring iocb entries more evenly */
  7849. /* Take some away from the FCP ring */
  7850. pring = &psli->ring[psli->fcp_ring];
  7851. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7852. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7853. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7854. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7855. /* and give them to the extra ring */
  7856. pring = &psli->ring[psli->extra_ring];
  7857. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7858. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7859. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7860. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7861. /* Setup default profile for this ring */
  7862. pring->iotag_max = 4096;
  7863. pring->num_mask = 1;
  7864. pring->prt[0].profile = 0; /* Mask 0 */
  7865. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7866. pring->prt[0].type = phba->cfg_multi_ring_type;
  7867. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7868. return 0;
  7869. }
  7870. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7871. * @phba: Pointer to HBA context object.
  7872. * @iocbq: Pointer to iocb object.
  7873. *
  7874. * The async_event handler calls this routine when it receives
  7875. * an ASYNC_STATUS_CN event from the port. The port generates
  7876. * this event when an Abort Sequence request to an rport fails
  7877. * twice in succession. The abort could be originated by the
  7878. * driver or by the port. The ABTS could have been for an ELS
  7879. * or FCP IO. The port only generates this event when an ABTS
  7880. * fails to complete after one retry.
  7881. */
  7882. static void
  7883. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7884. struct lpfc_iocbq *iocbq)
  7885. {
  7886. struct lpfc_nodelist *ndlp = NULL;
  7887. uint16_t rpi = 0, vpi = 0;
  7888. struct lpfc_vport *vport = NULL;
  7889. /* The rpi in the ulpContext is vport-sensitive. */
  7890. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7891. rpi = iocbq->iocb.ulpContext;
  7892. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7893. "3092 Port generated ABTS async event "
  7894. "on vpi %d rpi %d status 0x%x\n",
  7895. vpi, rpi, iocbq->iocb.ulpStatus);
  7896. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7897. if (!vport)
  7898. goto err_exit;
  7899. ndlp = lpfc_findnode_rpi(vport, rpi);
  7900. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7901. goto err_exit;
  7902. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7903. lpfc_sli_abts_recover_port(vport, ndlp);
  7904. return;
  7905. err_exit:
  7906. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7907. "3095 Event Context not found, no "
  7908. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7909. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7910. vpi, rpi);
  7911. }
  7912. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7913. * @phba: pointer to HBA context object.
  7914. * @ndlp: nodelist pointer for the impacted rport.
  7915. * @axri: pointer to the wcqe containing the failed exchange.
  7916. *
  7917. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7918. * port. The port generates this event when an abort exchange request to an
  7919. * rport fails twice in succession with no reply. The abort could be originated
  7920. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7921. */
  7922. void
  7923. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7924. struct lpfc_nodelist *ndlp,
  7925. struct sli4_wcqe_xri_aborted *axri)
  7926. {
  7927. struct lpfc_vport *vport;
  7928. uint32_t ext_status = 0;
  7929. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  7930. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7931. "3115 Node Context not found, driver "
  7932. "ignoring abts err event\n");
  7933. return;
  7934. }
  7935. vport = ndlp->vport;
  7936. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7937. "3116 Port generated FCP XRI ABORT event on "
  7938. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  7939. ndlp->vport->vpi, ndlp->nlp_rpi,
  7940. bf_get(lpfc_wcqe_xa_xri, axri),
  7941. bf_get(lpfc_wcqe_xa_status, axri),
  7942. axri->parameter);
  7943. /*
  7944. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  7945. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  7946. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  7947. */
  7948. ext_status = axri->parameter & IOERR_PARAM_MASK;
  7949. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  7950. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  7951. lpfc_sli_abts_recover_port(vport, ndlp);
  7952. }
  7953. /**
  7954. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7955. * @phba: Pointer to HBA context object.
  7956. * @pring: Pointer to driver SLI ring object.
  7957. * @iocbq: Pointer to iocb object.
  7958. *
  7959. * This function is called by the slow ring event handler
  7960. * function when there is an ASYNC event iocb in the ring.
  7961. * This function is called with no lock held.
  7962. * Currently this function handles only temperature related
  7963. * ASYNC events. The function decodes the temperature sensor
  7964. * event message and posts events for the management applications.
  7965. **/
  7966. static void
  7967. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7968. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7969. {
  7970. IOCB_t *icmd;
  7971. uint16_t evt_code;
  7972. struct temp_event temp_event_data;
  7973. struct Scsi_Host *shost;
  7974. uint32_t *iocb_w;
  7975. icmd = &iocbq->iocb;
  7976. evt_code = icmd->un.asyncstat.evt_code;
  7977. switch (evt_code) {
  7978. case ASYNC_TEMP_WARN:
  7979. case ASYNC_TEMP_SAFE:
  7980. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7981. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7982. if (evt_code == ASYNC_TEMP_WARN) {
  7983. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7984. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7985. "0347 Adapter is very hot, please take "
  7986. "corrective action. temperature : %d Celsius\n",
  7987. (uint32_t) icmd->ulpContext);
  7988. } else {
  7989. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7990. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7991. "0340 Adapter temperature is OK now. "
  7992. "temperature : %d Celsius\n",
  7993. (uint32_t) icmd->ulpContext);
  7994. }
  7995. /* Send temperature change event to applications */
  7996. shost = lpfc_shost_from_vport(phba->pport);
  7997. fc_host_post_vendor_event(shost, fc_get_event_number(),
  7998. sizeof(temp_event_data), (char *) &temp_event_data,
  7999. LPFC_NL_VENDOR_ID);
  8000. break;
  8001. case ASYNC_STATUS_CN:
  8002. lpfc_sli_abts_err_handler(phba, iocbq);
  8003. break;
  8004. default:
  8005. iocb_w = (uint32_t *) icmd;
  8006. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8007. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  8008. " evt_code 0x%x\n"
  8009. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  8010. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  8011. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  8012. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  8013. pring->ringno, icmd->un.asyncstat.evt_code,
  8014. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  8015. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  8016. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  8017. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  8018. break;
  8019. }
  8020. }
  8021. /**
  8022. * lpfc_sli_setup - SLI ring setup function
  8023. * @phba: Pointer to HBA context object.
  8024. *
  8025. * lpfc_sli_setup sets up rings of the SLI interface with
  8026. * number of iocbs per ring and iotags. This function is
  8027. * called while driver attach to the HBA and before the
  8028. * interrupts are enabled. So there is no need for locking.
  8029. *
  8030. * This function always returns 0.
  8031. **/
  8032. int
  8033. lpfc_sli_setup(struct lpfc_hba *phba)
  8034. {
  8035. int i, totiocbsize = 0;
  8036. struct lpfc_sli *psli = &phba->sli;
  8037. struct lpfc_sli_ring *pring;
  8038. psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
  8039. if (phba->sli_rev == LPFC_SLI_REV4)
  8040. psli->num_rings += phba->cfg_fcp_io_channel;
  8041. psli->sli_flag = 0;
  8042. psli->fcp_ring = LPFC_FCP_RING;
  8043. psli->next_ring = LPFC_FCP_NEXT_RING;
  8044. psli->extra_ring = LPFC_EXTRA_RING;
  8045. psli->iocbq_lookup = NULL;
  8046. psli->iocbq_lookup_len = 0;
  8047. psli->last_iotag = 0;
  8048. for (i = 0; i < psli->num_rings; i++) {
  8049. pring = &psli->ring[i];
  8050. switch (i) {
  8051. case LPFC_FCP_RING: /* ring 0 - FCP */
  8052. /* numCiocb and numRiocb are used in config_port */
  8053. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  8054. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  8055. pring->sli.sli3.numCiocb +=
  8056. SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  8057. pring->sli.sli3.numRiocb +=
  8058. SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  8059. pring->sli.sli3.numCiocb +=
  8060. SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  8061. pring->sli.sli3.numRiocb +=
  8062. SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  8063. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8064. SLI3_IOCB_CMD_SIZE :
  8065. SLI2_IOCB_CMD_SIZE;
  8066. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8067. SLI3_IOCB_RSP_SIZE :
  8068. SLI2_IOCB_RSP_SIZE;
  8069. pring->iotag_ctr = 0;
  8070. pring->iotag_max =
  8071. (phba->cfg_hba_queue_depth * 2);
  8072. pring->fast_iotag = pring->iotag_max;
  8073. pring->num_mask = 0;
  8074. break;
  8075. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  8076. /* numCiocb and numRiocb are used in config_port */
  8077. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  8078. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  8079. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8080. SLI3_IOCB_CMD_SIZE :
  8081. SLI2_IOCB_CMD_SIZE;
  8082. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8083. SLI3_IOCB_RSP_SIZE :
  8084. SLI2_IOCB_RSP_SIZE;
  8085. pring->iotag_max = phba->cfg_hba_queue_depth;
  8086. pring->num_mask = 0;
  8087. break;
  8088. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  8089. /* numCiocb and numRiocb are used in config_port */
  8090. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  8091. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  8092. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  8093. SLI3_IOCB_CMD_SIZE :
  8094. SLI2_IOCB_CMD_SIZE;
  8095. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  8096. SLI3_IOCB_RSP_SIZE :
  8097. SLI2_IOCB_RSP_SIZE;
  8098. pring->fast_iotag = 0;
  8099. pring->iotag_ctr = 0;
  8100. pring->iotag_max = 4096;
  8101. pring->lpfc_sli_rcv_async_status =
  8102. lpfc_sli_async_event_handler;
  8103. pring->num_mask = LPFC_MAX_RING_MASK;
  8104. pring->prt[0].profile = 0; /* Mask 0 */
  8105. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  8106. pring->prt[0].type = FC_TYPE_ELS;
  8107. pring->prt[0].lpfc_sli_rcv_unsol_event =
  8108. lpfc_els_unsol_event;
  8109. pring->prt[1].profile = 0; /* Mask 1 */
  8110. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  8111. pring->prt[1].type = FC_TYPE_ELS;
  8112. pring->prt[1].lpfc_sli_rcv_unsol_event =
  8113. lpfc_els_unsol_event;
  8114. pring->prt[2].profile = 0; /* Mask 2 */
  8115. /* NameServer Inquiry */
  8116. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  8117. /* NameServer */
  8118. pring->prt[2].type = FC_TYPE_CT;
  8119. pring->prt[2].lpfc_sli_rcv_unsol_event =
  8120. lpfc_ct_unsol_event;
  8121. pring->prt[3].profile = 0; /* Mask 3 */
  8122. /* NameServer response */
  8123. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8124. /* NameServer */
  8125. pring->prt[3].type = FC_TYPE_CT;
  8126. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8127. lpfc_ct_unsol_event;
  8128. break;
  8129. }
  8130. totiocbsize += (pring->sli.sli3.numCiocb *
  8131. pring->sli.sli3.sizeCiocb) +
  8132. (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
  8133. }
  8134. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8135. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8136. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8137. "SLI2 SLIM Data: x%x x%lx\n",
  8138. phba->brd_no, totiocbsize,
  8139. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8140. }
  8141. if (phba->cfg_multi_ring_support == 2)
  8142. lpfc_extra_ring_setup(phba);
  8143. return 0;
  8144. }
  8145. /**
  8146. * lpfc_sli_queue_setup - Queue initialization function
  8147. * @phba: Pointer to HBA context object.
  8148. *
  8149. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8150. * ring. This function also initializes ring indices of each ring.
  8151. * This function is called during the initialization of the SLI
  8152. * interface of an HBA.
  8153. * This function is called with no lock held and always returns
  8154. * 1.
  8155. **/
  8156. int
  8157. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8158. {
  8159. struct lpfc_sli *psli;
  8160. struct lpfc_sli_ring *pring;
  8161. int i;
  8162. psli = &phba->sli;
  8163. spin_lock_irq(&phba->hbalock);
  8164. INIT_LIST_HEAD(&psli->mboxq);
  8165. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8166. /* Initialize list headers for txq and txcmplq as double linked lists */
  8167. for (i = 0; i < psli->num_rings; i++) {
  8168. pring = &psli->ring[i];
  8169. pring->ringno = i;
  8170. pring->sli.sli3.next_cmdidx = 0;
  8171. pring->sli.sli3.local_getidx = 0;
  8172. pring->sli.sli3.cmdidx = 0;
  8173. INIT_LIST_HEAD(&pring->txq);
  8174. INIT_LIST_HEAD(&pring->txcmplq);
  8175. INIT_LIST_HEAD(&pring->iocb_continueq);
  8176. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8177. INIT_LIST_HEAD(&pring->postbufq);
  8178. spin_lock_init(&pring->ring_lock);
  8179. }
  8180. spin_unlock_irq(&phba->hbalock);
  8181. return 1;
  8182. }
  8183. /**
  8184. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8185. * @phba: Pointer to HBA context object.
  8186. *
  8187. * This routine flushes the mailbox command subsystem. It will unconditionally
  8188. * flush all the mailbox commands in the three possible stages in the mailbox
  8189. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8190. * command; and completed mailbox command queue. It is caller's responsibility
  8191. * to make sure that the driver is in the proper state to flush the mailbox
  8192. * command sub-system. Namely, the posting of mailbox commands into the
  8193. * pending mailbox command queue from the various clients must be stopped;
  8194. * either the HBA is in a state that it will never works on the outstanding
  8195. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8196. * mailbox command has been completed.
  8197. **/
  8198. static void
  8199. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8200. {
  8201. LIST_HEAD(completions);
  8202. struct lpfc_sli *psli = &phba->sli;
  8203. LPFC_MBOXQ_t *pmb;
  8204. unsigned long iflag;
  8205. /* Flush all the mailbox commands in the mbox system */
  8206. spin_lock_irqsave(&phba->hbalock, iflag);
  8207. /* The pending mailbox command queue */
  8208. list_splice_init(&phba->sli.mboxq, &completions);
  8209. /* The outstanding active mailbox command */
  8210. if (psli->mbox_active) {
  8211. list_add_tail(&psli->mbox_active->list, &completions);
  8212. psli->mbox_active = NULL;
  8213. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8214. }
  8215. /* The completed mailbox command queue */
  8216. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8217. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8218. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8219. while (!list_empty(&completions)) {
  8220. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8221. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8222. if (pmb->mbox_cmpl)
  8223. pmb->mbox_cmpl(phba, pmb);
  8224. }
  8225. }
  8226. /**
  8227. * lpfc_sli_host_down - Vport cleanup function
  8228. * @vport: Pointer to virtual port object.
  8229. *
  8230. * lpfc_sli_host_down is called to clean up the resources
  8231. * associated with a vport before destroying virtual
  8232. * port data structures.
  8233. * This function does following operations:
  8234. * - Free discovery resources associated with this virtual
  8235. * port.
  8236. * - Free iocbs associated with this virtual port in
  8237. * the txq.
  8238. * - Send abort for all iocb commands associated with this
  8239. * vport in txcmplq.
  8240. *
  8241. * This function is called with no lock held and always returns 1.
  8242. **/
  8243. int
  8244. lpfc_sli_host_down(struct lpfc_vport *vport)
  8245. {
  8246. LIST_HEAD(completions);
  8247. struct lpfc_hba *phba = vport->phba;
  8248. struct lpfc_sli *psli = &phba->sli;
  8249. struct lpfc_sli_ring *pring;
  8250. struct lpfc_iocbq *iocb, *next_iocb;
  8251. int i;
  8252. unsigned long flags = 0;
  8253. uint16_t prev_pring_flag;
  8254. lpfc_cleanup_discovery_resources(vport);
  8255. spin_lock_irqsave(&phba->hbalock, flags);
  8256. for (i = 0; i < psli->num_rings; i++) {
  8257. pring = &psli->ring[i];
  8258. prev_pring_flag = pring->flag;
  8259. /* Only slow rings */
  8260. if (pring->ringno == LPFC_ELS_RING) {
  8261. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8262. /* Set the lpfc data pending flag */
  8263. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8264. }
  8265. /*
  8266. * Error everything on the txq since these iocbs have not been
  8267. * given to the FW yet.
  8268. */
  8269. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8270. if (iocb->vport != vport)
  8271. continue;
  8272. list_move_tail(&iocb->list, &completions);
  8273. }
  8274. /* Next issue ABTS for everything on the txcmplq */
  8275. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8276. list) {
  8277. if (iocb->vport != vport)
  8278. continue;
  8279. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8280. }
  8281. pring->flag = prev_pring_flag;
  8282. }
  8283. spin_unlock_irqrestore(&phba->hbalock, flags);
  8284. /* Cancel all the IOCBs from the completions list */
  8285. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8286. IOERR_SLI_DOWN);
  8287. return 1;
  8288. }
  8289. /**
  8290. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8291. * @phba: Pointer to HBA context object.
  8292. *
  8293. * This function cleans up all iocb, buffers, mailbox commands
  8294. * while shutting down the HBA. This function is called with no
  8295. * lock held and always returns 1.
  8296. * This function does the following to cleanup driver resources:
  8297. * - Free discovery resources for each virtual port
  8298. * - Cleanup any pending fabric iocbs
  8299. * - Iterate through the iocb txq and free each entry
  8300. * in the list.
  8301. * - Free up any buffer posted to the HBA
  8302. * - Free mailbox commands in the mailbox queue.
  8303. **/
  8304. int
  8305. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8306. {
  8307. LIST_HEAD(completions);
  8308. struct lpfc_sli *psli = &phba->sli;
  8309. struct lpfc_sli_ring *pring;
  8310. struct lpfc_dmabuf *buf_ptr;
  8311. unsigned long flags = 0;
  8312. int i;
  8313. /* Shutdown the mailbox command sub-system */
  8314. lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
  8315. lpfc_hba_down_prep(phba);
  8316. lpfc_fabric_abort_hba(phba);
  8317. spin_lock_irqsave(&phba->hbalock, flags);
  8318. for (i = 0; i < psli->num_rings; i++) {
  8319. pring = &psli->ring[i];
  8320. /* Only slow rings */
  8321. if (pring->ringno == LPFC_ELS_RING) {
  8322. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8323. /* Set the lpfc data pending flag */
  8324. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8325. }
  8326. /*
  8327. * Error everything on the txq since these iocbs have not been
  8328. * given to the FW yet.
  8329. */
  8330. list_splice_init(&pring->txq, &completions);
  8331. }
  8332. spin_unlock_irqrestore(&phba->hbalock, flags);
  8333. /* Cancel all the IOCBs from the completions list */
  8334. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8335. IOERR_SLI_DOWN);
  8336. spin_lock_irqsave(&phba->hbalock, flags);
  8337. list_splice_init(&phba->elsbuf, &completions);
  8338. phba->elsbuf_cnt = 0;
  8339. phba->elsbuf_prev_cnt = 0;
  8340. spin_unlock_irqrestore(&phba->hbalock, flags);
  8341. while (!list_empty(&completions)) {
  8342. list_remove_head(&completions, buf_ptr,
  8343. struct lpfc_dmabuf, list);
  8344. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8345. kfree(buf_ptr);
  8346. }
  8347. /* Return any active mbox cmds */
  8348. del_timer_sync(&psli->mbox_tmo);
  8349. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8350. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8351. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8352. return 1;
  8353. }
  8354. /**
  8355. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8356. * @srcp: Source memory pointer.
  8357. * @destp: Destination memory pointer.
  8358. * @cnt: Number of words required to be copied.
  8359. *
  8360. * This function is used for copying data between driver memory
  8361. * and the SLI memory. This function also changes the endianness
  8362. * of each word if native endianness is different from SLI
  8363. * endianness. This function can be called with or without
  8364. * lock.
  8365. **/
  8366. void
  8367. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8368. {
  8369. uint32_t *src = srcp;
  8370. uint32_t *dest = destp;
  8371. uint32_t ldata;
  8372. int i;
  8373. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8374. ldata = *src;
  8375. ldata = le32_to_cpu(ldata);
  8376. *dest = ldata;
  8377. src++;
  8378. dest++;
  8379. }
  8380. }
  8381. /**
  8382. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8383. * @srcp: Source memory pointer.
  8384. * @destp: Destination memory pointer.
  8385. * @cnt: Number of words required to be copied.
  8386. *
  8387. * This function is used for copying data between a data structure
  8388. * with big endian representation to local endianness.
  8389. * This function can be called with or without lock.
  8390. **/
  8391. void
  8392. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8393. {
  8394. uint32_t *src = srcp;
  8395. uint32_t *dest = destp;
  8396. uint32_t ldata;
  8397. int i;
  8398. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8399. ldata = *src;
  8400. ldata = be32_to_cpu(ldata);
  8401. *dest = ldata;
  8402. src++;
  8403. dest++;
  8404. }
  8405. }
  8406. /**
  8407. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8408. * @phba: Pointer to HBA context object.
  8409. * @pring: Pointer to driver SLI ring object.
  8410. * @mp: Pointer to driver buffer object.
  8411. *
  8412. * This function is called with no lock held.
  8413. * It always return zero after adding the buffer to the postbufq
  8414. * buffer list.
  8415. **/
  8416. int
  8417. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8418. struct lpfc_dmabuf *mp)
  8419. {
  8420. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8421. later */
  8422. spin_lock_irq(&phba->hbalock);
  8423. list_add_tail(&mp->list, &pring->postbufq);
  8424. pring->postbufq_cnt++;
  8425. spin_unlock_irq(&phba->hbalock);
  8426. return 0;
  8427. }
  8428. /**
  8429. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8430. * @phba: Pointer to HBA context object.
  8431. *
  8432. * When HBQ is enabled, buffers are searched based on tags. This function
  8433. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8434. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8435. * does not conflict with tags of buffer posted for unsolicited events.
  8436. * The function returns the allocated tag. The function is called with
  8437. * no locks held.
  8438. **/
  8439. uint32_t
  8440. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8441. {
  8442. spin_lock_irq(&phba->hbalock);
  8443. phba->buffer_tag_count++;
  8444. /*
  8445. * Always set the QUE_BUFTAG_BIT to distiguish between
  8446. * a tag assigned by HBQ.
  8447. */
  8448. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8449. spin_unlock_irq(&phba->hbalock);
  8450. return phba->buffer_tag_count;
  8451. }
  8452. /**
  8453. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8454. * @phba: Pointer to HBA context object.
  8455. * @pring: Pointer to driver SLI ring object.
  8456. * @tag: Buffer tag.
  8457. *
  8458. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8459. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8460. * iocb is posted to the response ring with the tag of the buffer.
  8461. * This function searches the pring->postbufq list using the tag
  8462. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8463. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8464. * buffer is returned to the caller else NULL is returned.
  8465. * This function is called with no lock held.
  8466. **/
  8467. struct lpfc_dmabuf *
  8468. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8469. uint32_t tag)
  8470. {
  8471. struct lpfc_dmabuf *mp, *next_mp;
  8472. struct list_head *slp = &pring->postbufq;
  8473. /* Search postbufq, from the beginning, looking for a match on tag */
  8474. spin_lock_irq(&phba->hbalock);
  8475. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8476. if (mp->buffer_tag == tag) {
  8477. list_del_init(&mp->list);
  8478. pring->postbufq_cnt--;
  8479. spin_unlock_irq(&phba->hbalock);
  8480. return mp;
  8481. }
  8482. }
  8483. spin_unlock_irq(&phba->hbalock);
  8484. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8485. "0402 Cannot find virtual addr for buffer tag on "
  8486. "ring %d Data x%lx x%p x%p x%x\n",
  8487. pring->ringno, (unsigned long) tag,
  8488. slp->next, slp->prev, pring->postbufq_cnt);
  8489. return NULL;
  8490. }
  8491. /**
  8492. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8493. * @phba: Pointer to HBA context object.
  8494. * @pring: Pointer to driver SLI ring object.
  8495. * @phys: DMA address of the buffer.
  8496. *
  8497. * This function searches the buffer list using the dma_address
  8498. * of unsolicited event to find the driver's lpfc_dmabuf object
  8499. * corresponding to the dma_address. The function returns the
  8500. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8501. * This function is called by the ct and els unsolicited event
  8502. * handlers to get the buffer associated with the unsolicited
  8503. * event.
  8504. *
  8505. * This function is called with no lock held.
  8506. **/
  8507. struct lpfc_dmabuf *
  8508. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8509. dma_addr_t phys)
  8510. {
  8511. struct lpfc_dmabuf *mp, *next_mp;
  8512. struct list_head *slp = &pring->postbufq;
  8513. /* Search postbufq, from the beginning, looking for a match on phys */
  8514. spin_lock_irq(&phba->hbalock);
  8515. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8516. if (mp->phys == phys) {
  8517. list_del_init(&mp->list);
  8518. pring->postbufq_cnt--;
  8519. spin_unlock_irq(&phba->hbalock);
  8520. return mp;
  8521. }
  8522. }
  8523. spin_unlock_irq(&phba->hbalock);
  8524. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8525. "0410 Cannot find virtual addr for mapped buf on "
  8526. "ring %d Data x%llx x%p x%p x%x\n",
  8527. pring->ringno, (unsigned long long)phys,
  8528. slp->next, slp->prev, pring->postbufq_cnt);
  8529. return NULL;
  8530. }
  8531. /**
  8532. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8533. * @phba: Pointer to HBA context object.
  8534. * @cmdiocb: Pointer to driver command iocb object.
  8535. * @rspiocb: Pointer to driver response iocb object.
  8536. *
  8537. * This function is the completion handler for the abort iocbs for
  8538. * ELS commands. This function is called from the ELS ring event
  8539. * handler with no lock held. This function frees memory resources
  8540. * associated with the abort iocb.
  8541. **/
  8542. static void
  8543. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8544. struct lpfc_iocbq *rspiocb)
  8545. {
  8546. IOCB_t *irsp = &rspiocb->iocb;
  8547. uint16_t abort_iotag, abort_context;
  8548. struct lpfc_iocbq *abort_iocb = NULL;
  8549. if (irsp->ulpStatus) {
  8550. /*
  8551. * Assume that the port already completed and returned, or
  8552. * will return the iocb. Just Log the message.
  8553. */
  8554. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8555. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8556. spin_lock_irq(&phba->hbalock);
  8557. if (phba->sli_rev < LPFC_SLI_REV4) {
  8558. if (abort_iotag != 0 &&
  8559. abort_iotag <= phba->sli.last_iotag)
  8560. abort_iocb =
  8561. phba->sli.iocbq_lookup[abort_iotag];
  8562. } else
  8563. /* For sli4 the abort_tag is the XRI,
  8564. * so the abort routine puts the iotag of the iocb
  8565. * being aborted in the context field of the abort
  8566. * IOCB.
  8567. */
  8568. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8569. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8570. "0327 Cannot abort els iocb %p "
  8571. "with tag %x context %x, abort status %x, "
  8572. "abort code %x\n",
  8573. abort_iocb, abort_iotag, abort_context,
  8574. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8575. spin_unlock_irq(&phba->hbalock);
  8576. }
  8577. lpfc_sli_release_iocbq(phba, cmdiocb);
  8578. return;
  8579. }
  8580. /**
  8581. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8582. * @phba: Pointer to HBA context object.
  8583. * @cmdiocb: Pointer to driver command iocb object.
  8584. * @rspiocb: Pointer to driver response iocb object.
  8585. *
  8586. * The function is called from SLI ring event handler with no
  8587. * lock held. This function is the completion handler for ELS commands
  8588. * which are aborted. The function frees memory resources used for
  8589. * the aborted ELS commands.
  8590. **/
  8591. static void
  8592. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8593. struct lpfc_iocbq *rspiocb)
  8594. {
  8595. IOCB_t *irsp = &rspiocb->iocb;
  8596. /* ELS cmd tag <ulpIoTag> completes */
  8597. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8598. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8599. "x%x x%x x%x\n",
  8600. irsp->ulpIoTag, irsp->ulpStatus,
  8601. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8602. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8603. lpfc_ct_free_iocb(phba, cmdiocb);
  8604. else
  8605. lpfc_els_free_iocb(phba, cmdiocb);
  8606. return;
  8607. }
  8608. /**
  8609. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8610. * @phba: Pointer to HBA context object.
  8611. * @pring: Pointer to driver SLI ring object.
  8612. * @cmdiocb: Pointer to driver command iocb object.
  8613. *
  8614. * This function issues an abort iocb for the provided command iocb down to
  8615. * the port. Other than the case the outstanding command iocb is an abort
  8616. * request, this function issues abort out unconditionally. This function is
  8617. * called with hbalock held. The function returns 0 when it fails due to
  8618. * memory allocation failure or when the command iocb is an abort request.
  8619. **/
  8620. static int
  8621. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8622. struct lpfc_iocbq *cmdiocb)
  8623. {
  8624. struct lpfc_vport *vport = cmdiocb->vport;
  8625. struct lpfc_iocbq *abtsiocbp;
  8626. IOCB_t *icmd = NULL;
  8627. IOCB_t *iabt = NULL;
  8628. int retval;
  8629. unsigned long iflags;
  8630. /*
  8631. * There are certain command types we don't want to abort. And we
  8632. * don't want to abort commands that are already in the process of
  8633. * being aborted.
  8634. */
  8635. icmd = &cmdiocb->iocb;
  8636. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8637. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8638. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8639. return 0;
  8640. /* issue ABTS for this IOCB based on iotag */
  8641. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8642. if (abtsiocbp == NULL)
  8643. return 0;
  8644. /* This signals the response to set the correct status
  8645. * before calling the completion handler
  8646. */
  8647. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8648. iabt = &abtsiocbp->iocb;
  8649. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8650. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8651. if (phba->sli_rev == LPFC_SLI_REV4) {
  8652. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8653. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8654. }
  8655. else
  8656. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8657. iabt->ulpLe = 1;
  8658. iabt->ulpClass = icmd->ulpClass;
  8659. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8660. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8661. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8662. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8663. if (phba->link_state >= LPFC_LINK_UP)
  8664. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8665. else
  8666. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8667. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8668. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8669. "0339 Abort xri x%x, original iotag x%x, "
  8670. "abort cmd iotag x%x\n",
  8671. iabt->un.acxri.abortIoTag,
  8672. iabt->un.acxri.abortContextTag,
  8673. abtsiocbp->iotag);
  8674. if (phba->sli_rev == LPFC_SLI_REV4) {
  8675. /* Note: both hbalock and ring_lock need to be set here */
  8676. spin_lock_irqsave(&pring->ring_lock, iflags);
  8677. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8678. abtsiocbp, 0);
  8679. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  8680. } else {
  8681. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  8682. abtsiocbp, 0);
  8683. }
  8684. if (retval)
  8685. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8686. /*
  8687. * Caller to this routine should check for IOCB_ERROR
  8688. * and handle it properly. This routine no longer removes
  8689. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8690. */
  8691. return retval;
  8692. }
  8693. /**
  8694. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8695. * @phba: Pointer to HBA context object.
  8696. * @pring: Pointer to driver SLI ring object.
  8697. * @cmdiocb: Pointer to driver command iocb object.
  8698. *
  8699. * This function issues an abort iocb for the provided command iocb. In case
  8700. * of unloading, the abort iocb will not be issued to commands on the ELS
  8701. * ring. Instead, the callback function shall be changed to those commands
  8702. * so that nothing happens when them finishes. This function is called with
  8703. * hbalock held. The function returns 0 when the command iocb is an abort
  8704. * request.
  8705. **/
  8706. int
  8707. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8708. struct lpfc_iocbq *cmdiocb)
  8709. {
  8710. struct lpfc_vport *vport = cmdiocb->vport;
  8711. int retval = IOCB_ERROR;
  8712. IOCB_t *icmd = NULL;
  8713. /*
  8714. * There are certain command types we don't want to abort. And we
  8715. * don't want to abort commands that are already in the process of
  8716. * being aborted.
  8717. */
  8718. icmd = &cmdiocb->iocb;
  8719. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8720. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8721. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8722. return 0;
  8723. /*
  8724. * If we're unloading, don't abort iocb on the ELS ring, but change
  8725. * the callback so that nothing happens when it finishes.
  8726. */
  8727. if ((vport->load_flag & FC_UNLOADING) &&
  8728. (pring->ringno == LPFC_ELS_RING)) {
  8729. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8730. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8731. else
  8732. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8733. goto abort_iotag_exit;
  8734. }
  8735. /* Now, we try to issue the abort to the cmdiocb out */
  8736. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8737. abort_iotag_exit:
  8738. /*
  8739. * Caller to this routine should check for IOCB_ERROR
  8740. * and handle it properly. This routine no longer removes
  8741. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8742. */
  8743. return retval;
  8744. }
  8745. /**
  8746. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8747. * @phba: Pointer to HBA context object.
  8748. * @pring: Pointer to driver SLI ring object.
  8749. *
  8750. * This function aborts all iocbs in the given ring and frees all the iocb
  8751. * objects in txq. This function issues abort iocbs unconditionally for all
  8752. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8753. * to complete before the return of this function. The caller is not required
  8754. * to hold any locks.
  8755. **/
  8756. static void
  8757. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8758. {
  8759. LIST_HEAD(completions);
  8760. struct lpfc_iocbq *iocb, *next_iocb;
  8761. if (pring->ringno == LPFC_ELS_RING)
  8762. lpfc_fabric_abort_hba(phba);
  8763. spin_lock_irq(&phba->hbalock);
  8764. /* Take off all the iocbs on txq for cancelling */
  8765. list_splice_init(&pring->txq, &completions);
  8766. pring->txq_cnt = 0;
  8767. /* Next issue ABTS for everything on the txcmplq */
  8768. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8769. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8770. spin_unlock_irq(&phba->hbalock);
  8771. /* Cancel all the IOCBs from the completions list */
  8772. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8773. IOERR_SLI_ABORTED);
  8774. }
  8775. /**
  8776. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8777. * @phba: pointer to lpfc HBA data structure.
  8778. *
  8779. * This routine will abort all pending and outstanding iocbs to an HBA.
  8780. **/
  8781. void
  8782. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8783. {
  8784. struct lpfc_sli *psli = &phba->sli;
  8785. struct lpfc_sli_ring *pring;
  8786. int i;
  8787. for (i = 0; i < psli->num_rings; i++) {
  8788. pring = &psli->ring[i];
  8789. lpfc_sli_iocb_ring_abort(phba, pring);
  8790. }
  8791. }
  8792. /**
  8793. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8794. * @iocbq: Pointer to driver iocb object.
  8795. * @vport: Pointer to driver virtual port object.
  8796. * @tgt_id: SCSI ID of the target.
  8797. * @lun_id: LUN ID of the scsi device.
  8798. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8799. *
  8800. * This function acts as an iocb filter for functions which abort or count
  8801. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8802. * 0 if the filtering criteria is met for the given iocb and will return
  8803. * 1 if the filtering criteria is not met.
  8804. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8805. * given iocb is for the SCSI device specified by vport, tgt_id and
  8806. * lun_id parameter.
  8807. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8808. * given iocb is for the SCSI target specified by vport and tgt_id
  8809. * parameters.
  8810. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8811. * given iocb is for the SCSI host associated with the given vport.
  8812. * This function is called with no locks held.
  8813. **/
  8814. static int
  8815. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8816. uint16_t tgt_id, uint64_t lun_id,
  8817. lpfc_ctx_cmd ctx_cmd)
  8818. {
  8819. struct lpfc_scsi_buf *lpfc_cmd;
  8820. int rc = 1;
  8821. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8822. return rc;
  8823. if (iocbq->vport != vport)
  8824. return rc;
  8825. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8826. if (lpfc_cmd->pCmd == NULL)
  8827. return rc;
  8828. switch (ctx_cmd) {
  8829. case LPFC_CTX_LUN:
  8830. if ((lpfc_cmd->rdata->pnode) &&
  8831. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8832. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8833. rc = 0;
  8834. break;
  8835. case LPFC_CTX_TGT:
  8836. if ((lpfc_cmd->rdata->pnode) &&
  8837. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8838. rc = 0;
  8839. break;
  8840. case LPFC_CTX_HOST:
  8841. rc = 0;
  8842. break;
  8843. default:
  8844. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8845. __func__, ctx_cmd);
  8846. break;
  8847. }
  8848. return rc;
  8849. }
  8850. /**
  8851. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8852. * @vport: Pointer to virtual port.
  8853. * @tgt_id: SCSI ID of the target.
  8854. * @lun_id: LUN ID of the scsi device.
  8855. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8856. *
  8857. * This function returns number of FCP commands pending for the vport.
  8858. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8859. * commands pending on the vport associated with SCSI device specified
  8860. * by tgt_id and lun_id parameters.
  8861. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8862. * commands pending on the vport associated with SCSI target specified
  8863. * by tgt_id parameter.
  8864. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8865. * commands pending on the vport.
  8866. * This function returns the number of iocbs which satisfy the filter.
  8867. * This function is called without any lock held.
  8868. **/
  8869. int
  8870. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8871. lpfc_ctx_cmd ctx_cmd)
  8872. {
  8873. struct lpfc_hba *phba = vport->phba;
  8874. struct lpfc_iocbq *iocbq;
  8875. int sum, i;
  8876. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8877. iocbq = phba->sli.iocbq_lookup[i];
  8878. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8879. ctx_cmd) == 0)
  8880. sum++;
  8881. }
  8882. return sum;
  8883. }
  8884. /**
  8885. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8886. * @phba: Pointer to HBA context object
  8887. * @cmdiocb: Pointer to command iocb object.
  8888. * @rspiocb: Pointer to response iocb object.
  8889. *
  8890. * This function is called when an aborted FCP iocb completes. This
  8891. * function is called by the ring event handler with no lock held.
  8892. * This function frees the iocb.
  8893. **/
  8894. void
  8895. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8896. struct lpfc_iocbq *rspiocb)
  8897. {
  8898. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8899. "3096 ABORT_XRI_CN completing on xri x%x "
  8900. "original iotag x%x, abort cmd iotag x%x "
  8901. "status 0x%x, reason 0x%x\n",
  8902. cmdiocb->iocb.un.acxri.abortContextTag,
  8903. cmdiocb->iocb.un.acxri.abortIoTag,
  8904. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8905. rspiocb->iocb.un.ulpWord[4]);
  8906. lpfc_sli_release_iocbq(phba, cmdiocb);
  8907. return;
  8908. }
  8909. /**
  8910. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8911. * @vport: Pointer to virtual port.
  8912. * @pring: Pointer to driver SLI ring object.
  8913. * @tgt_id: SCSI ID of the target.
  8914. * @lun_id: LUN ID of the scsi device.
  8915. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8916. *
  8917. * This function sends an abort command for every SCSI command
  8918. * associated with the given virtual port pending on the ring
  8919. * filtered by lpfc_sli_validate_fcp_iocb function.
  8920. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8921. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8922. * parameters
  8923. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8924. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8925. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8926. * FCP iocbs associated with virtual port.
  8927. * This function returns number of iocbs it failed to abort.
  8928. * This function is called with no locks held.
  8929. **/
  8930. int
  8931. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8932. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8933. {
  8934. struct lpfc_hba *phba = vport->phba;
  8935. struct lpfc_iocbq *iocbq;
  8936. struct lpfc_iocbq *abtsiocb;
  8937. IOCB_t *cmd = NULL;
  8938. int errcnt = 0, ret_val = 0;
  8939. int i;
  8940. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8941. iocbq = phba->sli.iocbq_lookup[i];
  8942. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8943. abort_cmd) != 0)
  8944. continue;
  8945. /* issue ABTS for this IOCB based on iotag */
  8946. abtsiocb = lpfc_sli_get_iocbq(phba);
  8947. if (abtsiocb == NULL) {
  8948. errcnt++;
  8949. continue;
  8950. }
  8951. cmd = &iocbq->iocb;
  8952. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8953. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8954. if (phba->sli_rev == LPFC_SLI_REV4)
  8955. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8956. else
  8957. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8958. abtsiocb->iocb.ulpLe = 1;
  8959. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8960. abtsiocb->vport = phba->pport;
  8961. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8962. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8963. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8964. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8965. if (lpfc_is_link_up(phba))
  8966. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8967. else
  8968. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8969. /* Setup callback routine and issue the command. */
  8970. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8971. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8972. abtsiocb, 0);
  8973. if (ret_val == IOCB_ERROR) {
  8974. lpfc_sli_release_iocbq(phba, abtsiocb);
  8975. errcnt++;
  8976. continue;
  8977. }
  8978. }
  8979. return errcnt;
  8980. }
  8981. /**
  8982. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8983. * @phba: Pointer to HBA context object.
  8984. * @cmdiocbq: Pointer to command iocb.
  8985. * @rspiocbq: Pointer to response iocb.
  8986. *
  8987. * This function is the completion handler for iocbs issued using
  8988. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8989. * ring event handler function without any lock held. This function
  8990. * can be called from both worker thread context and interrupt
  8991. * context. This function also can be called from other thread which
  8992. * cleans up the SLI layer objects.
  8993. * This function copy the contents of the response iocb to the
  8994. * response iocb memory object provided by the caller of
  8995. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  8996. * sleeps for the iocb completion.
  8997. **/
  8998. static void
  8999. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  9000. struct lpfc_iocbq *cmdiocbq,
  9001. struct lpfc_iocbq *rspiocbq)
  9002. {
  9003. wait_queue_head_t *pdone_q;
  9004. unsigned long iflags;
  9005. struct lpfc_scsi_buf *lpfc_cmd;
  9006. spin_lock_irqsave(&phba->hbalock, iflags);
  9007. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  9008. if (cmdiocbq->context2 && rspiocbq)
  9009. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  9010. &rspiocbq->iocb, sizeof(IOCB_t));
  9011. /* Set the exchange busy flag for task management commands */
  9012. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  9013. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  9014. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  9015. cur_iocbq);
  9016. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  9017. }
  9018. pdone_q = cmdiocbq->context_un.wait_queue;
  9019. if (pdone_q)
  9020. wake_up(pdone_q);
  9021. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9022. return;
  9023. }
  9024. /**
  9025. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  9026. * @phba: Pointer to HBA context object..
  9027. * @piocbq: Pointer to command iocb.
  9028. * @flag: Flag to test.
  9029. *
  9030. * This routine grabs the hbalock and then test the iocb_flag to
  9031. * see if the passed in flag is set.
  9032. * Returns:
  9033. * 1 if flag is set.
  9034. * 0 if flag is not set.
  9035. **/
  9036. static int
  9037. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  9038. struct lpfc_iocbq *piocbq, uint32_t flag)
  9039. {
  9040. unsigned long iflags;
  9041. int ret;
  9042. spin_lock_irqsave(&phba->hbalock, iflags);
  9043. ret = piocbq->iocb_flag & flag;
  9044. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9045. return ret;
  9046. }
  9047. /**
  9048. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  9049. * @phba: Pointer to HBA context object..
  9050. * @pring: Pointer to sli ring.
  9051. * @piocb: Pointer to command iocb.
  9052. * @prspiocbq: Pointer to response iocb.
  9053. * @timeout: Timeout in number of seconds.
  9054. *
  9055. * This function issues the iocb to firmware and waits for the
  9056. * iocb to complete. If the iocb command is not
  9057. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  9058. * Caller should not free the iocb resources if this function
  9059. * returns IOCB_TIMEDOUT.
  9060. * The function waits for the iocb completion using an
  9061. * non-interruptible wait.
  9062. * This function will sleep while waiting for iocb completion.
  9063. * So, this function should not be called from any context which
  9064. * does not allow sleeping. Due to the same reason, this function
  9065. * cannot be called with interrupt disabled.
  9066. * This function assumes that the iocb completions occur while
  9067. * this function sleep. So, this function cannot be called from
  9068. * the thread which process iocb completion for this ring.
  9069. * This function clears the iocb_flag of the iocb object before
  9070. * issuing the iocb and the iocb completion handler sets this
  9071. * flag and wakes this thread when the iocb completes.
  9072. * The contents of the response iocb will be copied to prspiocbq
  9073. * by the completion handler when the command completes.
  9074. * This function returns IOCB_SUCCESS when success.
  9075. * This function is called with no lock held.
  9076. **/
  9077. int
  9078. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  9079. uint32_t ring_number,
  9080. struct lpfc_iocbq *piocb,
  9081. struct lpfc_iocbq *prspiocbq,
  9082. uint32_t timeout)
  9083. {
  9084. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9085. long timeleft, timeout_req = 0;
  9086. int retval = IOCB_SUCCESS;
  9087. uint32_t creg_val;
  9088. struct lpfc_iocbq *iocb;
  9089. int txq_cnt = 0;
  9090. int txcmplq_cnt = 0;
  9091. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9092. /*
  9093. * If the caller has provided a response iocbq buffer, then context2
  9094. * is NULL or its an error.
  9095. */
  9096. if (prspiocbq) {
  9097. if (piocb->context2)
  9098. return IOCB_ERROR;
  9099. piocb->context2 = prspiocbq;
  9100. }
  9101. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  9102. piocb->context_un.wait_queue = &done_q;
  9103. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  9104. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9105. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9106. return IOCB_ERROR;
  9107. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  9108. writel(creg_val, phba->HCregaddr);
  9109. readl(phba->HCregaddr); /* flush */
  9110. }
  9111. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  9112. SLI_IOCB_RET_IOCB);
  9113. if (retval == IOCB_SUCCESS) {
  9114. timeout_req = msecs_to_jiffies(timeout * 1000);
  9115. timeleft = wait_event_timeout(done_q,
  9116. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  9117. timeout_req);
  9118. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  9119. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9120. "0331 IOCB wake signaled\n");
  9121. } else if (timeleft == 0) {
  9122. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9123. "0338 IOCB wait timeout error - no "
  9124. "wake response Data x%x\n", timeout);
  9125. retval = IOCB_TIMEDOUT;
  9126. } else {
  9127. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9128. "0330 IOCB wake NOT set, "
  9129. "Data x%x x%lx\n",
  9130. timeout, (timeleft / jiffies));
  9131. retval = IOCB_TIMEDOUT;
  9132. }
  9133. } else if (retval == IOCB_BUSY) {
  9134. if (phba->cfg_log_verbose & LOG_SLI) {
  9135. list_for_each_entry(iocb, &pring->txq, list) {
  9136. txq_cnt++;
  9137. }
  9138. list_for_each_entry(iocb, &pring->txcmplq, list) {
  9139. txcmplq_cnt++;
  9140. }
  9141. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9142. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9143. phba->iocb_cnt, txq_cnt, txcmplq_cnt);
  9144. }
  9145. return retval;
  9146. } else {
  9147. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9148. "0332 IOCB wait issue failed, Data x%x\n",
  9149. retval);
  9150. retval = IOCB_ERROR;
  9151. }
  9152. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9153. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9154. return IOCB_ERROR;
  9155. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9156. writel(creg_val, phba->HCregaddr);
  9157. readl(phba->HCregaddr); /* flush */
  9158. }
  9159. if (prspiocbq)
  9160. piocb->context2 = NULL;
  9161. piocb->context_un.wait_queue = NULL;
  9162. piocb->iocb_cmpl = NULL;
  9163. return retval;
  9164. }
  9165. /**
  9166. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9167. * @phba: Pointer to HBA context object.
  9168. * @pmboxq: Pointer to driver mailbox object.
  9169. * @timeout: Timeout in number of seconds.
  9170. *
  9171. * This function issues the mailbox to firmware and waits for the
  9172. * mailbox command to complete. If the mailbox command is not
  9173. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9174. * The function waits for the mailbox completion using an
  9175. * interruptible wait. If the thread is woken up due to a
  9176. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9177. * should not free the mailbox resources, if this function returns
  9178. * MBX_TIMEOUT.
  9179. * This function will sleep while waiting for mailbox completion.
  9180. * So, this function should not be called from any context which
  9181. * does not allow sleeping. Due to the same reason, this function
  9182. * cannot be called with interrupt disabled.
  9183. * This function assumes that the mailbox completion occurs while
  9184. * this function sleep. So, this function cannot be called from
  9185. * the worker thread which processes mailbox completion.
  9186. * This function is called in the context of HBA management
  9187. * applications.
  9188. * This function returns MBX_SUCCESS when successful.
  9189. * This function is called with no lock held.
  9190. **/
  9191. int
  9192. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9193. uint32_t timeout)
  9194. {
  9195. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9196. int retval;
  9197. unsigned long flag;
  9198. /* The caller must leave context1 empty. */
  9199. if (pmboxq->context1)
  9200. return MBX_NOT_FINISHED;
  9201. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9202. /* setup wake call as IOCB callback */
  9203. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9204. /* setup context field to pass wait_queue pointer to wake function */
  9205. pmboxq->context1 = &done_q;
  9206. /* now issue the command */
  9207. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9208. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9209. wait_event_interruptible_timeout(done_q,
  9210. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9211. msecs_to_jiffies(timeout * 1000));
  9212. spin_lock_irqsave(&phba->hbalock, flag);
  9213. pmboxq->context1 = NULL;
  9214. /*
  9215. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9216. * else do not free the resources.
  9217. */
  9218. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9219. retval = MBX_SUCCESS;
  9220. lpfc_sli4_swap_str(phba, pmboxq);
  9221. } else {
  9222. retval = MBX_TIMEOUT;
  9223. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9224. }
  9225. spin_unlock_irqrestore(&phba->hbalock, flag);
  9226. }
  9227. return retval;
  9228. }
  9229. /**
  9230. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9231. * @phba: Pointer to HBA context.
  9232. *
  9233. * This function is called to shutdown the driver's mailbox sub-system.
  9234. * It first marks the mailbox sub-system is in a block state to prevent
  9235. * the asynchronous mailbox command from issued off the pending mailbox
  9236. * command queue. If the mailbox command sub-system shutdown is due to
  9237. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9238. * the mailbox sub-system flush routine to forcefully bring down the
  9239. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9240. * as with offline or HBA function reset), this routine will wait for the
  9241. * outstanding mailbox command to complete before invoking the mailbox
  9242. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9243. **/
  9244. void
  9245. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
  9246. {
  9247. struct lpfc_sli *psli = &phba->sli;
  9248. unsigned long timeout;
  9249. if (mbx_action == LPFC_MBX_NO_WAIT) {
  9250. /* delay 100ms for port state */
  9251. msleep(100);
  9252. lpfc_sli_mbox_sys_flush(phba);
  9253. return;
  9254. }
  9255. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9256. spin_lock_irq(&phba->hbalock);
  9257. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9258. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9259. /* Determine how long we might wait for the active mailbox
  9260. * command to be gracefully completed by firmware.
  9261. */
  9262. if (phba->sli.mbox_active)
  9263. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9264. phba->sli.mbox_active) *
  9265. 1000) + jiffies;
  9266. spin_unlock_irq(&phba->hbalock);
  9267. while (phba->sli.mbox_active) {
  9268. /* Check active mailbox complete status every 2ms */
  9269. msleep(2);
  9270. if (time_after(jiffies, timeout))
  9271. /* Timeout, let the mailbox flush routine to
  9272. * forcefully release active mailbox command
  9273. */
  9274. break;
  9275. }
  9276. } else
  9277. spin_unlock_irq(&phba->hbalock);
  9278. lpfc_sli_mbox_sys_flush(phba);
  9279. }
  9280. /**
  9281. * lpfc_sli_eratt_read - read sli-3 error attention events
  9282. * @phba: Pointer to HBA context.
  9283. *
  9284. * This function is called to read the SLI3 device error attention registers
  9285. * for possible error attention events. The caller must hold the hostlock
  9286. * with spin_lock_irq().
  9287. *
  9288. * This function returns 1 when there is Error Attention in the Host Attention
  9289. * Register and returns 0 otherwise.
  9290. **/
  9291. static int
  9292. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9293. {
  9294. uint32_t ha_copy;
  9295. /* Read chip Host Attention (HA) register */
  9296. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9297. goto unplug_err;
  9298. if (ha_copy & HA_ERATT) {
  9299. /* Read host status register to retrieve error event */
  9300. if (lpfc_sli_read_hs(phba))
  9301. goto unplug_err;
  9302. /* Check if there is a deferred error condition is active */
  9303. if ((HS_FFER1 & phba->work_hs) &&
  9304. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9305. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9306. phba->hba_flag |= DEFER_ERATT;
  9307. /* Clear all interrupt enable conditions */
  9308. writel(0, phba->HCregaddr);
  9309. readl(phba->HCregaddr);
  9310. }
  9311. /* Set the driver HA work bitmap */
  9312. phba->work_ha |= HA_ERATT;
  9313. /* Indicate polling handles this ERATT */
  9314. phba->hba_flag |= HBA_ERATT_HANDLED;
  9315. return 1;
  9316. }
  9317. return 0;
  9318. unplug_err:
  9319. /* Set the driver HS work bitmap */
  9320. phba->work_hs |= UNPLUG_ERR;
  9321. /* Set the driver HA work bitmap */
  9322. phba->work_ha |= HA_ERATT;
  9323. /* Indicate polling handles this ERATT */
  9324. phba->hba_flag |= HBA_ERATT_HANDLED;
  9325. return 1;
  9326. }
  9327. /**
  9328. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9329. * @phba: Pointer to HBA context.
  9330. *
  9331. * This function is called to read the SLI4 device error attention registers
  9332. * for possible error attention events. The caller must hold the hostlock
  9333. * with spin_lock_irq().
  9334. *
  9335. * This function returns 1 when there is Error Attention in the Host Attention
  9336. * Register and returns 0 otherwise.
  9337. **/
  9338. static int
  9339. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9340. {
  9341. uint32_t uerr_sta_hi, uerr_sta_lo;
  9342. uint32_t if_type, portsmphr;
  9343. struct lpfc_register portstat_reg;
  9344. /*
  9345. * For now, use the SLI4 device internal unrecoverable error
  9346. * registers for error attention. This can be changed later.
  9347. */
  9348. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9349. switch (if_type) {
  9350. case LPFC_SLI_INTF_IF_TYPE_0:
  9351. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9352. &uerr_sta_lo) ||
  9353. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9354. &uerr_sta_hi)) {
  9355. phba->work_hs |= UNPLUG_ERR;
  9356. phba->work_ha |= HA_ERATT;
  9357. phba->hba_flag |= HBA_ERATT_HANDLED;
  9358. return 1;
  9359. }
  9360. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9361. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9362. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9363. "1423 HBA Unrecoverable error: "
  9364. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9365. "ue_mask_lo_reg=0x%x, "
  9366. "ue_mask_hi_reg=0x%x\n",
  9367. uerr_sta_lo, uerr_sta_hi,
  9368. phba->sli4_hba.ue_mask_lo,
  9369. phba->sli4_hba.ue_mask_hi);
  9370. phba->work_status[0] = uerr_sta_lo;
  9371. phba->work_status[1] = uerr_sta_hi;
  9372. phba->work_ha |= HA_ERATT;
  9373. phba->hba_flag |= HBA_ERATT_HANDLED;
  9374. return 1;
  9375. }
  9376. break;
  9377. case LPFC_SLI_INTF_IF_TYPE_2:
  9378. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9379. &portstat_reg.word0) ||
  9380. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9381. &portsmphr)){
  9382. phba->work_hs |= UNPLUG_ERR;
  9383. phba->work_ha |= HA_ERATT;
  9384. phba->hba_flag |= HBA_ERATT_HANDLED;
  9385. return 1;
  9386. }
  9387. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9388. phba->work_status[0] =
  9389. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9390. phba->work_status[1] =
  9391. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9392. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9393. "2885 Port Status Event: "
  9394. "port status reg 0x%x, "
  9395. "port smphr reg 0x%x, "
  9396. "error 1=0x%x, error 2=0x%x\n",
  9397. portstat_reg.word0,
  9398. portsmphr,
  9399. phba->work_status[0],
  9400. phba->work_status[1]);
  9401. phba->work_ha |= HA_ERATT;
  9402. phba->hba_flag |= HBA_ERATT_HANDLED;
  9403. return 1;
  9404. }
  9405. break;
  9406. case LPFC_SLI_INTF_IF_TYPE_1:
  9407. default:
  9408. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9409. "2886 HBA Error Attention on unsupported "
  9410. "if type %d.", if_type);
  9411. return 1;
  9412. }
  9413. return 0;
  9414. }
  9415. /**
  9416. * lpfc_sli_check_eratt - check error attention events
  9417. * @phba: Pointer to HBA context.
  9418. *
  9419. * This function is called from timer soft interrupt context to check HBA's
  9420. * error attention register bit for error attention events.
  9421. *
  9422. * This function returns 1 when there is Error Attention in the Host Attention
  9423. * Register and returns 0 otherwise.
  9424. **/
  9425. int
  9426. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9427. {
  9428. uint32_t ha_copy;
  9429. /* If somebody is waiting to handle an eratt, don't process it
  9430. * here. The brdkill function will do this.
  9431. */
  9432. if (phba->link_flag & LS_IGNORE_ERATT)
  9433. return 0;
  9434. /* Check if interrupt handler handles this ERATT */
  9435. spin_lock_irq(&phba->hbalock);
  9436. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9437. /* Interrupt handler has handled ERATT */
  9438. spin_unlock_irq(&phba->hbalock);
  9439. return 0;
  9440. }
  9441. /*
  9442. * If there is deferred error attention, do not check for error
  9443. * attention
  9444. */
  9445. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9446. spin_unlock_irq(&phba->hbalock);
  9447. return 0;
  9448. }
  9449. /* If PCI channel is offline, don't process it */
  9450. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9451. spin_unlock_irq(&phba->hbalock);
  9452. return 0;
  9453. }
  9454. switch (phba->sli_rev) {
  9455. case LPFC_SLI_REV2:
  9456. case LPFC_SLI_REV3:
  9457. /* Read chip Host Attention (HA) register */
  9458. ha_copy = lpfc_sli_eratt_read(phba);
  9459. break;
  9460. case LPFC_SLI_REV4:
  9461. /* Read device Uncoverable Error (UERR) registers */
  9462. ha_copy = lpfc_sli4_eratt_read(phba);
  9463. break;
  9464. default:
  9465. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9466. "0299 Invalid SLI revision (%d)\n",
  9467. phba->sli_rev);
  9468. ha_copy = 0;
  9469. break;
  9470. }
  9471. spin_unlock_irq(&phba->hbalock);
  9472. return ha_copy;
  9473. }
  9474. /**
  9475. * lpfc_intr_state_check - Check device state for interrupt handling
  9476. * @phba: Pointer to HBA context.
  9477. *
  9478. * This inline routine checks whether a device or its PCI slot is in a state
  9479. * that the interrupt should be handled.
  9480. *
  9481. * This function returns 0 if the device or the PCI slot is in a state that
  9482. * interrupt should be handled, otherwise -EIO.
  9483. */
  9484. static inline int
  9485. lpfc_intr_state_check(struct lpfc_hba *phba)
  9486. {
  9487. /* If the pci channel is offline, ignore all the interrupts */
  9488. if (unlikely(pci_channel_offline(phba->pcidev)))
  9489. return -EIO;
  9490. /* Update device level interrupt statistics */
  9491. phba->sli.slistat.sli_intr++;
  9492. /* Ignore all interrupts during initialization. */
  9493. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9494. return -EIO;
  9495. return 0;
  9496. }
  9497. /**
  9498. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9499. * @irq: Interrupt number.
  9500. * @dev_id: The device context pointer.
  9501. *
  9502. * This function is directly called from the PCI layer as an interrupt
  9503. * service routine when device with SLI-3 interface spec is enabled with
  9504. * MSI-X multi-message interrupt mode and there are slow-path events in
  9505. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9506. * interrupt mode, this function is called as part of the device-level
  9507. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9508. * is undergoing initialization, the interrupt handler will not process
  9509. * the interrupt. The link attention and ELS ring attention events are
  9510. * handled by the worker thread. The interrupt handler signals the worker
  9511. * thread and returns for these events. This function is called without
  9512. * any lock held. It gets the hbalock to access and update SLI data
  9513. * structures.
  9514. *
  9515. * This function returns IRQ_HANDLED when interrupt is handled else it
  9516. * returns IRQ_NONE.
  9517. **/
  9518. irqreturn_t
  9519. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9520. {
  9521. struct lpfc_hba *phba;
  9522. uint32_t ha_copy, hc_copy;
  9523. uint32_t work_ha_copy;
  9524. unsigned long status;
  9525. unsigned long iflag;
  9526. uint32_t control;
  9527. MAILBOX_t *mbox, *pmbox;
  9528. struct lpfc_vport *vport;
  9529. struct lpfc_nodelist *ndlp;
  9530. struct lpfc_dmabuf *mp;
  9531. LPFC_MBOXQ_t *pmb;
  9532. int rc;
  9533. /*
  9534. * Get the driver's phba structure from the dev_id and
  9535. * assume the HBA is not interrupting.
  9536. */
  9537. phba = (struct lpfc_hba *)dev_id;
  9538. if (unlikely(!phba))
  9539. return IRQ_NONE;
  9540. /*
  9541. * Stuff needs to be attented to when this function is invoked as an
  9542. * individual interrupt handler in MSI-X multi-message interrupt mode
  9543. */
  9544. if (phba->intr_type == MSIX) {
  9545. /* Check device state for handling interrupt */
  9546. if (lpfc_intr_state_check(phba))
  9547. return IRQ_NONE;
  9548. /* Need to read HA REG for slow-path events */
  9549. spin_lock_irqsave(&phba->hbalock, iflag);
  9550. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9551. goto unplug_error;
  9552. /* If somebody is waiting to handle an eratt don't process it
  9553. * here. The brdkill function will do this.
  9554. */
  9555. if (phba->link_flag & LS_IGNORE_ERATT)
  9556. ha_copy &= ~HA_ERATT;
  9557. /* Check the need for handling ERATT in interrupt handler */
  9558. if (ha_copy & HA_ERATT) {
  9559. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9560. /* ERATT polling has handled ERATT */
  9561. ha_copy &= ~HA_ERATT;
  9562. else
  9563. /* Indicate interrupt handler handles ERATT */
  9564. phba->hba_flag |= HBA_ERATT_HANDLED;
  9565. }
  9566. /*
  9567. * If there is deferred error attention, do not check for any
  9568. * interrupt.
  9569. */
  9570. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9571. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9572. return IRQ_NONE;
  9573. }
  9574. /* Clear up only attention source related to slow-path */
  9575. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9576. goto unplug_error;
  9577. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9578. HC_LAINT_ENA | HC_ERINT_ENA),
  9579. phba->HCregaddr);
  9580. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9581. phba->HAregaddr);
  9582. writel(hc_copy, phba->HCregaddr);
  9583. readl(phba->HAregaddr); /* flush */
  9584. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9585. } else
  9586. ha_copy = phba->ha_copy;
  9587. work_ha_copy = ha_copy & phba->work_ha_mask;
  9588. if (work_ha_copy) {
  9589. if (work_ha_copy & HA_LATT) {
  9590. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9591. /*
  9592. * Turn off Link Attention interrupts
  9593. * until CLEAR_LA done
  9594. */
  9595. spin_lock_irqsave(&phba->hbalock, iflag);
  9596. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9597. if (lpfc_readl(phba->HCregaddr, &control))
  9598. goto unplug_error;
  9599. control &= ~HC_LAINT_ENA;
  9600. writel(control, phba->HCregaddr);
  9601. readl(phba->HCregaddr); /* flush */
  9602. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9603. }
  9604. else
  9605. work_ha_copy &= ~HA_LATT;
  9606. }
  9607. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9608. /*
  9609. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9610. * the only slow ring.
  9611. */
  9612. status = (work_ha_copy &
  9613. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9614. status >>= (4*LPFC_ELS_RING);
  9615. if (status & HA_RXMASK) {
  9616. spin_lock_irqsave(&phba->hbalock, iflag);
  9617. if (lpfc_readl(phba->HCregaddr, &control))
  9618. goto unplug_error;
  9619. lpfc_debugfs_slow_ring_trc(phba,
  9620. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9621. control, status,
  9622. (uint32_t)phba->sli.slistat.sli_intr);
  9623. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9624. lpfc_debugfs_slow_ring_trc(phba,
  9625. "ISR Disable ring:"
  9626. "pwork:x%x hawork:x%x wait:x%x",
  9627. phba->work_ha, work_ha_copy,
  9628. (uint32_t)((unsigned long)
  9629. &phba->work_waitq));
  9630. control &=
  9631. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9632. writel(control, phba->HCregaddr);
  9633. readl(phba->HCregaddr); /* flush */
  9634. }
  9635. else {
  9636. lpfc_debugfs_slow_ring_trc(phba,
  9637. "ISR slow ring: pwork:"
  9638. "x%x hawork:x%x wait:x%x",
  9639. phba->work_ha, work_ha_copy,
  9640. (uint32_t)((unsigned long)
  9641. &phba->work_waitq));
  9642. }
  9643. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9644. }
  9645. }
  9646. spin_lock_irqsave(&phba->hbalock, iflag);
  9647. if (work_ha_copy & HA_ERATT) {
  9648. if (lpfc_sli_read_hs(phba))
  9649. goto unplug_error;
  9650. /*
  9651. * Check if there is a deferred error condition
  9652. * is active
  9653. */
  9654. if ((HS_FFER1 & phba->work_hs) &&
  9655. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9656. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9657. phba->work_hs)) {
  9658. phba->hba_flag |= DEFER_ERATT;
  9659. /* Clear all interrupt enable conditions */
  9660. writel(0, phba->HCregaddr);
  9661. readl(phba->HCregaddr);
  9662. }
  9663. }
  9664. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9665. pmb = phba->sli.mbox_active;
  9666. pmbox = &pmb->u.mb;
  9667. mbox = phba->mbox;
  9668. vport = pmb->vport;
  9669. /* First check out the status word */
  9670. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9671. if (pmbox->mbxOwner != OWN_HOST) {
  9672. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9673. /*
  9674. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9675. * mbxStatus <status>
  9676. */
  9677. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9678. LOG_SLI,
  9679. "(%d):0304 Stray Mailbox "
  9680. "Interrupt mbxCommand x%x "
  9681. "mbxStatus x%x\n",
  9682. (vport ? vport->vpi : 0),
  9683. pmbox->mbxCommand,
  9684. pmbox->mbxStatus);
  9685. /* clear mailbox attention bit */
  9686. work_ha_copy &= ~HA_MBATT;
  9687. } else {
  9688. phba->sli.mbox_active = NULL;
  9689. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9690. phba->last_completion_time = jiffies;
  9691. del_timer(&phba->sli.mbox_tmo);
  9692. if (pmb->mbox_cmpl) {
  9693. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9694. MAILBOX_CMD_SIZE);
  9695. if (pmb->out_ext_byte_len &&
  9696. pmb->context2)
  9697. lpfc_sli_pcimem_bcopy(
  9698. phba->mbox_ext,
  9699. pmb->context2,
  9700. pmb->out_ext_byte_len);
  9701. }
  9702. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9703. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9704. lpfc_debugfs_disc_trc(vport,
  9705. LPFC_DISC_TRC_MBOX_VPORT,
  9706. "MBOX dflt rpi: : "
  9707. "status:x%x rpi:x%x",
  9708. (uint32_t)pmbox->mbxStatus,
  9709. pmbox->un.varWords[0], 0);
  9710. if (!pmbox->mbxStatus) {
  9711. mp = (struct lpfc_dmabuf *)
  9712. (pmb->context1);
  9713. ndlp = (struct lpfc_nodelist *)
  9714. pmb->context2;
  9715. /* Reg_LOGIN of dflt RPI was
  9716. * successful. new lets get
  9717. * rid of the RPI using the
  9718. * same mbox buffer.
  9719. */
  9720. lpfc_unreg_login(phba,
  9721. vport->vpi,
  9722. pmbox->un.varWords[0],
  9723. pmb);
  9724. pmb->mbox_cmpl =
  9725. lpfc_mbx_cmpl_dflt_rpi;
  9726. pmb->context1 = mp;
  9727. pmb->context2 = ndlp;
  9728. pmb->vport = vport;
  9729. rc = lpfc_sli_issue_mbox(phba,
  9730. pmb,
  9731. MBX_NOWAIT);
  9732. if (rc != MBX_BUSY)
  9733. lpfc_printf_log(phba,
  9734. KERN_ERR,
  9735. LOG_MBOX | LOG_SLI,
  9736. "0350 rc should have"
  9737. "been MBX_BUSY\n");
  9738. if (rc != MBX_NOT_FINISHED)
  9739. goto send_current_mbox;
  9740. }
  9741. }
  9742. spin_lock_irqsave(
  9743. &phba->pport->work_port_lock,
  9744. iflag);
  9745. phba->pport->work_port_events &=
  9746. ~WORKER_MBOX_TMO;
  9747. spin_unlock_irqrestore(
  9748. &phba->pport->work_port_lock,
  9749. iflag);
  9750. lpfc_mbox_cmpl_put(phba, pmb);
  9751. }
  9752. } else
  9753. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9754. if ((work_ha_copy & HA_MBATT) &&
  9755. (phba->sli.mbox_active == NULL)) {
  9756. send_current_mbox:
  9757. /* Process next mailbox command if there is one */
  9758. do {
  9759. rc = lpfc_sli_issue_mbox(phba, NULL,
  9760. MBX_NOWAIT);
  9761. } while (rc == MBX_NOT_FINISHED);
  9762. if (rc != MBX_SUCCESS)
  9763. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9764. LOG_SLI, "0349 rc should be "
  9765. "MBX_SUCCESS\n");
  9766. }
  9767. spin_lock_irqsave(&phba->hbalock, iflag);
  9768. phba->work_ha |= work_ha_copy;
  9769. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9770. lpfc_worker_wake_up(phba);
  9771. }
  9772. return IRQ_HANDLED;
  9773. unplug_error:
  9774. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9775. return IRQ_HANDLED;
  9776. } /* lpfc_sli_sp_intr_handler */
  9777. /**
  9778. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9779. * @irq: Interrupt number.
  9780. * @dev_id: The device context pointer.
  9781. *
  9782. * This function is directly called from the PCI layer as an interrupt
  9783. * service routine when device with SLI-3 interface spec is enabled with
  9784. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9785. * ring event in the HBA. However, when the device is enabled with either
  9786. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9787. * device-level interrupt handler. When the PCI slot is in error recovery
  9788. * or the HBA is undergoing initialization, the interrupt handler will not
  9789. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9790. * the intrrupt context. This function is called without any lock held.
  9791. * It gets the hbalock to access and update SLI data structures.
  9792. *
  9793. * This function returns IRQ_HANDLED when interrupt is handled else it
  9794. * returns IRQ_NONE.
  9795. **/
  9796. irqreturn_t
  9797. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9798. {
  9799. struct lpfc_hba *phba;
  9800. uint32_t ha_copy;
  9801. unsigned long status;
  9802. unsigned long iflag;
  9803. /* Get the driver's phba structure from the dev_id and
  9804. * assume the HBA is not interrupting.
  9805. */
  9806. phba = (struct lpfc_hba *) dev_id;
  9807. if (unlikely(!phba))
  9808. return IRQ_NONE;
  9809. /*
  9810. * Stuff needs to be attented to when this function is invoked as an
  9811. * individual interrupt handler in MSI-X multi-message interrupt mode
  9812. */
  9813. if (phba->intr_type == MSIX) {
  9814. /* Check device state for handling interrupt */
  9815. if (lpfc_intr_state_check(phba))
  9816. return IRQ_NONE;
  9817. /* Need to read HA REG for FCP ring and other ring events */
  9818. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9819. return IRQ_HANDLED;
  9820. /* Clear up only attention source related to fast-path */
  9821. spin_lock_irqsave(&phba->hbalock, iflag);
  9822. /*
  9823. * If there is deferred error attention, do not check for
  9824. * any interrupt.
  9825. */
  9826. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9827. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9828. return IRQ_NONE;
  9829. }
  9830. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9831. phba->HAregaddr);
  9832. readl(phba->HAregaddr); /* flush */
  9833. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9834. } else
  9835. ha_copy = phba->ha_copy;
  9836. /*
  9837. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9838. */
  9839. ha_copy &= ~(phba->work_ha_mask);
  9840. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9841. status >>= (4*LPFC_FCP_RING);
  9842. if (status & HA_RXMASK)
  9843. lpfc_sli_handle_fast_ring_event(phba,
  9844. &phba->sli.ring[LPFC_FCP_RING],
  9845. status);
  9846. if (phba->cfg_multi_ring_support == 2) {
  9847. /*
  9848. * Process all events on extra ring. Take the optimized path
  9849. * for extra ring IO.
  9850. */
  9851. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9852. status >>= (4*LPFC_EXTRA_RING);
  9853. if (status & HA_RXMASK) {
  9854. lpfc_sli_handle_fast_ring_event(phba,
  9855. &phba->sli.ring[LPFC_EXTRA_RING],
  9856. status);
  9857. }
  9858. }
  9859. return IRQ_HANDLED;
  9860. } /* lpfc_sli_fp_intr_handler */
  9861. /**
  9862. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9863. * @irq: Interrupt number.
  9864. * @dev_id: The device context pointer.
  9865. *
  9866. * This function is the HBA device-level interrupt handler to device with
  9867. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9868. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9869. * requires driver attention. This function invokes the slow-path interrupt
  9870. * attention handling function and fast-path interrupt attention handling
  9871. * function in turn to process the relevant HBA attention events. This
  9872. * function is called without any lock held. It gets the hbalock to access
  9873. * and update SLI data structures.
  9874. *
  9875. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9876. * returns IRQ_NONE.
  9877. **/
  9878. irqreturn_t
  9879. lpfc_sli_intr_handler(int irq, void *dev_id)
  9880. {
  9881. struct lpfc_hba *phba;
  9882. irqreturn_t sp_irq_rc, fp_irq_rc;
  9883. unsigned long status1, status2;
  9884. uint32_t hc_copy;
  9885. /*
  9886. * Get the driver's phba structure from the dev_id and
  9887. * assume the HBA is not interrupting.
  9888. */
  9889. phba = (struct lpfc_hba *) dev_id;
  9890. if (unlikely(!phba))
  9891. return IRQ_NONE;
  9892. /* Check device state for handling interrupt */
  9893. if (lpfc_intr_state_check(phba))
  9894. return IRQ_NONE;
  9895. spin_lock(&phba->hbalock);
  9896. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9897. spin_unlock(&phba->hbalock);
  9898. return IRQ_HANDLED;
  9899. }
  9900. if (unlikely(!phba->ha_copy)) {
  9901. spin_unlock(&phba->hbalock);
  9902. return IRQ_NONE;
  9903. } else if (phba->ha_copy & HA_ERATT) {
  9904. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9905. /* ERATT polling has handled ERATT */
  9906. phba->ha_copy &= ~HA_ERATT;
  9907. else
  9908. /* Indicate interrupt handler handles ERATT */
  9909. phba->hba_flag |= HBA_ERATT_HANDLED;
  9910. }
  9911. /*
  9912. * If there is deferred error attention, do not check for any interrupt.
  9913. */
  9914. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9915. spin_unlock(&phba->hbalock);
  9916. return IRQ_NONE;
  9917. }
  9918. /* Clear attention sources except link and error attentions */
  9919. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9920. spin_unlock(&phba->hbalock);
  9921. return IRQ_HANDLED;
  9922. }
  9923. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9924. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9925. phba->HCregaddr);
  9926. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9927. writel(hc_copy, phba->HCregaddr);
  9928. readl(phba->HAregaddr); /* flush */
  9929. spin_unlock(&phba->hbalock);
  9930. /*
  9931. * Invokes slow-path host attention interrupt handling as appropriate.
  9932. */
  9933. /* status of events with mailbox and link attention */
  9934. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9935. /* status of events with ELS ring */
  9936. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9937. status2 >>= (4*LPFC_ELS_RING);
  9938. if (status1 || (status2 & HA_RXMASK))
  9939. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9940. else
  9941. sp_irq_rc = IRQ_NONE;
  9942. /*
  9943. * Invoke fast-path host attention interrupt handling as appropriate.
  9944. */
  9945. /* status of events with FCP ring */
  9946. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9947. status1 >>= (4*LPFC_FCP_RING);
  9948. /* status of events with extra ring */
  9949. if (phba->cfg_multi_ring_support == 2) {
  9950. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9951. status2 >>= (4*LPFC_EXTRA_RING);
  9952. } else
  9953. status2 = 0;
  9954. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9955. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9956. else
  9957. fp_irq_rc = IRQ_NONE;
  9958. /* Return device-level interrupt handling status */
  9959. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9960. } /* lpfc_sli_intr_handler */
  9961. /**
  9962. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9963. * @phba: pointer to lpfc hba data structure.
  9964. *
  9965. * This routine is invoked by the worker thread to process all the pending
  9966. * SLI4 FCP abort XRI events.
  9967. **/
  9968. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9969. {
  9970. struct lpfc_cq_event *cq_event;
  9971. /* First, declare the fcp xri abort event has been handled */
  9972. spin_lock_irq(&phba->hbalock);
  9973. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9974. spin_unlock_irq(&phba->hbalock);
  9975. /* Now, handle all the fcp xri abort events */
  9976. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9977. /* Get the first event from the head of the event queue */
  9978. spin_lock_irq(&phba->hbalock);
  9979. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9980. cq_event, struct lpfc_cq_event, list);
  9981. spin_unlock_irq(&phba->hbalock);
  9982. /* Notify aborted XRI for FCP work queue */
  9983. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9984. /* Free the event processed back to the free pool */
  9985. lpfc_sli4_cq_event_release(phba, cq_event);
  9986. }
  9987. }
  9988. /**
  9989. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9990. * @phba: pointer to lpfc hba data structure.
  9991. *
  9992. * This routine is invoked by the worker thread to process all the pending
  9993. * SLI4 els abort xri events.
  9994. **/
  9995. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  9996. {
  9997. struct lpfc_cq_event *cq_event;
  9998. /* First, declare the els xri abort event has been handled */
  9999. spin_lock_irq(&phba->hbalock);
  10000. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  10001. spin_unlock_irq(&phba->hbalock);
  10002. /* Now, handle all the els xri abort events */
  10003. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  10004. /* Get the first event from the head of the event queue */
  10005. spin_lock_irq(&phba->hbalock);
  10006. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  10007. cq_event, struct lpfc_cq_event, list);
  10008. spin_unlock_irq(&phba->hbalock);
  10009. /* Notify aborted XRI for ELS work queue */
  10010. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  10011. /* Free the event processed back to the free pool */
  10012. lpfc_sli4_cq_event_release(phba, cq_event);
  10013. }
  10014. }
  10015. /**
  10016. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  10017. * @phba: pointer to lpfc hba data structure
  10018. * @pIocbIn: pointer to the rspiocbq
  10019. * @pIocbOut: pointer to the cmdiocbq
  10020. * @wcqe: pointer to the complete wcqe
  10021. *
  10022. * This routine transfers the fields of a command iocbq to a response iocbq
  10023. * by copying all the IOCB fields from command iocbq and transferring the
  10024. * completion status information from the complete wcqe.
  10025. **/
  10026. static void
  10027. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  10028. struct lpfc_iocbq *pIocbIn,
  10029. struct lpfc_iocbq *pIocbOut,
  10030. struct lpfc_wcqe_complete *wcqe)
  10031. {
  10032. unsigned long iflags;
  10033. uint32_t status;
  10034. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  10035. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  10036. sizeof(struct lpfc_iocbq) - offset);
  10037. /* Map WCQE parameters into irspiocb parameters */
  10038. status = bf_get(lpfc_wcqe_c_status, wcqe);
  10039. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  10040. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  10041. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  10042. pIocbIn->iocb.un.fcpi.fcpi_parm =
  10043. pIocbOut->iocb.un.fcpi.fcpi_parm -
  10044. wcqe->total_data_placed;
  10045. else
  10046. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10047. else {
  10048. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  10049. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  10050. }
  10051. /* Convert BG errors for completion status */
  10052. if (status == CQE_STATUS_DI_ERROR) {
  10053. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  10054. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  10055. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  10056. else
  10057. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  10058. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  10059. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  10060. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10061. BGS_GUARD_ERR_MASK;
  10062. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  10063. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10064. BGS_APPTAG_ERR_MASK;
  10065. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  10066. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10067. BGS_REFTAG_ERR_MASK;
  10068. /* Check to see if there was any good data before the error */
  10069. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  10070. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10071. BGS_HI_WATER_MARK_PRESENT_MASK;
  10072. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  10073. wcqe->total_data_placed;
  10074. }
  10075. /*
  10076. * Set ALL the error bits to indicate we don't know what
  10077. * type of error it is.
  10078. */
  10079. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  10080. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  10081. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  10082. BGS_GUARD_ERR_MASK);
  10083. }
  10084. /* Pick up HBA exchange busy condition */
  10085. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  10086. spin_lock_irqsave(&phba->hbalock, iflags);
  10087. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  10088. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10089. }
  10090. }
  10091. /**
  10092. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  10093. * @phba: Pointer to HBA context object.
  10094. * @wcqe: Pointer to work-queue completion queue entry.
  10095. *
  10096. * This routine handles an ELS work-queue completion event and construct
  10097. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  10098. * discovery engine to handle.
  10099. *
  10100. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  10101. **/
  10102. static struct lpfc_iocbq *
  10103. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  10104. struct lpfc_iocbq *irspiocbq)
  10105. {
  10106. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  10107. struct lpfc_iocbq *cmdiocbq;
  10108. struct lpfc_wcqe_complete *wcqe;
  10109. unsigned long iflags;
  10110. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  10111. spin_lock_irqsave(&pring->ring_lock, iflags);
  10112. pring->stats.iocb_event++;
  10113. /* Look up the ELS command IOCB and create pseudo response IOCB */
  10114. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10115. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10116. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10117. if (unlikely(!cmdiocbq)) {
  10118. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10119. "0386 ELS complete with no corresponding "
  10120. "cmdiocb: iotag (%d)\n",
  10121. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10122. lpfc_sli_release_iocbq(phba, irspiocbq);
  10123. return NULL;
  10124. }
  10125. /* Fake the irspiocbq and copy necessary response information */
  10126. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  10127. return irspiocbq;
  10128. }
  10129. /**
  10130. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  10131. * @phba: Pointer to HBA context object.
  10132. * @cqe: Pointer to mailbox completion queue entry.
  10133. *
  10134. * This routine process a mailbox completion queue entry with asynchrous
  10135. * event.
  10136. *
  10137. * Return: true if work posted to worker thread, otherwise false.
  10138. **/
  10139. static bool
  10140. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10141. {
  10142. struct lpfc_cq_event *cq_event;
  10143. unsigned long iflags;
  10144. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10145. "0392 Async Event: word0:x%x, word1:x%x, "
  10146. "word2:x%x, word3:x%x\n", mcqe->word0,
  10147. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10148. /* Allocate a new internal CQ_EVENT entry */
  10149. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10150. if (!cq_event) {
  10151. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10152. "0394 Failed to allocate CQ_EVENT entry\n");
  10153. return false;
  10154. }
  10155. /* Move the CQE into an asynchronous event entry */
  10156. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10157. spin_lock_irqsave(&phba->hbalock, iflags);
  10158. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10159. /* Set the async event flag */
  10160. phba->hba_flag |= ASYNC_EVENT;
  10161. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10162. return true;
  10163. }
  10164. /**
  10165. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10166. * @phba: Pointer to HBA context object.
  10167. * @cqe: Pointer to mailbox completion queue entry.
  10168. *
  10169. * This routine process a mailbox completion queue entry with mailbox
  10170. * completion event.
  10171. *
  10172. * Return: true if work posted to worker thread, otherwise false.
  10173. **/
  10174. static bool
  10175. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10176. {
  10177. uint32_t mcqe_status;
  10178. MAILBOX_t *mbox, *pmbox;
  10179. struct lpfc_mqe *mqe;
  10180. struct lpfc_vport *vport;
  10181. struct lpfc_nodelist *ndlp;
  10182. struct lpfc_dmabuf *mp;
  10183. unsigned long iflags;
  10184. LPFC_MBOXQ_t *pmb;
  10185. bool workposted = false;
  10186. int rc;
  10187. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10188. if (!bf_get(lpfc_trailer_completed, mcqe))
  10189. goto out_no_mqe_complete;
  10190. /* Get the reference to the active mbox command */
  10191. spin_lock_irqsave(&phba->hbalock, iflags);
  10192. pmb = phba->sli.mbox_active;
  10193. if (unlikely(!pmb)) {
  10194. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10195. "1832 No pending MBOX command to handle\n");
  10196. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10197. goto out_no_mqe_complete;
  10198. }
  10199. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10200. mqe = &pmb->u.mqe;
  10201. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10202. mbox = phba->mbox;
  10203. vport = pmb->vport;
  10204. /* Reset heartbeat timer */
  10205. phba->last_completion_time = jiffies;
  10206. del_timer(&phba->sli.mbox_tmo);
  10207. /* Move mbox data to caller's mailbox region, do endian swapping */
  10208. if (pmb->mbox_cmpl && mbox)
  10209. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10210. /*
  10211. * For mcqe errors, conditionally move a modified error code to
  10212. * the mbox so that the error will not be missed.
  10213. */
  10214. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10215. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10216. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10217. bf_set(lpfc_mqe_status, mqe,
  10218. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10219. }
  10220. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10221. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10222. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10223. "MBOX dflt rpi: status:x%x rpi:x%x",
  10224. mcqe_status,
  10225. pmbox->un.varWords[0], 0);
  10226. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10227. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10228. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10229. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10230. * RID of the PPI using the same mbox buffer.
  10231. */
  10232. lpfc_unreg_login(phba, vport->vpi,
  10233. pmbox->un.varWords[0], pmb);
  10234. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10235. pmb->context1 = mp;
  10236. pmb->context2 = ndlp;
  10237. pmb->vport = vport;
  10238. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10239. if (rc != MBX_BUSY)
  10240. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10241. LOG_SLI, "0385 rc should "
  10242. "have been MBX_BUSY\n");
  10243. if (rc != MBX_NOT_FINISHED)
  10244. goto send_current_mbox;
  10245. }
  10246. }
  10247. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10248. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10249. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10250. /* There is mailbox completion work to do */
  10251. spin_lock_irqsave(&phba->hbalock, iflags);
  10252. __lpfc_mbox_cmpl_put(phba, pmb);
  10253. phba->work_ha |= HA_MBATT;
  10254. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10255. workposted = true;
  10256. send_current_mbox:
  10257. spin_lock_irqsave(&phba->hbalock, iflags);
  10258. /* Release the mailbox command posting token */
  10259. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10260. /* Setting active mailbox pointer need to be in sync to flag clear */
  10261. phba->sli.mbox_active = NULL;
  10262. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10263. /* Wake up worker thread to post the next pending mailbox command */
  10264. lpfc_worker_wake_up(phba);
  10265. out_no_mqe_complete:
  10266. if (bf_get(lpfc_trailer_consumed, mcqe))
  10267. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10268. return workposted;
  10269. }
  10270. /**
  10271. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10272. * @phba: Pointer to HBA context object.
  10273. * @cqe: Pointer to mailbox completion queue entry.
  10274. *
  10275. * This routine process a mailbox completion queue entry, it invokes the
  10276. * proper mailbox complete handling or asynchrous event handling routine
  10277. * according to the MCQE's async bit.
  10278. *
  10279. * Return: true if work posted to worker thread, otherwise false.
  10280. **/
  10281. static bool
  10282. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10283. {
  10284. struct lpfc_mcqe mcqe;
  10285. bool workposted;
  10286. /* Copy the mailbox MCQE and convert endian order as needed */
  10287. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10288. /* Invoke the proper event handling routine */
  10289. if (!bf_get(lpfc_trailer_async, &mcqe))
  10290. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10291. else
  10292. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10293. return workposted;
  10294. }
  10295. /**
  10296. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10297. * @phba: Pointer to HBA context object.
  10298. * @cq: Pointer to associated CQ
  10299. * @wcqe: Pointer to work-queue completion queue entry.
  10300. *
  10301. * This routine handles an ELS work-queue completion event.
  10302. *
  10303. * Return: true if work posted to worker thread, otherwise false.
  10304. **/
  10305. static bool
  10306. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10307. struct lpfc_wcqe_complete *wcqe)
  10308. {
  10309. struct lpfc_iocbq *irspiocbq;
  10310. unsigned long iflags;
  10311. struct lpfc_sli_ring *pring = cq->pring;
  10312. int txq_cnt = 0;
  10313. int txcmplq_cnt = 0;
  10314. int fcp_txcmplq_cnt = 0;
  10315. /* Get an irspiocbq for later ELS response processing use */
  10316. irspiocbq = lpfc_sli_get_iocbq(phba);
  10317. if (!irspiocbq) {
  10318. if (!list_empty(&pring->txq))
  10319. txq_cnt++;
  10320. if (!list_empty(&pring->txcmplq))
  10321. txcmplq_cnt++;
  10322. if (!list_empty(&phba->sli.ring[LPFC_FCP_RING].txcmplq))
  10323. fcp_txcmplq_cnt++;
  10324. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10325. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10326. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10327. txq_cnt, phba->iocb_cnt,
  10328. fcp_txcmplq_cnt,
  10329. txcmplq_cnt);
  10330. return false;
  10331. }
  10332. /* Save off the slow-path queue event for work thread to process */
  10333. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10334. spin_lock_irqsave(&phba->hbalock, iflags);
  10335. list_add_tail(&irspiocbq->cq_event.list,
  10336. &phba->sli4_hba.sp_queue_event);
  10337. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10338. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10339. return true;
  10340. }
  10341. /**
  10342. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10343. * @phba: Pointer to HBA context object.
  10344. * @wcqe: Pointer to work-queue completion queue entry.
  10345. *
  10346. * This routine handles slow-path WQ entry comsumed event by invoking the
  10347. * proper WQ release routine to the slow-path WQ.
  10348. **/
  10349. static void
  10350. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10351. struct lpfc_wcqe_release *wcqe)
  10352. {
  10353. /* sanity check on queue memory */
  10354. if (unlikely(!phba->sli4_hba.els_wq))
  10355. return;
  10356. /* Check for the slow-path ELS work queue */
  10357. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10358. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10359. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10360. else
  10361. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10362. "2579 Slow-path wqe consume event carries "
  10363. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10364. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10365. phba->sli4_hba.els_wq->queue_id);
  10366. }
  10367. /**
  10368. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10369. * @phba: Pointer to HBA context object.
  10370. * @cq: Pointer to a WQ completion queue.
  10371. * @wcqe: Pointer to work-queue completion queue entry.
  10372. *
  10373. * This routine handles an XRI abort event.
  10374. *
  10375. * Return: true if work posted to worker thread, otherwise false.
  10376. **/
  10377. static bool
  10378. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10379. struct lpfc_queue *cq,
  10380. struct sli4_wcqe_xri_aborted *wcqe)
  10381. {
  10382. bool workposted = false;
  10383. struct lpfc_cq_event *cq_event;
  10384. unsigned long iflags;
  10385. /* Allocate a new internal CQ_EVENT entry */
  10386. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10387. if (!cq_event) {
  10388. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10389. "0602 Failed to allocate CQ_EVENT entry\n");
  10390. return false;
  10391. }
  10392. /* Move the CQE into the proper xri abort event list */
  10393. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10394. switch (cq->subtype) {
  10395. case LPFC_FCP:
  10396. spin_lock_irqsave(&phba->hbalock, iflags);
  10397. list_add_tail(&cq_event->list,
  10398. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10399. /* Set the fcp xri abort event flag */
  10400. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10401. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10402. workposted = true;
  10403. break;
  10404. case LPFC_ELS:
  10405. spin_lock_irqsave(&phba->hbalock, iflags);
  10406. list_add_tail(&cq_event->list,
  10407. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10408. /* Set the els xri abort event flag */
  10409. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10410. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10411. workposted = true;
  10412. break;
  10413. default:
  10414. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10415. "0603 Invalid work queue CQE subtype (x%x)\n",
  10416. cq->subtype);
  10417. workposted = false;
  10418. break;
  10419. }
  10420. return workposted;
  10421. }
  10422. /**
  10423. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10424. * @phba: Pointer to HBA context object.
  10425. * @rcqe: Pointer to receive-queue completion queue entry.
  10426. *
  10427. * This routine process a receive-queue completion queue entry.
  10428. *
  10429. * Return: true if work posted to worker thread, otherwise false.
  10430. **/
  10431. static bool
  10432. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10433. {
  10434. bool workposted = false;
  10435. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10436. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10437. struct hbq_dmabuf *dma_buf;
  10438. uint32_t status, rq_id;
  10439. unsigned long iflags;
  10440. /* sanity check on queue memory */
  10441. if (unlikely(!hrq) || unlikely(!drq))
  10442. return workposted;
  10443. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10444. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10445. else
  10446. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10447. if (rq_id != hrq->queue_id)
  10448. goto out;
  10449. status = bf_get(lpfc_rcqe_status, rcqe);
  10450. switch (status) {
  10451. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10452. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10453. "2537 Receive Frame Truncated!!\n");
  10454. hrq->RQ_buf_trunc++;
  10455. case FC_STATUS_RQ_SUCCESS:
  10456. lpfc_sli4_rq_release(hrq, drq);
  10457. spin_lock_irqsave(&phba->hbalock, iflags);
  10458. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10459. if (!dma_buf) {
  10460. hrq->RQ_no_buf_found++;
  10461. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10462. goto out;
  10463. }
  10464. hrq->RQ_rcv_buf++;
  10465. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10466. /* save off the frame for the word thread to process */
  10467. list_add_tail(&dma_buf->cq_event.list,
  10468. &phba->sli4_hba.sp_queue_event);
  10469. /* Frame received */
  10470. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10471. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10472. workposted = true;
  10473. break;
  10474. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10475. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10476. hrq->RQ_no_posted_buf++;
  10477. /* Post more buffers if possible */
  10478. spin_lock_irqsave(&phba->hbalock, iflags);
  10479. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10480. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10481. workposted = true;
  10482. break;
  10483. }
  10484. out:
  10485. return workposted;
  10486. }
  10487. /**
  10488. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10489. * @phba: Pointer to HBA context object.
  10490. * @cq: Pointer to the completion queue.
  10491. * @wcqe: Pointer to a completion queue entry.
  10492. *
  10493. * This routine process a slow-path work-queue or receive queue completion queue
  10494. * entry.
  10495. *
  10496. * Return: true if work posted to worker thread, otherwise false.
  10497. **/
  10498. static bool
  10499. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10500. struct lpfc_cqe *cqe)
  10501. {
  10502. struct lpfc_cqe cqevt;
  10503. bool workposted = false;
  10504. /* Copy the work queue CQE and convert endian order if needed */
  10505. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10506. /* Check and process for different type of WCQE and dispatch */
  10507. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10508. case CQE_CODE_COMPL_WQE:
  10509. /* Process the WQ/RQ complete event */
  10510. phba->last_completion_time = jiffies;
  10511. workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
  10512. (struct lpfc_wcqe_complete *)&cqevt);
  10513. break;
  10514. case CQE_CODE_RELEASE_WQE:
  10515. /* Process the WQ release event */
  10516. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10517. (struct lpfc_wcqe_release *)&cqevt);
  10518. break;
  10519. case CQE_CODE_XRI_ABORTED:
  10520. /* Process the WQ XRI abort event */
  10521. phba->last_completion_time = jiffies;
  10522. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10523. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10524. break;
  10525. case CQE_CODE_RECEIVE:
  10526. case CQE_CODE_RECEIVE_V1:
  10527. /* Process the RQ event */
  10528. phba->last_completion_time = jiffies;
  10529. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10530. (struct lpfc_rcqe *)&cqevt);
  10531. break;
  10532. default:
  10533. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10534. "0388 Not a valid WCQE code: x%x\n",
  10535. bf_get(lpfc_cqe_code, &cqevt));
  10536. break;
  10537. }
  10538. return workposted;
  10539. }
  10540. /**
  10541. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10542. * @phba: Pointer to HBA context object.
  10543. * @eqe: Pointer to fast-path event queue entry.
  10544. *
  10545. * This routine process a event queue entry from the slow-path event queue.
  10546. * It will check the MajorCode and MinorCode to determine this is for a
  10547. * completion event on a completion queue, if not, an error shall be logged
  10548. * and just return. Otherwise, it will get to the corresponding completion
  10549. * queue and process all the entries on that completion queue, rearm the
  10550. * completion queue, and then return.
  10551. *
  10552. **/
  10553. static void
  10554. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10555. struct lpfc_queue *speq)
  10556. {
  10557. struct lpfc_queue *cq = NULL, *childq;
  10558. struct lpfc_cqe *cqe;
  10559. bool workposted = false;
  10560. int ecount = 0;
  10561. uint16_t cqid;
  10562. /* Get the reference to the corresponding CQ */
  10563. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10564. list_for_each_entry(childq, &speq->child_list, list) {
  10565. if (childq->queue_id == cqid) {
  10566. cq = childq;
  10567. break;
  10568. }
  10569. }
  10570. if (unlikely(!cq)) {
  10571. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10572. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10573. "0365 Slow-path CQ identifier "
  10574. "(%d) does not exist\n", cqid);
  10575. return;
  10576. }
  10577. /* Process all the entries to the CQ */
  10578. switch (cq->type) {
  10579. case LPFC_MCQ:
  10580. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10581. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10582. if (!(++ecount % cq->entry_repost))
  10583. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10584. cq->CQ_mbox++;
  10585. }
  10586. break;
  10587. case LPFC_WCQ:
  10588. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10589. if (cq->subtype == LPFC_FCP)
  10590. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10591. cqe);
  10592. else
  10593. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10594. cqe);
  10595. if (!(++ecount % cq->entry_repost))
  10596. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10597. }
  10598. /* Track the max number of CQEs processed in 1 EQ */
  10599. if (ecount > cq->CQ_max_cqe)
  10600. cq->CQ_max_cqe = ecount;
  10601. break;
  10602. default:
  10603. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10604. "0370 Invalid completion queue type (%d)\n",
  10605. cq->type);
  10606. return;
  10607. }
  10608. /* Catch the no cq entry condition, log an error */
  10609. if (unlikely(ecount == 0))
  10610. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10611. "0371 No entry from the CQ: identifier "
  10612. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10613. /* In any case, flash and re-arm the RCQ */
  10614. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10615. /* wake up worker thread if there are works to be done */
  10616. if (workposted)
  10617. lpfc_worker_wake_up(phba);
  10618. }
  10619. /**
  10620. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10621. * @phba: Pointer to HBA context object.
  10622. * @cq: Pointer to associated CQ
  10623. * @wcqe: Pointer to work-queue completion queue entry.
  10624. *
  10625. * This routine process a fast-path work queue completion entry from fast-path
  10626. * event queue for FCP command response completion.
  10627. **/
  10628. static void
  10629. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10630. struct lpfc_wcqe_complete *wcqe)
  10631. {
  10632. struct lpfc_sli_ring *pring = cq->pring;
  10633. struct lpfc_iocbq *cmdiocbq;
  10634. struct lpfc_iocbq irspiocbq;
  10635. unsigned long iflags;
  10636. /* Check for response status */
  10637. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10638. /* If resource errors reported from HBA, reduce queue
  10639. * depth of the SCSI device.
  10640. */
  10641. if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10642. IOSTAT_LOCAL_REJECT)) &&
  10643. ((wcqe->parameter & IOERR_PARAM_MASK) ==
  10644. IOERR_NO_RESOURCES))
  10645. phba->lpfc_rampdown_queue_depth(phba);
  10646. /* Log the error status */
  10647. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10648. "0373 FCP complete error: status=x%x, "
  10649. "hw_status=x%x, total_data_specified=%d, "
  10650. "parameter=x%x, word3=x%x\n",
  10651. bf_get(lpfc_wcqe_c_status, wcqe),
  10652. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10653. wcqe->total_data_placed, wcqe->parameter,
  10654. wcqe->word3);
  10655. }
  10656. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10657. spin_lock_irqsave(&pring->ring_lock, iflags);
  10658. pring->stats.iocb_event++;
  10659. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10660. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10661. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10662. if (unlikely(!cmdiocbq)) {
  10663. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10664. "0374 FCP complete with no corresponding "
  10665. "cmdiocb: iotag (%d)\n",
  10666. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10667. return;
  10668. }
  10669. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10670. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10671. "0375 FCP cmdiocb not callback function "
  10672. "iotag: (%d)\n",
  10673. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10674. return;
  10675. }
  10676. /* Fake the irspiocb and copy necessary response information */
  10677. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10678. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10679. spin_lock_irqsave(&phba->hbalock, iflags);
  10680. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10681. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10682. }
  10683. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10684. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10685. }
  10686. /**
  10687. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10688. * @phba: Pointer to HBA context object.
  10689. * @cq: Pointer to completion queue.
  10690. * @wcqe: Pointer to work-queue completion queue entry.
  10691. *
  10692. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10693. * proper WQ release routine to the slow-path WQ.
  10694. **/
  10695. static void
  10696. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10697. struct lpfc_wcqe_release *wcqe)
  10698. {
  10699. struct lpfc_queue *childwq;
  10700. bool wqid_matched = false;
  10701. uint16_t fcp_wqid;
  10702. /* Check for fast-path FCP work queue release */
  10703. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10704. list_for_each_entry(childwq, &cq->child_list, list) {
  10705. if (childwq->queue_id == fcp_wqid) {
  10706. lpfc_sli4_wq_release(childwq,
  10707. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10708. wqid_matched = true;
  10709. break;
  10710. }
  10711. }
  10712. /* Report warning log message if no match found */
  10713. if (wqid_matched != true)
  10714. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10715. "2580 Fast-path wqe consume event carries "
  10716. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10717. }
  10718. /**
  10719. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10720. * @cq: Pointer to the completion queue.
  10721. * @eqe: Pointer to fast-path completion queue entry.
  10722. *
  10723. * This routine process a fast-path work queue completion entry from fast-path
  10724. * event queue for FCP command response completion.
  10725. **/
  10726. static int
  10727. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10728. struct lpfc_cqe *cqe)
  10729. {
  10730. struct lpfc_wcqe_release wcqe;
  10731. bool workposted = false;
  10732. /* Copy the work queue CQE and convert endian order if needed */
  10733. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10734. /* Check and process for different type of WCQE and dispatch */
  10735. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10736. case CQE_CODE_COMPL_WQE:
  10737. cq->CQ_wq++;
  10738. /* Process the WQ complete event */
  10739. phba->last_completion_time = jiffies;
  10740. lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
  10741. (struct lpfc_wcqe_complete *)&wcqe);
  10742. break;
  10743. case CQE_CODE_RELEASE_WQE:
  10744. cq->CQ_release_wqe++;
  10745. /* Process the WQ release event */
  10746. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10747. (struct lpfc_wcqe_release *)&wcqe);
  10748. break;
  10749. case CQE_CODE_XRI_ABORTED:
  10750. cq->CQ_xri_aborted++;
  10751. /* Process the WQ XRI abort event */
  10752. phba->last_completion_time = jiffies;
  10753. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10754. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10755. break;
  10756. default:
  10757. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10758. "0144 Not a valid WCQE code: x%x\n",
  10759. bf_get(lpfc_wcqe_c_code, &wcqe));
  10760. break;
  10761. }
  10762. return workposted;
  10763. }
  10764. /**
  10765. * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
  10766. * @phba: Pointer to HBA context object.
  10767. * @eqe: Pointer to fast-path event queue entry.
  10768. *
  10769. * This routine process a event queue entry from the fast-path event queue.
  10770. * It will check the MajorCode and MinorCode to determine this is for a
  10771. * completion event on a completion queue, if not, an error shall be logged
  10772. * and just return. Otherwise, it will get to the corresponding completion
  10773. * queue and process all the entries on the completion queue, rearm the
  10774. * completion queue, and then return.
  10775. **/
  10776. static void
  10777. lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10778. uint32_t qidx)
  10779. {
  10780. struct lpfc_queue *cq;
  10781. struct lpfc_cqe *cqe;
  10782. bool workposted = false;
  10783. uint16_t cqid;
  10784. int ecount = 0;
  10785. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10786. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10787. "0366 Not a valid completion "
  10788. "event: majorcode=x%x, minorcode=x%x\n",
  10789. bf_get_le32(lpfc_eqe_major_code, eqe),
  10790. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10791. return;
  10792. }
  10793. /* Get the reference to the corresponding CQ */
  10794. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10795. /* Check if this is a Slow path event */
  10796. if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) {
  10797. lpfc_sli4_sp_handle_eqe(phba, eqe,
  10798. phba->sli4_hba.hba_eq[qidx]);
  10799. return;
  10800. }
  10801. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  10802. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10803. "3146 Fast-path completion queues "
  10804. "does not exist\n");
  10805. return;
  10806. }
  10807. cq = phba->sli4_hba.fcp_cq[qidx];
  10808. if (unlikely(!cq)) {
  10809. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10810. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10811. "0367 Fast-path completion queue "
  10812. "(%d) does not exist\n", qidx);
  10813. return;
  10814. }
  10815. if (unlikely(cqid != cq->queue_id)) {
  10816. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10817. "0368 Miss-matched fast-path completion "
  10818. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10819. cqid, cq->queue_id);
  10820. return;
  10821. }
  10822. /* Process all the entries to the CQ */
  10823. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10824. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10825. if (!(++ecount % cq->entry_repost))
  10826. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10827. }
  10828. /* Track the max number of CQEs processed in 1 EQ */
  10829. if (ecount > cq->CQ_max_cqe)
  10830. cq->CQ_max_cqe = ecount;
  10831. /* Catch the no cq entry condition */
  10832. if (unlikely(ecount == 0))
  10833. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10834. "0369 No entry from fast-path completion "
  10835. "queue fcpcqid=%d\n", cq->queue_id);
  10836. /* In any case, flash and re-arm the CQ */
  10837. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10838. /* wake up worker thread if there are works to be done */
  10839. if (workposted)
  10840. lpfc_worker_wake_up(phba);
  10841. }
  10842. static void
  10843. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10844. {
  10845. struct lpfc_eqe *eqe;
  10846. /* walk all the EQ entries and drop on the floor */
  10847. while ((eqe = lpfc_sli4_eq_get(eq)))
  10848. ;
  10849. /* Clear and re-arm the EQ */
  10850. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10851. }
  10852. /**
  10853. * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
  10854. * @irq: Interrupt number.
  10855. * @dev_id: The device context pointer.
  10856. *
  10857. * This function is directly called from the PCI layer as an interrupt
  10858. * service routine when device with SLI-4 interface spec is enabled with
  10859. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10860. * ring event in the HBA. However, when the device is enabled with either
  10861. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10862. * device-level interrupt handler. When the PCI slot is in error recovery
  10863. * or the HBA is undergoing initialization, the interrupt handler will not
  10864. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10865. * the intrrupt context. This function is called without any lock held.
  10866. * It gets the hbalock to access and update SLI data structures. Note that,
  10867. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10868. * equal to that of FCP CQ index.
  10869. *
  10870. * The link attention and ELS ring attention events are handled
  10871. * by the worker thread. The interrupt handler signals the worker thread
  10872. * and returns for these events. This function is called without any lock
  10873. * held. It gets the hbalock to access and update SLI data structures.
  10874. *
  10875. * This function returns IRQ_HANDLED when interrupt is handled else it
  10876. * returns IRQ_NONE.
  10877. **/
  10878. irqreturn_t
  10879. lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
  10880. {
  10881. struct lpfc_hba *phba;
  10882. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10883. struct lpfc_queue *fpeq;
  10884. struct lpfc_eqe *eqe;
  10885. unsigned long iflag;
  10886. int ecount = 0;
  10887. int fcp_eqidx;
  10888. /* Get the driver's phba structure from the dev_id */
  10889. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10890. phba = fcp_eq_hdl->phba;
  10891. fcp_eqidx = fcp_eq_hdl->idx;
  10892. if (unlikely(!phba))
  10893. return IRQ_NONE;
  10894. if (unlikely(!phba->sli4_hba.hba_eq))
  10895. return IRQ_NONE;
  10896. /* Get to the EQ struct associated with this vector */
  10897. fpeq = phba->sli4_hba.hba_eq[fcp_eqidx];
  10898. if (unlikely(!fpeq))
  10899. return IRQ_NONE;
  10900. if (lpfc_fcp_look_ahead) {
  10901. if (atomic_dec_and_test(&fcp_eq_hdl->fcp_eq_in_use))
  10902. lpfc_sli4_eq_clr_intr(fpeq);
  10903. else {
  10904. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10905. return IRQ_NONE;
  10906. }
  10907. }
  10908. /* Check device state for handling interrupt */
  10909. if (unlikely(lpfc_intr_state_check(phba))) {
  10910. fpeq->EQ_badstate++;
  10911. /* Check again for link_state with lock held */
  10912. spin_lock_irqsave(&phba->hbalock, iflag);
  10913. if (phba->link_state < LPFC_LINK_DOWN)
  10914. /* Flush, clear interrupt, and rearm the EQ */
  10915. lpfc_sli4_eq_flush(phba, fpeq);
  10916. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10917. if (lpfc_fcp_look_ahead)
  10918. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10919. return IRQ_NONE;
  10920. }
  10921. /*
  10922. * Process all the event on FCP fast-path EQ
  10923. */
  10924. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10925. lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx);
  10926. if (!(++ecount % fpeq->entry_repost))
  10927. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10928. fpeq->EQ_processed++;
  10929. }
  10930. /* Track the max number of EQEs processed in 1 intr */
  10931. if (ecount > fpeq->EQ_max_eqe)
  10932. fpeq->EQ_max_eqe = ecount;
  10933. /* Always clear and re-arm the fast-path EQ */
  10934. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  10935. if (unlikely(ecount == 0)) {
  10936. fpeq->EQ_no_entry++;
  10937. if (lpfc_fcp_look_ahead) {
  10938. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10939. return IRQ_NONE;
  10940. }
  10941. if (phba->intr_type == MSIX)
  10942. /* MSI-X treated interrupt served as no EQ share INT */
  10943. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10944. "0358 MSI-X interrupt with no EQE\n");
  10945. else
  10946. /* Non MSI-X treated on interrupt as EQ share INT */
  10947. return IRQ_NONE;
  10948. }
  10949. if (lpfc_fcp_look_ahead)
  10950. atomic_inc(&fcp_eq_hdl->fcp_eq_in_use);
  10951. return IRQ_HANDLED;
  10952. } /* lpfc_sli4_fp_intr_handler */
  10953. /**
  10954. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10955. * @irq: Interrupt number.
  10956. * @dev_id: The device context pointer.
  10957. *
  10958. * This function is the device-level interrupt handler to device with SLI-4
  10959. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10960. * interrupt mode is enabled and there is an event in the HBA which requires
  10961. * driver attention. This function invokes the slow-path interrupt attention
  10962. * handling function and fast-path interrupt attention handling function in
  10963. * turn to process the relevant HBA attention events. This function is called
  10964. * without any lock held. It gets the hbalock to access and update SLI data
  10965. * structures.
  10966. *
  10967. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10968. * returns IRQ_NONE.
  10969. **/
  10970. irqreturn_t
  10971. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10972. {
  10973. struct lpfc_hba *phba;
  10974. irqreturn_t hba_irq_rc;
  10975. bool hba_handled = false;
  10976. int fcp_eqidx;
  10977. /* Get the driver's phba structure from the dev_id */
  10978. phba = (struct lpfc_hba *)dev_id;
  10979. if (unlikely(!phba))
  10980. return IRQ_NONE;
  10981. /*
  10982. * Invoke fast-path host attention interrupt handling as appropriate.
  10983. */
  10984. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) {
  10985. hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
  10986. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10987. if (hba_irq_rc == IRQ_HANDLED)
  10988. hba_handled |= true;
  10989. }
  10990. return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
  10991. } /* lpfc_sli4_intr_handler */
  10992. /**
  10993. * lpfc_sli4_queue_free - free a queue structure and associated memory
  10994. * @queue: The queue structure to free.
  10995. *
  10996. * This function frees a queue structure and the DMAable memory used for
  10997. * the host resident queue. This function must be called after destroying the
  10998. * queue on the HBA.
  10999. **/
  11000. void
  11001. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  11002. {
  11003. struct lpfc_dmabuf *dmabuf;
  11004. if (!queue)
  11005. return;
  11006. while (!list_empty(&queue->page_list)) {
  11007. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  11008. list);
  11009. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  11010. dmabuf->virt, dmabuf->phys);
  11011. kfree(dmabuf);
  11012. }
  11013. kfree(queue);
  11014. return;
  11015. }
  11016. /**
  11017. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  11018. * @phba: The HBA that this queue is being created on.
  11019. * @entry_size: The size of each queue entry for this queue.
  11020. * @entry count: The number of entries that this queue will handle.
  11021. *
  11022. * This function allocates a queue structure and the DMAable memory used for
  11023. * the host resident queue. This function must be called before creating the
  11024. * queue on the HBA.
  11025. **/
  11026. struct lpfc_queue *
  11027. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  11028. uint32_t entry_count)
  11029. {
  11030. struct lpfc_queue *queue;
  11031. struct lpfc_dmabuf *dmabuf;
  11032. int x, total_qe_count;
  11033. void *dma_pointer;
  11034. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11035. if (!phba->sli4_hba.pc_sli4_params.supported)
  11036. hw_page_size = SLI4_PAGE_SIZE;
  11037. queue = kzalloc(sizeof(struct lpfc_queue) +
  11038. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  11039. if (!queue)
  11040. return NULL;
  11041. queue->page_count = (ALIGN(entry_size * entry_count,
  11042. hw_page_size))/hw_page_size;
  11043. INIT_LIST_HEAD(&queue->list);
  11044. INIT_LIST_HEAD(&queue->page_list);
  11045. INIT_LIST_HEAD(&queue->child_list);
  11046. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  11047. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  11048. if (!dmabuf)
  11049. goto out_fail;
  11050. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  11051. hw_page_size, &dmabuf->phys,
  11052. GFP_KERNEL);
  11053. if (!dmabuf->virt) {
  11054. kfree(dmabuf);
  11055. goto out_fail;
  11056. }
  11057. memset(dmabuf->virt, 0, hw_page_size);
  11058. dmabuf->buffer_tag = x;
  11059. list_add_tail(&dmabuf->list, &queue->page_list);
  11060. /* initialize queue's entry array */
  11061. dma_pointer = dmabuf->virt;
  11062. for (; total_qe_count < entry_count &&
  11063. dma_pointer < (hw_page_size + dmabuf->virt);
  11064. total_qe_count++, dma_pointer += entry_size) {
  11065. queue->qe[total_qe_count].address = dma_pointer;
  11066. }
  11067. }
  11068. queue->entry_size = entry_size;
  11069. queue->entry_count = entry_count;
  11070. /*
  11071. * entry_repost is calculated based on the number of entries in the
  11072. * queue. This works out except for RQs. If buffers are NOT initially
  11073. * posted for every RQE, entry_repost should be adjusted accordingly.
  11074. */
  11075. queue->entry_repost = (entry_count >> 3);
  11076. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  11077. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  11078. queue->phba = phba;
  11079. return queue;
  11080. out_fail:
  11081. lpfc_sli4_queue_free(queue);
  11082. return NULL;
  11083. }
  11084. /**
  11085. * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
  11086. * @phba: HBA structure that indicates port to create a queue on.
  11087. * @pci_barset: PCI BAR set flag.
  11088. *
  11089. * This function shall perform iomap of the specified PCI BAR address to host
  11090. * memory address if not already done so and return it. The returned host
  11091. * memory address can be NULL.
  11092. */
  11093. static void __iomem *
  11094. lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
  11095. {
  11096. struct pci_dev *pdev;
  11097. unsigned long bar_map, bar_map_len;
  11098. if (!phba->pcidev)
  11099. return NULL;
  11100. else
  11101. pdev = phba->pcidev;
  11102. switch (pci_barset) {
  11103. case WQ_PCI_BAR_0_AND_1:
  11104. if (!phba->pci_bar0_memmap_p) {
  11105. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
  11106. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
  11107. phba->pci_bar0_memmap_p = ioremap(bar_map, bar_map_len);
  11108. }
  11109. return phba->pci_bar0_memmap_p;
  11110. case WQ_PCI_BAR_2_AND_3:
  11111. if (!phba->pci_bar2_memmap_p) {
  11112. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
  11113. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
  11114. phba->pci_bar2_memmap_p = ioremap(bar_map, bar_map_len);
  11115. }
  11116. return phba->pci_bar2_memmap_p;
  11117. case WQ_PCI_BAR_4_AND_5:
  11118. if (!phba->pci_bar4_memmap_p) {
  11119. bar_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
  11120. bar_map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
  11121. phba->pci_bar4_memmap_p = ioremap(bar_map, bar_map_len);
  11122. }
  11123. return phba->pci_bar4_memmap_p;
  11124. default:
  11125. break;
  11126. }
  11127. return NULL;
  11128. }
  11129. /**
  11130. * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
  11131. * @phba: HBA structure that indicates port to create a queue on.
  11132. * @startq: The starting FCP EQ to modify
  11133. *
  11134. * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
  11135. *
  11136. * The @phba struct is used to send mailbox command to HBA. The @startq
  11137. * is used to get the starting FCP EQ to change.
  11138. * This function is asynchronous and will wait for the mailbox
  11139. * command to finish before continuing.
  11140. *
  11141. * On success this function will return a zero. If unable to allocate enough
  11142. * memory this function will return -ENOMEM. If the queue create mailbox command
  11143. * fails this function will return -ENXIO.
  11144. **/
  11145. uint32_t
  11146. lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq)
  11147. {
  11148. struct lpfc_mbx_modify_eq_delay *eq_delay;
  11149. LPFC_MBOXQ_t *mbox;
  11150. struct lpfc_queue *eq;
  11151. int cnt, rc, length, status = 0;
  11152. uint32_t shdr_status, shdr_add_status;
  11153. uint32_t result;
  11154. int fcp_eqidx;
  11155. union lpfc_sli4_cfg_shdr *shdr;
  11156. uint16_t dmult;
  11157. if (startq >= phba->cfg_fcp_io_channel)
  11158. return 0;
  11159. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11160. if (!mbox)
  11161. return -ENOMEM;
  11162. length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
  11163. sizeof(struct lpfc_sli4_cfg_mhdr));
  11164. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11165. LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
  11166. length, LPFC_SLI4_MBX_EMBED);
  11167. eq_delay = &mbox->u.mqe.un.eq_delay;
  11168. /* Calculate delay multiper from maximum interrupt per second */
  11169. result = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel;
  11170. if (result > LPFC_DMULT_CONST)
  11171. dmult = 0;
  11172. else
  11173. dmult = LPFC_DMULT_CONST/result - 1;
  11174. cnt = 0;
  11175. for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel;
  11176. fcp_eqidx++) {
  11177. eq = phba->sli4_hba.hba_eq[fcp_eqidx];
  11178. if (!eq)
  11179. continue;
  11180. eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
  11181. eq_delay->u.request.eq[cnt].phase = 0;
  11182. eq_delay->u.request.eq[cnt].delay_multi = dmult;
  11183. cnt++;
  11184. if (cnt >= LPFC_MAX_EQ_DELAY)
  11185. break;
  11186. }
  11187. eq_delay->u.request.num_eq = cnt;
  11188. mbox->vport = phba->pport;
  11189. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11190. mbox->context1 = NULL;
  11191. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11192. shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
  11193. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11194. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11195. if (shdr_status || shdr_add_status || rc) {
  11196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11197. "2512 MODIFY_EQ_DELAY mailbox failed with "
  11198. "status x%x add_status x%x, mbx status x%x\n",
  11199. shdr_status, shdr_add_status, rc);
  11200. status = -ENXIO;
  11201. }
  11202. mempool_free(mbox, phba->mbox_mem_pool);
  11203. return status;
  11204. }
  11205. /**
  11206. * lpfc_eq_create - Create an Event Queue on the HBA
  11207. * @phba: HBA structure that indicates port to create a queue on.
  11208. * @eq: The queue structure to use to create the event queue.
  11209. * @imax: The maximum interrupt per second limit.
  11210. *
  11211. * This function creates an event queue, as detailed in @eq, on a port,
  11212. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  11213. *
  11214. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  11215. * is used to get the entry count and entry size that are necessary to
  11216. * determine the number of pages to allocate and use for this queue. This
  11217. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  11218. * event queue. This function is asynchronous and will wait for the mailbox
  11219. * command to finish before continuing.
  11220. *
  11221. * On success this function will return a zero. If unable to allocate enough
  11222. * memory this function will return -ENOMEM. If the queue create mailbox command
  11223. * fails this function will return -ENXIO.
  11224. **/
  11225. uint32_t
  11226. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
  11227. {
  11228. struct lpfc_mbx_eq_create *eq_create;
  11229. LPFC_MBOXQ_t *mbox;
  11230. int rc, length, status = 0;
  11231. struct lpfc_dmabuf *dmabuf;
  11232. uint32_t shdr_status, shdr_add_status;
  11233. union lpfc_sli4_cfg_shdr *shdr;
  11234. uint16_t dmult;
  11235. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11236. /* sanity check on queue memory */
  11237. if (!eq)
  11238. return -ENODEV;
  11239. if (!phba->sli4_hba.pc_sli4_params.supported)
  11240. hw_page_size = SLI4_PAGE_SIZE;
  11241. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11242. if (!mbox)
  11243. return -ENOMEM;
  11244. length = (sizeof(struct lpfc_mbx_eq_create) -
  11245. sizeof(struct lpfc_sli4_cfg_mhdr));
  11246. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11247. LPFC_MBOX_OPCODE_EQ_CREATE,
  11248. length, LPFC_SLI4_MBX_EMBED);
  11249. eq_create = &mbox->u.mqe.un.eq_create;
  11250. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11251. eq->page_count);
  11252. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11253. LPFC_EQE_SIZE);
  11254. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11255. /* Calculate delay multiper from maximum interrupt per second */
  11256. if (imax > LPFC_DMULT_CONST)
  11257. dmult = 0;
  11258. else
  11259. dmult = LPFC_DMULT_CONST/imax - 1;
  11260. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11261. dmult);
  11262. switch (eq->entry_count) {
  11263. default:
  11264. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11265. "0360 Unsupported EQ count. (%d)\n",
  11266. eq->entry_count);
  11267. if (eq->entry_count < 256)
  11268. return -EINVAL;
  11269. /* otherwise default to smallest count (drop through) */
  11270. case 256:
  11271. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11272. LPFC_EQ_CNT_256);
  11273. break;
  11274. case 512:
  11275. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11276. LPFC_EQ_CNT_512);
  11277. break;
  11278. case 1024:
  11279. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11280. LPFC_EQ_CNT_1024);
  11281. break;
  11282. case 2048:
  11283. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11284. LPFC_EQ_CNT_2048);
  11285. break;
  11286. case 4096:
  11287. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11288. LPFC_EQ_CNT_4096);
  11289. break;
  11290. }
  11291. list_for_each_entry(dmabuf, &eq->page_list, list) {
  11292. memset(dmabuf->virt, 0, hw_page_size);
  11293. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11294. putPaddrLow(dmabuf->phys);
  11295. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11296. putPaddrHigh(dmabuf->phys);
  11297. }
  11298. mbox->vport = phba->pport;
  11299. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11300. mbox->context1 = NULL;
  11301. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11302. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  11303. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11304. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11305. if (shdr_status || shdr_add_status || rc) {
  11306. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11307. "2500 EQ_CREATE mailbox failed with "
  11308. "status x%x add_status x%x, mbx status x%x\n",
  11309. shdr_status, shdr_add_status, rc);
  11310. status = -ENXIO;
  11311. }
  11312. eq->type = LPFC_EQ;
  11313. eq->subtype = LPFC_NONE;
  11314. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  11315. if (eq->queue_id == 0xFFFF)
  11316. status = -ENXIO;
  11317. eq->host_index = 0;
  11318. eq->hba_index = 0;
  11319. mempool_free(mbox, phba->mbox_mem_pool);
  11320. return status;
  11321. }
  11322. /**
  11323. * lpfc_cq_create - Create a Completion Queue on the HBA
  11324. * @phba: HBA structure that indicates port to create a queue on.
  11325. * @cq: The queue structure to use to create the completion queue.
  11326. * @eq: The event queue to bind this completion queue to.
  11327. *
  11328. * This function creates a completion queue, as detailed in @wq, on a port,
  11329. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  11330. *
  11331. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11332. * is used to get the entry count and entry size that are necessary to
  11333. * determine the number of pages to allocate and use for this queue. The @eq
  11334. * is used to indicate which event queue to bind this completion queue to. This
  11335. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  11336. * completion queue. This function is asynchronous and will wait for the mailbox
  11337. * command to finish before continuing.
  11338. *
  11339. * On success this function will return a zero. If unable to allocate enough
  11340. * memory this function will return -ENOMEM. If the queue create mailbox command
  11341. * fails this function will return -ENXIO.
  11342. **/
  11343. uint32_t
  11344. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11345. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  11346. {
  11347. struct lpfc_mbx_cq_create *cq_create;
  11348. struct lpfc_dmabuf *dmabuf;
  11349. LPFC_MBOXQ_t *mbox;
  11350. int rc, length, status = 0;
  11351. uint32_t shdr_status, shdr_add_status;
  11352. union lpfc_sli4_cfg_shdr *shdr;
  11353. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11354. /* sanity check on queue memory */
  11355. if (!cq || !eq)
  11356. return -ENODEV;
  11357. if (!phba->sli4_hba.pc_sli4_params.supported)
  11358. hw_page_size = SLI4_PAGE_SIZE;
  11359. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11360. if (!mbox)
  11361. return -ENOMEM;
  11362. length = (sizeof(struct lpfc_mbx_cq_create) -
  11363. sizeof(struct lpfc_sli4_cfg_mhdr));
  11364. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11365. LPFC_MBOX_OPCODE_CQ_CREATE,
  11366. length, LPFC_SLI4_MBX_EMBED);
  11367. cq_create = &mbox->u.mqe.un.cq_create;
  11368. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  11369. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  11370. cq->page_count);
  11371. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  11372. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  11373. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11374. phba->sli4_hba.pc_sli4_params.cqv);
  11375. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  11376. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  11377. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  11378. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  11379. eq->queue_id);
  11380. } else {
  11381. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  11382. eq->queue_id);
  11383. }
  11384. switch (cq->entry_count) {
  11385. default:
  11386. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11387. "0361 Unsupported CQ count. (%d)\n",
  11388. cq->entry_count);
  11389. if (cq->entry_count < 256) {
  11390. status = -EINVAL;
  11391. goto out;
  11392. }
  11393. /* otherwise default to smallest count (drop through) */
  11394. case 256:
  11395. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11396. LPFC_CQ_CNT_256);
  11397. break;
  11398. case 512:
  11399. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11400. LPFC_CQ_CNT_512);
  11401. break;
  11402. case 1024:
  11403. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11404. LPFC_CQ_CNT_1024);
  11405. break;
  11406. }
  11407. list_for_each_entry(dmabuf, &cq->page_list, list) {
  11408. memset(dmabuf->virt, 0, hw_page_size);
  11409. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11410. putPaddrLow(dmabuf->phys);
  11411. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11412. putPaddrHigh(dmabuf->phys);
  11413. }
  11414. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11415. /* The IOCTL status is embedded in the mailbox subheader. */
  11416. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11417. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11418. if (shdr_status || shdr_add_status || rc) {
  11419. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11420. "2501 CQ_CREATE mailbox failed with "
  11421. "status x%x add_status x%x, mbx status x%x\n",
  11422. shdr_status, shdr_add_status, rc);
  11423. status = -ENXIO;
  11424. goto out;
  11425. }
  11426. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11427. if (cq->queue_id == 0xFFFF) {
  11428. status = -ENXIO;
  11429. goto out;
  11430. }
  11431. /* link the cq onto the parent eq child list */
  11432. list_add_tail(&cq->list, &eq->child_list);
  11433. /* Set up completion queue's type and subtype */
  11434. cq->type = type;
  11435. cq->subtype = subtype;
  11436. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11437. cq->assoc_qid = eq->queue_id;
  11438. cq->host_index = 0;
  11439. cq->hba_index = 0;
  11440. out:
  11441. mempool_free(mbox, phba->mbox_mem_pool);
  11442. return status;
  11443. }
  11444. /**
  11445. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  11446. * @phba: HBA structure that indicates port to create a queue on.
  11447. * @mq: The queue structure to use to create the mailbox queue.
  11448. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  11449. * @cq: The completion queue to associate with this cq.
  11450. *
  11451. * This function provides failback (fb) functionality when the
  11452. * mq_create_ext fails on older FW generations. It's purpose is identical
  11453. * to mq_create_ext otherwise.
  11454. *
  11455. * This routine cannot fail as all attributes were previously accessed and
  11456. * initialized in mq_create_ext.
  11457. **/
  11458. static void
  11459. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11460. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  11461. {
  11462. struct lpfc_mbx_mq_create *mq_create;
  11463. struct lpfc_dmabuf *dmabuf;
  11464. int length;
  11465. length = (sizeof(struct lpfc_mbx_mq_create) -
  11466. sizeof(struct lpfc_sli4_cfg_mhdr));
  11467. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11468. LPFC_MBOX_OPCODE_MQ_CREATE,
  11469. length, LPFC_SLI4_MBX_EMBED);
  11470. mq_create = &mbox->u.mqe.un.mq_create;
  11471. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  11472. mq->page_count);
  11473. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  11474. cq->queue_id);
  11475. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  11476. switch (mq->entry_count) {
  11477. case 16:
  11478. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11479. LPFC_MQ_RING_SIZE_16);
  11480. break;
  11481. case 32:
  11482. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11483. LPFC_MQ_RING_SIZE_32);
  11484. break;
  11485. case 64:
  11486. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11487. LPFC_MQ_RING_SIZE_64);
  11488. break;
  11489. case 128:
  11490. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11491. LPFC_MQ_RING_SIZE_128);
  11492. break;
  11493. }
  11494. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11495. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11496. putPaddrLow(dmabuf->phys);
  11497. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11498. putPaddrHigh(dmabuf->phys);
  11499. }
  11500. }
  11501. /**
  11502. * lpfc_mq_create - Create a mailbox Queue on the HBA
  11503. * @phba: HBA structure that indicates port to create a queue on.
  11504. * @mq: The queue structure to use to create the mailbox queue.
  11505. * @cq: The completion queue to associate with this cq.
  11506. * @subtype: The queue's subtype.
  11507. *
  11508. * This function creates a mailbox queue, as detailed in @mq, on a port,
  11509. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  11510. *
  11511. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11512. * is used to get the entry count and entry size that are necessary to
  11513. * determine the number of pages to allocate and use for this queue. This
  11514. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  11515. * mailbox queue. This function is asynchronous and will wait for the mailbox
  11516. * command to finish before continuing.
  11517. *
  11518. * On success this function will return a zero. If unable to allocate enough
  11519. * memory this function will return -ENOMEM. If the queue create mailbox command
  11520. * fails this function will return -ENXIO.
  11521. **/
  11522. int32_t
  11523. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11524. struct lpfc_queue *cq, uint32_t subtype)
  11525. {
  11526. struct lpfc_mbx_mq_create *mq_create;
  11527. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11528. struct lpfc_dmabuf *dmabuf;
  11529. LPFC_MBOXQ_t *mbox;
  11530. int rc, length, status = 0;
  11531. uint32_t shdr_status, shdr_add_status;
  11532. union lpfc_sli4_cfg_shdr *shdr;
  11533. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11534. /* sanity check on queue memory */
  11535. if (!mq || !cq)
  11536. return -ENODEV;
  11537. if (!phba->sli4_hba.pc_sli4_params.supported)
  11538. hw_page_size = SLI4_PAGE_SIZE;
  11539. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11540. if (!mbox)
  11541. return -ENOMEM;
  11542. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11543. sizeof(struct lpfc_sli4_cfg_mhdr));
  11544. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11545. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11546. length, LPFC_SLI4_MBX_EMBED);
  11547. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11548. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11549. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11550. &mq_create_ext->u.request, mq->page_count);
  11551. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11552. &mq_create_ext->u.request, 1);
  11553. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11554. &mq_create_ext->u.request, 1);
  11555. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11556. &mq_create_ext->u.request, 1);
  11557. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11558. &mq_create_ext->u.request, 1);
  11559. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11560. &mq_create_ext->u.request, 1);
  11561. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11562. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11563. phba->sli4_hba.pc_sli4_params.mqv);
  11564. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11565. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11566. cq->queue_id);
  11567. else
  11568. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11569. cq->queue_id);
  11570. switch (mq->entry_count) {
  11571. default:
  11572. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11573. "0362 Unsupported MQ count. (%d)\n",
  11574. mq->entry_count);
  11575. if (mq->entry_count < 16) {
  11576. status = -EINVAL;
  11577. goto out;
  11578. }
  11579. /* otherwise default to smallest count (drop through) */
  11580. case 16:
  11581. bf_set(lpfc_mq_context_ring_size,
  11582. &mq_create_ext->u.request.context,
  11583. LPFC_MQ_RING_SIZE_16);
  11584. break;
  11585. case 32:
  11586. bf_set(lpfc_mq_context_ring_size,
  11587. &mq_create_ext->u.request.context,
  11588. LPFC_MQ_RING_SIZE_32);
  11589. break;
  11590. case 64:
  11591. bf_set(lpfc_mq_context_ring_size,
  11592. &mq_create_ext->u.request.context,
  11593. LPFC_MQ_RING_SIZE_64);
  11594. break;
  11595. case 128:
  11596. bf_set(lpfc_mq_context_ring_size,
  11597. &mq_create_ext->u.request.context,
  11598. LPFC_MQ_RING_SIZE_128);
  11599. break;
  11600. }
  11601. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11602. memset(dmabuf->virt, 0, hw_page_size);
  11603. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11604. putPaddrLow(dmabuf->phys);
  11605. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11606. putPaddrHigh(dmabuf->phys);
  11607. }
  11608. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11609. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11610. &mq_create_ext->u.response);
  11611. if (rc != MBX_SUCCESS) {
  11612. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11613. "2795 MQ_CREATE_EXT failed with "
  11614. "status x%x. Failback to MQ_CREATE.\n",
  11615. rc);
  11616. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11617. mq_create = &mbox->u.mqe.un.mq_create;
  11618. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11619. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11620. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11621. &mq_create->u.response);
  11622. }
  11623. /* The IOCTL status is embedded in the mailbox subheader. */
  11624. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11625. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11626. if (shdr_status || shdr_add_status || rc) {
  11627. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11628. "2502 MQ_CREATE mailbox failed with "
  11629. "status x%x add_status x%x, mbx status x%x\n",
  11630. shdr_status, shdr_add_status, rc);
  11631. status = -ENXIO;
  11632. goto out;
  11633. }
  11634. if (mq->queue_id == 0xFFFF) {
  11635. status = -ENXIO;
  11636. goto out;
  11637. }
  11638. mq->type = LPFC_MQ;
  11639. mq->assoc_qid = cq->queue_id;
  11640. mq->subtype = subtype;
  11641. mq->host_index = 0;
  11642. mq->hba_index = 0;
  11643. /* link the mq onto the parent cq child list */
  11644. list_add_tail(&mq->list, &cq->child_list);
  11645. out:
  11646. mempool_free(mbox, phba->mbox_mem_pool);
  11647. return status;
  11648. }
  11649. /**
  11650. * lpfc_wq_create - Create a Work Queue on the HBA
  11651. * @phba: HBA structure that indicates port to create a queue on.
  11652. * @wq: The queue structure to use to create the work queue.
  11653. * @cq: The completion queue to bind this work queue to.
  11654. * @subtype: The subtype of the work queue indicating its functionality.
  11655. *
  11656. * This function creates a work queue, as detailed in @wq, on a port, described
  11657. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11658. *
  11659. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11660. * is used to get the entry count and entry size that are necessary to
  11661. * determine the number of pages to allocate and use for this queue. The @cq
  11662. * is used to indicate which completion queue to bind this work queue to. This
  11663. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11664. * work queue. This function is asynchronous and will wait for the mailbox
  11665. * command to finish before continuing.
  11666. *
  11667. * On success this function will return a zero. If unable to allocate enough
  11668. * memory this function will return -ENOMEM. If the queue create mailbox command
  11669. * fails this function will return -ENXIO.
  11670. **/
  11671. uint32_t
  11672. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11673. struct lpfc_queue *cq, uint32_t subtype)
  11674. {
  11675. struct lpfc_mbx_wq_create *wq_create;
  11676. struct lpfc_dmabuf *dmabuf;
  11677. LPFC_MBOXQ_t *mbox;
  11678. int rc, length, status = 0;
  11679. uint32_t shdr_status, shdr_add_status;
  11680. union lpfc_sli4_cfg_shdr *shdr;
  11681. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11682. struct dma_address *page;
  11683. void __iomem *bar_memmap_p;
  11684. uint32_t db_offset;
  11685. uint16_t pci_barset;
  11686. /* sanity check on queue memory */
  11687. if (!wq || !cq)
  11688. return -ENODEV;
  11689. if (!phba->sli4_hba.pc_sli4_params.supported)
  11690. hw_page_size = SLI4_PAGE_SIZE;
  11691. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11692. if (!mbox)
  11693. return -ENOMEM;
  11694. length = (sizeof(struct lpfc_mbx_wq_create) -
  11695. sizeof(struct lpfc_sli4_cfg_mhdr));
  11696. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11697. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11698. length, LPFC_SLI4_MBX_EMBED);
  11699. wq_create = &mbox->u.mqe.un.wq_create;
  11700. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11701. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11702. wq->page_count);
  11703. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11704. cq->queue_id);
  11705. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11706. phba->sli4_hba.pc_sli4_params.wqv);
  11707. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11708. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11709. wq->entry_count);
  11710. switch (wq->entry_size) {
  11711. default:
  11712. case 64:
  11713. bf_set(lpfc_mbx_wq_create_wqe_size,
  11714. &wq_create->u.request_1,
  11715. LPFC_WQ_WQE_SIZE_64);
  11716. break;
  11717. case 128:
  11718. bf_set(lpfc_mbx_wq_create_wqe_size,
  11719. &wq_create->u.request_1,
  11720. LPFC_WQ_WQE_SIZE_128);
  11721. break;
  11722. }
  11723. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11724. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11725. page = wq_create->u.request_1.page;
  11726. } else {
  11727. page = wq_create->u.request.page;
  11728. }
  11729. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11730. memset(dmabuf->virt, 0, hw_page_size);
  11731. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11732. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11733. }
  11734. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  11735. bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
  11736. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11737. /* The IOCTL status is embedded in the mailbox subheader. */
  11738. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11739. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11740. if (shdr_status || shdr_add_status || rc) {
  11741. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11742. "2503 WQ_CREATE mailbox failed with "
  11743. "status x%x add_status x%x, mbx status x%x\n",
  11744. shdr_status, shdr_add_status, rc);
  11745. status = -ENXIO;
  11746. goto out;
  11747. }
  11748. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11749. if (wq->queue_id == 0xFFFF) {
  11750. status = -ENXIO;
  11751. goto out;
  11752. }
  11753. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  11754. wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
  11755. &wq_create->u.response);
  11756. if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
  11757. (wq->db_format != LPFC_DB_RING_FORMAT)) {
  11758. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11759. "3265 WQ[%d] doorbell format not "
  11760. "supported: x%x\n", wq->queue_id,
  11761. wq->db_format);
  11762. status = -EINVAL;
  11763. goto out;
  11764. }
  11765. pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
  11766. &wq_create->u.response);
  11767. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  11768. if (!bar_memmap_p) {
  11769. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11770. "3263 WQ[%d] failed to memmap pci "
  11771. "barset:x%x\n", wq->queue_id,
  11772. pci_barset);
  11773. status = -ENOMEM;
  11774. goto out;
  11775. }
  11776. db_offset = wq_create->u.response.doorbell_offset;
  11777. if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
  11778. (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
  11779. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11780. "3252 WQ[%d] doorbell offset not "
  11781. "supported: x%x\n", wq->queue_id,
  11782. db_offset);
  11783. status = -EINVAL;
  11784. goto out;
  11785. }
  11786. wq->db_regaddr = bar_memmap_p + db_offset;
  11787. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11788. "3264 WQ[%d]: barset:x%x, offset:x%x\n",
  11789. wq->queue_id, pci_barset, db_offset);
  11790. } else {
  11791. wq->db_format = LPFC_DB_LIST_FORMAT;
  11792. wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
  11793. }
  11794. wq->type = LPFC_WQ;
  11795. wq->assoc_qid = cq->queue_id;
  11796. wq->subtype = subtype;
  11797. wq->host_index = 0;
  11798. wq->hba_index = 0;
  11799. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11800. /* link the wq onto the parent cq child list */
  11801. list_add_tail(&wq->list, &cq->child_list);
  11802. out:
  11803. mempool_free(mbox, phba->mbox_mem_pool);
  11804. return status;
  11805. }
  11806. /**
  11807. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11808. * @phba: HBA structure that indicates port to create a queue on.
  11809. * @rq: The queue structure to use for the receive queue.
  11810. * @qno: The associated HBQ number
  11811. *
  11812. *
  11813. * For SLI4 we need to adjust the RQ repost value based on
  11814. * the number of buffers that are initially posted to the RQ.
  11815. */
  11816. void
  11817. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11818. {
  11819. uint32_t cnt;
  11820. /* sanity check on queue memory */
  11821. if (!rq)
  11822. return;
  11823. cnt = lpfc_hbq_defs[qno]->entry_count;
  11824. /* Recalc repost for RQs based on buffers initially posted */
  11825. cnt = (cnt >> 3);
  11826. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11827. cnt = LPFC_QUEUE_MIN_REPOST;
  11828. rq->entry_repost = cnt;
  11829. }
  11830. /**
  11831. * lpfc_rq_create - Create a Receive Queue on the HBA
  11832. * @phba: HBA structure that indicates port to create a queue on.
  11833. * @hrq: The queue structure to use to create the header receive queue.
  11834. * @drq: The queue structure to use to create the data receive queue.
  11835. * @cq: The completion queue to bind this work queue to.
  11836. *
  11837. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11838. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11839. * to the HBA.
  11840. *
  11841. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11842. * struct is used to get the entry count that is necessary to determine the
  11843. * number of pages to use for this queue. The @cq is used to indicate which
  11844. * completion queue to bind received buffers that are posted to these queues to.
  11845. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11846. * receive queue pair. This function is asynchronous and will wait for the
  11847. * mailbox command to finish before continuing.
  11848. *
  11849. * On success this function will return a zero. If unable to allocate enough
  11850. * memory this function will return -ENOMEM. If the queue create mailbox command
  11851. * fails this function will return -ENXIO.
  11852. **/
  11853. uint32_t
  11854. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11855. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11856. {
  11857. struct lpfc_mbx_rq_create *rq_create;
  11858. struct lpfc_dmabuf *dmabuf;
  11859. LPFC_MBOXQ_t *mbox;
  11860. int rc, length, status = 0;
  11861. uint32_t shdr_status, shdr_add_status;
  11862. union lpfc_sli4_cfg_shdr *shdr;
  11863. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11864. void __iomem *bar_memmap_p;
  11865. uint32_t db_offset;
  11866. uint16_t pci_barset;
  11867. /* sanity check on queue memory */
  11868. if (!hrq || !drq || !cq)
  11869. return -ENODEV;
  11870. if (!phba->sli4_hba.pc_sli4_params.supported)
  11871. hw_page_size = SLI4_PAGE_SIZE;
  11872. if (hrq->entry_count != drq->entry_count)
  11873. return -EINVAL;
  11874. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11875. if (!mbox)
  11876. return -ENOMEM;
  11877. length = (sizeof(struct lpfc_mbx_rq_create) -
  11878. sizeof(struct lpfc_sli4_cfg_mhdr));
  11879. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11880. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11881. length, LPFC_SLI4_MBX_EMBED);
  11882. rq_create = &mbox->u.mqe.un.rq_create;
  11883. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11884. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11885. phba->sli4_hba.pc_sli4_params.rqv);
  11886. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11887. bf_set(lpfc_rq_context_rqe_count_1,
  11888. &rq_create->u.request.context,
  11889. hrq->entry_count);
  11890. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11891. bf_set(lpfc_rq_context_rqe_size,
  11892. &rq_create->u.request.context,
  11893. LPFC_RQE_SIZE_8);
  11894. bf_set(lpfc_rq_context_page_size,
  11895. &rq_create->u.request.context,
  11896. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11897. } else {
  11898. switch (hrq->entry_count) {
  11899. default:
  11900. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11901. "2535 Unsupported RQ count. (%d)\n",
  11902. hrq->entry_count);
  11903. if (hrq->entry_count < 512) {
  11904. status = -EINVAL;
  11905. goto out;
  11906. }
  11907. /* otherwise default to smallest count (drop through) */
  11908. case 512:
  11909. bf_set(lpfc_rq_context_rqe_count,
  11910. &rq_create->u.request.context,
  11911. LPFC_RQ_RING_SIZE_512);
  11912. break;
  11913. case 1024:
  11914. bf_set(lpfc_rq_context_rqe_count,
  11915. &rq_create->u.request.context,
  11916. LPFC_RQ_RING_SIZE_1024);
  11917. break;
  11918. case 2048:
  11919. bf_set(lpfc_rq_context_rqe_count,
  11920. &rq_create->u.request.context,
  11921. LPFC_RQ_RING_SIZE_2048);
  11922. break;
  11923. case 4096:
  11924. bf_set(lpfc_rq_context_rqe_count,
  11925. &rq_create->u.request.context,
  11926. LPFC_RQ_RING_SIZE_4096);
  11927. break;
  11928. }
  11929. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11930. LPFC_HDR_BUF_SIZE);
  11931. }
  11932. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11933. cq->queue_id);
  11934. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11935. hrq->page_count);
  11936. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11937. memset(dmabuf->virt, 0, hw_page_size);
  11938. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11939. putPaddrLow(dmabuf->phys);
  11940. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11941. putPaddrHigh(dmabuf->phys);
  11942. }
  11943. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  11944. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  11945. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11946. /* The IOCTL status is embedded in the mailbox subheader. */
  11947. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11948. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11949. if (shdr_status || shdr_add_status || rc) {
  11950. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11951. "2504 RQ_CREATE mailbox failed with "
  11952. "status x%x add_status x%x, mbx status x%x\n",
  11953. shdr_status, shdr_add_status, rc);
  11954. status = -ENXIO;
  11955. goto out;
  11956. }
  11957. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11958. if (hrq->queue_id == 0xFFFF) {
  11959. status = -ENXIO;
  11960. goto out;
  11961. }
  11962. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  11963. hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
  11964. &rq_create->u.response);
  11965. if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
  11966. (hrq->db_format != LPFC_DB_RING_FORMAT)) {
  11967. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11968. "3262 RQ [%d] doorbell format not "
  11969. "supported: x%x\n", hrq->queue_id,
  11970. hrq->db_format);
  11971. status = -EINVAL;
  11972. goto out;
  11973. }
  11974. pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
  11975. &rq_create->u.response);
  11976. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  11977. if (!bar_memmap_p) {
  11978. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11979. "3269 RQ[%d] failed to memmap pci "
  11980. "barset:x%x\n", hrq->queue_id,
  11981. pci_barset);
  11982. status = -ENOMEM;
  11983. goto out;
  11984. }
  11985. db_offset = rq_create->u.response.doorbell_offset;
  11986. if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
  11987. (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
  11988. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11989. "3270 RQ[%d] doorbell offset not "
  11990. "supported: x%x\n", hrq->queue_id,
  11991. db_offset);
  11992. status = -EINVAL;
  11993. goto out;
  11994. }
  11995. hrq->db_regaddr = bar_memmap_p + db_offset;
  11996. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11997. "3266 RQ[qid:%d]: barset:x%x, offset:x%x\n",
  11998. hrq->queue_id, pci_barset, db_offset);
  11999. } else {
  12000. hrq->db_format = LPFC_DB_RING_FORMAT;
  12001. hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  12002. }
  12003. hrq->type = LPFC_HRQ;
  12004. hrq->assoc_qid = cq->queue_id;
  12005. hrq->subtype = subtype;
  12006. hrq->host_index = 0;
  12007. hrq->hba_index = 0;
  12008. /* now create the data queue */
  12009. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12010. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  12011. length, LPFC_SLI4_MBX_EMBED);
  12012. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  12013. phba->sli4_hba.pc_sli4_params.rqv);
  12014. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  12015. bf_set(lpfc_rq_context_rqe_count_1,
  12016. &rq_create->u.request.context, hrq->entry_count);
  12017. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  12018. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  12019. LPFC_RQE_SIZE_8);
  12020. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  12021. (PAGE_SIZE/SLI4_PAGE_SIZE));
  12022. } else {
  12023. switch (drq->entry_count) {
  12024. default:
  12025. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12026. "2536 Unsupported RQ count. (%d)\n",
  12027. drq->entry_count);
  12028. if (drq->entry_count < 512) {
  12029. status = -EINVAL;
  12030. goto out;
  12031. }
  12032. /* otherwise default to smallest count (drop through) */
  12033. case 512:
  12034. bf_set(lpfc_rq_context_rqe_count,
  12035. &rq_create->u.request.context,
  12036. LPFC_RQ_RING_SIZE_512);
  12037. break;
  12038. case 1024:
  12039. bf_set(lpfc_rq_context_rqe_count,
  12040. &rq_create->u.request.context,
  12041. LPFC_RQ_RING_SIZE_1024);
  12042. break;
  12043. case 2048:
  12044. bf_set(lpfc_rq_context_rqe_count,
  12045. &rq_create->u.request.context,
  12046. LPFC_RQ_RING_SIZE_2048);
  12047. break;
  12048. case 4096:
  12049. bf_set(lpfc_rq_context_rqe_count,
  12050. &rq_create->u.request.context,
  12051. LPFC_RQ_RING_SIZE_4096);
  12052. break;
  12053. }
  12054. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  12055. LPFC_DATA_BUF_SIZE);
  12056. }
  12057. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  12058. cq->queue_id);
  12059. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  12060. drq->page_count);
  12061. list_for_each_entry(dmabuf, &drq->page_list, list) {
  12062. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  12063. putPaddrLow(dmabuf->phys);
  12064. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  12065. putPaddrHigh(dmabuf->phys);
  12066. }
  12067. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  12068. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  12069. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12070. /* The IOCTL status is embedded in the mailbox subheader. */
  12071. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  12072. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12073. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12074. if (shdr_status || shdr_add_status || rc) {
  12075. status = -ENXIO;
  12076. goto out;
  12077. }
  12078. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  12079. if (drq->queue_id == 0xFFFF) {
  12080. status = -ENXIO;
  12081. goto out;
  12082. }
  12083. drq->type = LPFC_DRQ;
  12084. drq->assoc_qid = cq->queue_id;
  12085. drq->subtype = subtype;
  12086. drq->host_index = 0;
  12087. drq->hba_index = 0;
  12088. /* link the header and data RQs onto the parent cq child list */
  12089. list_add_tail(&hrq->list, &cq->child_list);
  12090. list_add_tail(&drq->list, &cq->child_list);
  12091. out:
  12092. mempool_free(mbox, phba->mbox_mem_pool);
  12093. return status;
  12094. }
  12095. /**
  12096. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  12097. * @eq: The queue structure associated with the queue to destroy.
  12098. *
  12099. * This function destroys a queue, as detailed in @eq by sending an mailbox
  12100. * command, specific to the type of queue, to the HBA.
  12101. *
  12102. * The @eq struct is used to get the queue ID of the queue to destroy.
  12103. *
  12104. * On success this function will return a zero. If the queue destroy mailbox
  12105. * command fails this function will return -ENXIO.
  12106. **/
  12107. uint32_t
  12108. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  12109. {
  12110. LPFC_MBOXQ_t *mbox;
  12111. int rc, length, status = 0;
  12112. uint32_t shdr_status, shdr_add_status;
  12113. union lpfc_sli4_cfg_shdr *shdr;
  12114. /* sanity check on queue memory */
  12115. if (!eq)
  12116. return -ENODEV;
  12117. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  12118. if (!mbox)
  12119. return -ENOMEM;
  12120. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  12121. sizeof(struct lpfc_sli4_cfg_mhdr));
  12122. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12123. LPFC_MBOX_OPCODE_EQ_DESTROY,
  12124. length, LPFC_SLI4_MBX_EMBED);
  12125. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  12126. eq->queue_id);
  12127. mbox->vport = eq->phba->pport;
  12128. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12129. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  12130. /* The IOCTL status is embedded in the mailbox subheader. */
  12131. shdr = (union lpfc_sli4_cfg_shdr *)
  12132. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  12133. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12134. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12135. if (shdr_status || shdr_add_status || rc) {
  12136. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12137. "2505 EQ_DESTROY mailbox failed with "
  12138. "status x%x add_status x%x, mbx status x%x\n",
  12139. shdr_status, shdr_add_status, rc);
  12140. status = -ENXIO;
  12141. }
  12142. /* Remove eq from any list */
  12143. list_del_init(&eq->list);
  12144. mempool_free(mbox, eq->phba->mbox_mem_pool);
  12145. return status;
  12146. }
  12147. /**
  12148. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  12149. * @cq: The queue structure associated with the queue to destroy.
  12150. *
  12151. * This function destroys a queue, as detailed in @cq by sending an mailbox
  12152. * command, specific to the type of queue, to the HBA.
  12153. *
  12154. * The @cq struct is used to get the queue ID of the queue to destroy.
  12155. *
  12156. * On success this function will return a zero. If the queue destroy mailbox
  12157. * command fails this function will return -ENXIO.
  12158. **/
  12159. uint32_t
  12160. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  12161. {
  12162. LPFC_MBOXQ_t *mbox;
  12163. int rc, length, status = 0;
  12164. uint32_t shdr_status, shdr_add_status;
  12165. union lpfc_sli4_cfg_shdr *shdr;
  12166. /* sanity check on queue memory */
  12167. if (!cq)
  12168. return -ENODEV;
  12169. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  12170. if (!mbox)
  12171. return -ENOMEM;
  12172. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  12173. sizeof(struct lpfc_sli4_cfg_mhdr));
  12174. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12175. LPFC_MBOX_OPCODE_CQ_DESTROY,
  12176. length, LPFC_SLI4_MBX_EMBED);
  12177. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  12178. cq->queue_id);
  12179. mbox->vport = cq->phba->pport;
  12180. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12181. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  12182. /* The IOCTL status is embedded in the mailbox subheader. */
  12183. shdr = (union lpfc_sli4_cfg_shdr *)
  12184. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  12185. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12186. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12187. if (shdr_status || shdr_add_status || rc) {
  12188. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12189. "2506 CQ_DESTROY mailbox failed with "
  12190. "status x%x add_status x%x, mbx status x%x\n",
  12191. shdr_status, shdr_add_status, rc);
  12192. status = -ENXIO;
  12193. }
  12194. /* Remove cq from any list */
  12195. list_del_init(&cq->list);
  12196. mempool_free(mbox, cq->phba->mbox_mem_pool);
  12197. return status;
  12198. }
  12199. /**
  12200. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  12201. * @qm: The queue structure associated with the queue to destroy.
  12202. *
  12203. * This function destroys a queue, as detailed in @mq by sending an mailbox
  12204. * command, specific to the type of queue, to the HBA.
  12205. *
  12206. * The @mq struct is used to get the queue ID of the queue to destroy.
  12207. *
  12208. * On success this function will return a zero. If the queue destroy mailbox
  12209. * command fails this function will return -ENXIO.
  12210. **/
  12211. uint32_t
  12212. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  12213. {
  12214. LPFC_MBOXQ_t *mbox;
  12215. int rc, length, status = 0;
  12216. uint32_t shdr_status, shdr_add_status;
  12217. union lpfc_sli4_cfg_shdr *shdr;
  12218. /* sanity check on queue memory */
  12219. if (!mq)
  12220. return -ENODEV;
  12221. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  12222. if (!mbox)
  12223. return -ENOMEM;
  12224. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  12225. sizeof(struct lpfc_sli4_cfg_mhdr));
  12226. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  12227. LPFC_MBOX_OPCODE_MQ_DESTROY,
  12228. length, LPFC_SLI4_MBX_EMBED);
  12229. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  12230. mq->queue_id);
  12231. mbox->vport = mq->phba->pport;
  12232. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12233. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  12234. /* The IOCTL status is embedded in the mailbox subheader. */
  12235. shdr = (union lpfc_sli4_cfg_shdr *)
  12236. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  12237. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12238. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12239. if (shdr_status || shdr_add_status || rc) {
  12240. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12241. "2507 MQ_DESTROY mailbox failed with "
  12242. "status x%x add_status x%x, mbx status x%x\n",
  12243. shdr_status, shdr_add_status, rc);
  12244. status = -ENXIO;
  12245. }
  12246. /* Remove mq from any list */
  12247. list_del_init(&mq->list);
  12248. mempool_free(mbox, mq->phba->mbox_mem_pool);
  12249. return status;
  12250. }
  12251. /**
  12252. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  12253. * @wq: The queue structure associated with the queue to destroy.
  12254. *
  12255. * This function destroys a queue, as detailed in @wq by sending an mailbox
  12256. * command, specific to the type of queue, to the HBA.
  12257. *
  12258. * The @wq struct is used to get the queue ID of the queue to destroy.
  12259. *
  12260. * On success this function will return a zero. If the queue destroy mailbox
  12261. * command fails this function will return -ENXIO.
  12262. **/
  12263. uint32_t
  12264. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  12265. {
  12266. LPFC_MBOXQ_t *mbox;
  12267. int rc, length, status = 0;
  12268. uint32_t shdr_status, shdr_add_status;
  12269. union lpfc_sli4_cfg_shdr *shdr;
  12270. /* sanity check on queue memory */
  12271. if (!wq)
  12272. return -ENODEV;
  12273. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  12274. if (!mbox)
  12275. return -ENOMEM;
  12276. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  12277. sizeof(struct lpfc_sli4_cfg_mhdr));
  12278. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12279. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  12280. length, LPFC_SLI4_MBX_EMBED);
  12281. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  12282. wq->queue_id);
  12283. mbox->vport = wq->phba->pport;
  12284. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12285. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  12286. shdr = (union lpfc_sli4_cfg_shdr *)
  12287. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  12288. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12289. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12290. if (shdr_status || shdr_add_status || rc) {
  12291. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12292. "2508 WQ_DESTROY mailbox failed with "
  12293. "status x%x add_status x%x, mbx status x%x\n",
  12294. shdr_status, shdr_add_status, rc);
  12295. status = -ENXIO;
  12296. }
  12297. /* Remove wq from any list */
  12298. list_del_init(&wq->list);
  12299. mempool_free(mbox, wq->phba->mbox_mem_pool);
  12300. return status;
  12301. }
  12302. /**
  12303. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  12304. * @rq: The queue structure associated with the queue to destroy.
  12305. *
  12306. * This function destroys a queue, as detailed in @rq by sending an mailbox
  12307. * command, specific to the type of queue, to the HBA.
  12308. *
  12309. * The @rq struct is used to get the queue ID of the queue to destroy.
  12310. *
  12311. * On success this function will return a zero. If the queue destroy mailbox
  12312. * command fails this function will return -ENXIO.
  12313. **/
  12314. uint32_t
  12315. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  12316. struct lpfc_queue *drq)
  12317. {
  12318. LPFC_MBOXQ_t *mbox;
  12319. int rc, length, status = 0;
  12320. uint32_t shdr_status, shdr_add_status;
  12321. union lpfc_sli4_cfg_shdr *shdr;
  12322. /* sanity check on queue memory */
  12323. if (!hrq || !drq)
  12324. return -ENODEV;
  12325. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  12326. if (!mbox)
  12327. return -ENOMEM;
  12328. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  12329. sizeof(struct lpfc_sli4_cfg_mhdr));
  12330. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12331. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  12332. length, LPFC_SLI4_MBX_EMBED);
  12333. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12334. hrq->queue_id);
  12335. mbox->vport = hrq->phba->pport;
  12336. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  12337. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  12338. /* The IOCTL status is embedded in the mailbox subheader. */
  12339. shdr = (union lpfc_sli4_cfg_shdr *)
  12340. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12341. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12342. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12343. if (shdr_status || shdr_add_status || rc) {
  12344. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12345. "2509 RQ_DESTROY mailbox failed with "
  12346. "status x%x add_status x%x, mbx status x%x\n",
  12347. shdr_status, shdr_add_status, rc);
  12348. if (rc != MBX_TIMEOUT)
  12349. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12350. return -ENXIO;
  12351. }
  12352. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12353. drq->queue_id);
  12354. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  12355. shdr = (union lpfc_sli4_cfg_shdr *)
  12356. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12357. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12358. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12359. if (shdr_status || shdr_add_status || rc) {
  12360. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12361. "2510 RQ_DESTROY mailbox failed with "
  12362. "status x%x add_status x%x, mbx status x%x\n",
  12363. shdr_status, shdr_add_status, rc);
  12364. status = -ENXIO;
  12365. }
  12366. list_del_init(&hrq->list);
  12367. list_del_init(&drq->list);
  12368. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12369. return status;
  12370. }
  12371. /**
  12372. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  12373. * @phba: The virtual port for which this call being executed.
  12374. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  12375. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  12376. * @xritag: the xritag that ties this io to the SGL pages.
  12377. *
  12378. * This routine will post the sgl pages for the IO that has the xritag
  12379. * that is in the iocbq structure. The xritag is assigned during iocbq
  12380. * creation and persists for as long as the driver is loaded.
  12381. * if the caller has fewer than 256 scatter gather segments to map then
  12382. * pdma_phys_addr1 should be 0.
  12383. * If the caller needs to map more than 256 scatter gather segment then
  12384. * pdma_phys_addr1 should be a valid physical address.
  12385. * physical address for SGLs must be 64 byte aligned.
  12386. * If you are going to map 2 SGL's then the first one must have 256 entries
  12387. * the second sgl can have between 1 and 256 entries.
  12388. *
  12389. * Return codes:
  12390. * 0 - Success
  12391. * -ENXIO, -ENOMEM - Failure
  12392. **/
  12393. int
  12394. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  12395. dma_addr_t pdma_phys_addr0,
  12396. dma_addr_t pdma_phys_addr1,
  12397. uint16_t xritag)
  12398. {
  12399. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  12400. LPFC_MBOXQ_t *mbox;
  12401. int rc;
  12402. uint32_t shdr_status, shdr_add_status;
  12403. uint32_t mbox_tmo;
  12404. union lpfc_sli4_cfg_shdr *shdr;
  12405. if (xritag == NO_XRI) {
  12406. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12407. "0364 Invalid param:\n");
  12408. return -EINVAL;
  12409. }
  12410. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12411. if (!mbox)
  12412. return -ENOMEM;
  12413. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12414. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12415. sizeof(struct lpfc_mbx_post_sgl_pages) -
  12416. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  12417. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  12418. &mbox->u.mqe.un.post_sgl_pages;
  12419. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  12420. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  12421. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  12422. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  12423. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  12424. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  12425. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  12426. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  12427. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  12428. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  12429. if (!phba->sli4_hba.intr_enable)
  12430. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12431. else {
  12432. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12433. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12434. }
  12435. /* The IOCTL status is embedded in the mailbox subheader. */
  12436. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  12437. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12438. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12439. if (rc != MBX_TIMEOUT)
  12440. mempool_free(mbox, phba->mbox_mem_pool);
  12441. if (shdr_status || shdr_add_status || rc) {
  12442. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12443. "2511 POST_SGL mailbox failed with "
  12444. "status x%x add_status x%x, mbx status x%x\n",
  12445. shdr_status, shdr_add_status, rc);
  12446. rc = -ENXIO;
  12447. }
  12448. return 0;
  12449. }
  12450. /**
  12451. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  12452. * @phba: pointer to lpfc hba data structure.
  12453. *
  12454. * This routine is invoked to post rpi header templates to the
  12455. * HBA consistent with the SLI-4 interface spec. This routine
  12456. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  12457. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  12458. *
  12459. * Returns
  12460. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  12461. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  12462. **/
  12463. uint16_t
  12464. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  12465. {
  12466. unsigned long xri;
  12467. /*
  12468. * Fetch the next logical xri. Because this index is logical,
  12469. * the driver starts at 0 each time.
  12470. */
  12471. spin_lock_irq(&phba->hbalock);
  12472. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  12473. phba->sli4_hba.max_cfg_param.max_xri, 0);
  12474. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  12475. spin_unlock_irq(&phba->hbalock);
  12476. return NO_XRI;
  12477. } else {
  12478. set_bit(xri, phba->sli4_hba.xri_bmask);
  12479. phba->sli4_hba.max_cfg_param.xri_used++;
  12480. }
  12481. spin_unlock_irq(&phba->hbalock);
  12482. return xri;
  12483. }
  12484. /**
  12485. * lpfc_sli4_free_xri - Release an xri for reuse.
  12486. * @phba: pointer to lpfc hba data structure.
  12487. *
  12488. * This routine is invoked to release an xri to the pool of
  12489. * available rpis maintained by the driver.
  12490. **/
  12491. void
  12492. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12493. {
  12494. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  12495. phba->sli4_hba.max_cfg_param.xri_used--;
  12496. }
  12497. }
  12498. /**
  12499. * lpfc_sli4_free_xri - Release an xri for reuse.
  12500. * @phba: pointer to lpfc hba data structure.
  12501. *
  12502. * This routine is invoked to release an xri to the pool of
  12503. * available rpis maintained by the driver.
  12504. **/
  12505. void
  12506. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12507. {
  12508. spin_lock_irq(&phba->hbalock);
  12509. __lpfc_sli4_free_xri(phba, xri);
  12510. spin_unlock_irq(&phba->hbalock);
  12511. }
  12512. /**
  12513. * lpfc_sli4_next_xritag - Get an xritag for the io
  12514. * @phba: Pointer to HBA context object.
  12515. *
  12516. * This function gets an xritag for the iocb. If there is no unused xritag
  12517. * it will return 0xffff.
  12518. * The function returns the allocated xritag if successful, else returns zero.
  12519. * Zero is not a valid xritag.
  12520. * The caller is not required to hold any lock.
  12521. **/
  12522. uint16_t
  12523. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  12524. {
  12525. uint16_t xri_index;
  12526. xri_index = lpfc_sli4_alloc_xri(phba);
  12527. if (xri_index == NO_XRI)
  12528. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  12529. "2004 Failed to allocate XRI.last XRITAG is %d"
  12530. " Max XRI is %d, Used XRI is %d\n",
  12531. xri_index,
  12532. phba->sli4_hba.max_cfg_param.max_xri,
  12533. phba->sli4_hba.max_cfg_param.xri_used);
  12534. return xri_index;
  12535. }
  12536. /**
  12537. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  12538. * @phba: pointer to lpfc hba data structure.
  12539. * @post_sgl_list: pointer to els sgl entry list.
  12540. * @count: number of els sgl entries on the list.
  12541. *
  12542. * This routine is invoked to post a block of driver's sgl pages to the
  12543. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12544. * is only called when the driver is loading and after all IO has been
  12545. * stopped.
  12546. **/
  12547. static int
  12548. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  12549. struct list_head *post_sgl_list,
  12550. int post_cnt)
  12551. {
  12552. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  12553. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12554. struct sgl_page_pairs *sgl_pg_pairs;
  12555. void *viraddr;
  12556. LPFC_MBOXQ_t *mbox;
  12557. uint32_t reqlen, alloclen, pg_pairs;
  12558. uint32_t mbox_tmo;
  12559. uint16_t xritag_start = 0;
  12560. int rc = 0;
  12561. uint32_t shdr_status, shdr_add_status;
  12562. union lpfc_sli4_cfg_shdr *shdr;
  12563. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12564. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12565. if (reqlen > SLI4_PAGE_SIZE) {
  12566. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12567. "2559 Block sgl registration required DMA "
  12568. "size (%d) great than a page\n", reqlen);
  12569. return -ENOMEM;
  12570. }
  12571. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12572. if (!mbox)
  12573. return -ENOMEM;
  12574. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12575. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12576. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12577. LPFC_SLI4_MBX_NEMBED);
  12578. if (alloclen < reqlen) {
  12579. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12580. "0285 Allocated DMA memory size (%d) is "
  12581. "less than the requested DMA memory "
  12582. "size (%d)\n", alloclen, reqlen);
  12583. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12584. return -ENOMEM;
  12585. }
  12586. /* Set up the SGL pages in the non-embedded DMA pages */
  12587. viraddr = mbox->sge_array->addr[0];
  12588. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12589. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12590. pg_pairs = 0;
  12591. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  12592. /* Set up the sge entry */
  12593. sgl_pg_pairs->sgl_pg0_addr_lo =
  12594. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12595. sgl_pg_pairs->sgl_pg0_addr_hi =
  12596. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12597. sgl_pg_pairs->sgl_pg1_addr_lo =
  12598. cpu_to_le32(putPaddrLow(0));
  12599. sgl_pg_pairs->sgl_pg1_addr_hi =
  12600. cpu_to_le32(putPaddrHigh(0));
  12601. /* Keep the first xritag on the list */
  12602. if (pg_pairs == 0)
  12603. xritag_start = sglq_entry->sli4_xritag;
  12604. sgl_pg_pairs++;
  12605. pg_pairs++;
  12606. }
  12607. /* Complete initialization and perform endian conversion. */
  12608. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12609. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  12610. sgl->word0 = cpu_to_le32(sgl->word0);
  12611. if (!phba->sli4_hba.intr_enable)
  12612. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12613. else {
  12614. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12615. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12616. }
  12617. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12618. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12619. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12620. if (rc != MBX_TIMEOUT)
  12621. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12622. if (shdr_status || shdr_add_status || rc) {
  12623. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12624. "2513 POST_SGL_BLOCK mailbox command failed "
  12625. "status x%x add_status x%x mbx status x%x\n",
  12626. shdr_status, shdr_add_status, rc);
  12627. rc = -ENXIO;
  12628. }
  12629. return rc;
  12630. }
  12631. /**
  12632. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12633. * @phba: pointer to lpfc hba data structure.
  12634. * @sblist: pointer to scsi buffer list.
  12635. * @count: number of scsi buffers on the list.
  12636. *
  12637. * This routine is invoked to post a block of @count scsi sgl pages from a
  12638. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12639. * No Lock is held.
  12640. *
  12641. **/
  12642. int
  12643. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  12644. struct list_head *sblist,
  12645. int count)
  12646. {
  12647. struct lpfc_scsi_buf *psb;
  12648. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12649. struct sgl_page_pairs *sgl_pg_pairs;
  12650. void *viraddr;
  12651. LPFC_MBOXQ_t *mbox;
  12652. uint32_t reqlen, alloclen, pg_pairs;
  12653. uint32_t mbox_tmo;
  12654. uint16_t xritag_start = 0;
  12655. int rc = 0;
  12656. uint32_t shdr_status, shdr_add_status;
  12657. dma_addr_t pdma_phys_bpl1;
  12658. union lpfc_sli4_cfg_shdr *shdr;
  12659. /* Calculate the requested length of the dma memory */
  12660. reqlen = count * sizeof(struct sgl_page_pairs) +
  12661. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12662. if (reqlen > SLI4_PAGE_SIZE) {
  12663. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12664. "0217 Block sgl registration required DMA "
  12665. "size (%d) great than a page\n", reqlen);
  12666. return -ENOMEM;
  12667. }
  12668. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12669. if (!mbox) {
  12670. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12671. "0283 Failed to allocate mbox cmd memory\n");
  12672. return -ENOMEM;
  12673. }
  12674. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12675. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12676. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12677. LPFC_SLI4_MBX_NEMBED);
  12678. if (alloclen < reqlen) {
  12679. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12680. "2561 Allocated DMA memory size (%d) is "
  12681. "less than the requested DMA memory "
  12682. "size (%d)\n", alloclen, reqlen);
  12683. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12684. return -ENOMEM;
  12685. }
  12686. /* Get the first SGE entry from the non-embedded DMA memory */
  12687. viraddr = mbox->sge_array->addr[0];
  12688. /* Set up the SGL pages in the non-embedded DMA pages */
  12689. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12690. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12691. pg_pairs = 0;
  12692. list_for_each_entry(psb, sblist, list) {
  12693. /* Set up the sge entry */
  12694. sgl_pg_pairs->sgl_pg0_addr_lo =
  12695. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12696. sgl_pg_pairs->sgl_pg0_addr_hi =
  12697. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12698. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12699. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12700. else
  12701. pdma_phys_bpl1 = 0;
  12702. sgl_pg_pairs->sgl_pg1_addr_lo =
  12703. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12704. sgl_pg_pairs->sgl_pg1_addr_hi =
  12705. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12706. /* Keep the first xritag on the list */
  12707. if (pg_pairs == 0)
  12708. xritag_start = psb->cur_iocbq.sli4_xritag;
  12709. sgl_pg_pairs++;
  12710. pg_pairs++;
  12711. }
  12712. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12713. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12714. /* Perform endian conversion if necessary */
  12715. sgl->word0 = cpu_to_le32(sgl->word0);
  12716. if (!phba->sli4_hba.intr_enable)
  12717. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12718. else {
  12719. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12720. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12721. }
  12722. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12723. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12724. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12725. if (rc != MBX_TIMEOUT)
  12726. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12727. if (shdr_status || shdr_add_status || rc) {
  12728. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12729. "2564 POST_SGL_BLOCK mailbox command failed "
  12730. "status x%x add_status x%x mbx status x%x\n",
  12731. shdr_status, shdr_add_status, rc);
  12732. rc = -ENXIO;
  12733. }
  12734. return rc;
  12735. }
  12736. /**
  12737. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12738. * @phba: pointer to lpfc_hba struct that the frame was received on
  12739. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12740. *
  12741. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12742. * valid type of frame that the LPFC driver will handle. This function will
  12743. * return a zero if the frame is a valid frame or a non zero value when the
  12744. * frame does not pass the check.
  12745. **/
  12746. static int
  12747. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12748. {
  12749. /* make rctl_names static to save stack space */
  12750. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12751. char *type_names[] = FC_TYPE_NAMES_INIT;
  12752. struct fc_vft_header *fc_vft_hdr;
  12753. uint32_t *header = (uint32_t *) fc_hdr;
  12754. switch (fc_hdr->fh_r_ctl) {
  12755. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12756. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12757. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12758. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12759. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12760. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12761. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12762. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12763. case FC_RCTL_ELS_REQ: /* extended link services request */
  12764. case FC_RCTL_ELS_REP: /* extended link services reply */
  12765. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12766. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12767. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12768. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12769. case FC_RCTL_BA_RMC: /* remove connection */
  12770. case FC_RCTL_BA_ACC: /* basic accept */
  12771. case FC_RCTL_BA_RJT: /* basic reject */
  12772. case FC_RCTL_BA_PRMT:
  12773. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12774. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12775. case FC_RCTL_P_RJT: /* port reject */
  12776. case FC_RCTL_F_RJT: /* fabric reject */
  12777. case FC_RCTL_P_BSY: /* port busy */
  12778. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12779. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12780. case FC_RCTL_LCR: /* link credit reset */
  12781. case FC_RCTL_END: /* end */
  12782. break;
  12783. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12784. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12785. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12786. return lpfc_fc_frame_check(phba, fc_hdr);
  12787. default:
  12788. goto drop;
  12789. }
  12790. switch (fc_hdr->fh_type) {
  12791. case FC_TYPE_BLS:
  12792. case FC_TYPE_ELS:
  12793. case FC_TYPE_FCP:
  12794. case FC_TYPE_CT:
  12795. break;
  12796. case FC_TYPE_IP:
  12797. case FC_TYPE_ILS:
  12798. default:
  12799. goto drop;
  12800. }
  12801. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12802. "2538 Received frame rctl:%s type:%s "
  12803. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12804. rctl_names[fc_hdr->fh_r_ctl],
  12805. type_names[fc_hdr->fh_type],
  12806. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12807. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12808. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12809. return 0;
  12810. drop:
  12811. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12812. "2539 Dropped frame rctl:%s type:%s\n",
  12813. rctl_names[fc_hdr->fh_r_ctl],
  12814. type_names[fc_hdr->fh_type]);
  12815. return 1;
  12816. }
  12817. /**
  12818. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12819. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12820. *
  12821. * This function processes the FC header to retrieve the VFI from the VF
  12822. * header, if one exists. This function will return the VFI if one exists
  12823. * or 0 if no VSAN Header exists.
  12824. **/
  12825. static uint32_t
  12826. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12827. {
  12828. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12829. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12830. return 0;
  12831. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12832. }
  12833. /**
  12834. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12835. * @phba: Pointer to the HBA structure to search for the vport on
  12836. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12837. * @fcfi: The FC Fabric ID that the frame came from
  12838. *
  12839. * This function searches the @phba for a vport that matches the content of the
  12840. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12841. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12842. * returns the matching vport pointer or NULL if unable to match frame to a
  12843. * vport.
  12844. **/
  12845. static struct lpfc_vport *
  12846. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12847. uint16_t fcfi)
  12848. {
  12849. struct lpfc_vport **vports;
  12850. struct lpfc_vport *vport = NULL;
  12851. int i;
  12852. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12853. fc_hdr->fh_d_id[1] << 8 |
  12854. fc_hdr->fh_d_id[2]);
  12855. if (did == Fabric_DID)
  12856. return phba->pport;
  12857. if ((phba->pport->fc_flag & FC_PT2PT) &&
  12858. !(phba->link_state == LPFC_HBA_READY))
  12859. return phba->pport;
  12860. vports = lpfc_create_vport_work_array(phba);
  12861. if (vports != NULL)
  12862. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12863. if (phba->fcf.fcfi == fcfi &&
  12864. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12865. vports[i]->fc_myDID == did) {
  12866. vport = vports[i];
  12867. break;
  12868. }
  12869. }
  12870. lpfc_destroy_vport_work_array(phba, vports);
  12871. return vport;
  12872. }
  12873. /**
  12874. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12875. * @vport: The vport to work on.
  12876. *
  12877. * This function updates the receive sequence time stamp for this vport. The
  12878. * receive sequence time stamp indicates the time that the last frame of the
  12879. * the sequence that has been idle for the longest amount of time was received.
  12880. * the driver uses this time stamp to indicate if any received sequences have
  12881. * timed out.
  12882. **/
  12883. void
  12884. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12885. {
  12886. struct lpfc_dmabuf *h_buf;
  12887. struct hbq_dmabuf *dmabuf = NULL;
  12888. /* get the oldest sequence on the rcv list */
  12889. h_buf = list_get_first(&vport->rcv_buffer_list,
  12890. struct lpfc_dmabuf, list);
  12891. if (!h_buf)
  12892. return;
  12893. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12894. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12895. }
  12896. /**
  12897. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12898. * @vport: The vport that the received sequences were sent to.
  12899. *
  12900. * This function cleans up all outstanding received sequences. This is called
  12901. * by the driver when a link event or user action invalidates all the received
  12902. * sequences.
  12903. **/
  12904. void
  12905. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12906. {
  12907. struct lpfc_dmabuf *h_buf, *hnext;
  12908. struct lpfc_dmabuf *d_buf, *dnext;
  12909. struct hbq_dmabuf *dmabuf = NULL;
  12910. /* start with the oldest sequence on the rcv list */
  12911. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12912. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12913. list_del_init(&dmabuf->hbuf.list);
  12914. list_for_each_entry_safe(d_buf, dnext,
  12915. &dmabuf->dbuf.list, list) {
  12916. list_del_init(&d_buf->list);
  12917. lpfc_in_buf_free(vport->phba, d_buf);
  12918. }
  12919. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12920. }
  12921. }
  12922. /**
  12923. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12924. * @vport: The vport that the received sequences were sent to.
  12925. *
  12926. * This function determines whether any received sequences have timed out by
  12927. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12928. * indicates that there is at least one timed out sequence this routine will
  12929. * go through the received sequences one at a time from most inactive to most
  12930. * active to determine which ones need to be cleaned up. Once it has determined
  12931. * that a sequence needs to be cleaned up it will simply free up the resources
  12932. * without sending an abort.
  12933. **/
  12934. void
  12935. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12936. {
  12937. struct lpfc_dmabuf *h_buf, *hnext;
  12938. struct lpfc_dmabuf *d_buf, *dnext;
  12939. struct hbq_dmabuf *dmabuf = NULL;
  12940. unsigned long timeout;
  12941. int abort_count = 0;
  12942. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12943. vport->rcv_buffer_time_stamp);
  12944. if (list_empty(&vport->rcv_buffer_list) ||
  12945. time_before(jiffies, timeout))
  12946. return;
  12947. /* start with the oldest sequence on the rcv list */
  12948. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12949. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12950. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12951. dmabuf->time_stamp);
  12952. if (time_before(jiffies, timeout))
  12953. break;
  12954. abort_count++;
  12955. list_del_init(&dmabuf->hbuf.list);
  12956. list_for_each_entry_safe(d_buf, dnext,
  12957. &dmabuf->dbuf.list, list) {
  12958. list_del_init(&d_buf->list);
  12959. lpfc_in_buf_free(vport->phba, d_buf);
  12960. }
  12961. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12962. }
  12963. if (abort_count)
  12964. lpfc_update_rcv_time_stamp(vport);
  12965. }
  12966. /**
  12967. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12968. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12969. *
  12970. * This function searches through the existing incomplete sequences that have
  12971. * been sent to this @vport. If the frame matches one of the incomplete
  12972. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12973. * make up that sequence. If no sequence is found that matches this frame then
  12974. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12975. * This function returns a pointer to the first dmabuf in the sequence list that
  12976. * the frame was linked to.
  12977. **/
  12978. static struct hbq_dmabuf *
  12979. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12980. {
  12981. struct fc_frame_header *new_hdr;
  12982. struct fc_frame_header *temp_hdr;
  12983. struct lpfc_dmabuf *d_buf;
  12984. struct lpfc_dmabuf *h_buf;
  12985. struct hbq_dmabuf *seq_dmabuf = NULL;
  12986. struct hbq_dmabuf *temp_dmabuf = NULL;
  12987. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12988. dmabuf->time_stamp = jiffies;
  12989. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12990. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12991. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12992. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12993. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12994. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12995. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12996. continue;
  12997. /* found a pending sequence that matches this frame */
  12998. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12999. break;
  13000. }
  13001. if (!seq_dmabuf) {
  13002. /*
  13003. * This indicates first frame received for this sequence.
  13004. * Queue the buffer on the vport's rcv_buffer_list.
  13005. */
  13006. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13007. lpfc_update_rcv_time_stamp(vport);
  13008. return dmabuf;
  13009. }
  13010. temp_hdr = seq_dmabuf->hbuf.virt;
  13011. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  13012. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13013. list_del_init(&seq_dmabuf->hbuf.list);
  13014. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13015. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13016. lpfc_update_rcv_time_stamp(vport);
  13017. return dmabuf;
  13018. }
  13019. /* move this sequence to the tail to indicate a young sequence */
  13020. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  13021. seq_dmabuf->time_stamp = jiffies;
  13022. lpfc_update_rcv_time_stamp(vport);
  13023. if (list_empty(&seq_dmabuf->dbuf.list)) {
  13024. temp_hdr = dmabuf->hbuf.virt;
  13025. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  13026. return seq_dmabuf;
  13027. }
  13028. /* find the correct place in the sequence to insert this frame */
  13029. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  13030. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13031. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  13032. /*
  13033. * If the frame's sequence count is greater than the frame on
  13034. * the list then insert the frame right after this frame
  13035. */
  13036. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  13037. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  13038. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  13039. return seq_dmabuf;
  13040. }
  13041. }
  13042. return NULL;
  13043. }
  13044. /**
  13045. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  13046. * @vport: pointer to a vitural port
  13047. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13048. *
  13049. * This function tries to abort from the partially assembed sequence, described
  13050. * by the information from basic abbort @dmabuf. It checks to see whether such
  13051. * partially assembled sequence held by the driver. If so, it shall free up all
  13052. * the frames from the partially assembled sequence.
  13053. *
  13054. * Return
  13055. * true -- if there is matching partially assembled sequence present and all
  13056. * the frames freed with the sequence;
  13057. * false -- if there is no matching partially assembled sequence present so
  13058. * nothing got aborted in the lower layer driver
  13059. **/
  13060. static bool
  13061. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  13062. struct hbq_dmabuf *dmabuf)
  13063. {
  13064. struct fc_frame_header *new_hdr;
  13065. struct fc_frame_header *temp_hdr;
  13066. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  13067. struct hbq_dmabuf *seq_dmabuf = NULL;
  13068. /* Use the hdr_buf to find the sequence that matches this frame */
  13069. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  13070. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  13071. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13072. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  13073. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  13074. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  13075. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  13076. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  13077. continue;
  13078. /* found a pending sequence that matches this frame */
  13079. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  13080. break;
  13081. }
  13082. /* Free up all the frames from the partially assembled sequence */
  13083. if (seq_dmabuf) {
  13084. list_for_each_entry_safe(d_buf, n_buf,
  13085. &seq_dmabuf->dbuf.list, list) {
  13086. list_del_init(&d_buf->list);
  13087. lpfc_in_buf_free(vport->phba, d_buf);
  13088. }
  13089. return true;
  13090. }
  13091. return false;
  13092. }
  13093. /**
  13094. * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
  13095. * @vport: pointer to a vitural port
  13096. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13097. *
  13098. * This function tries to abort from the assembed sequence from upper level
  13099. * protocol, described by the information from basic abbort @dmabuf. It
  13100. * checks to see whether such pending context exists at upper level protocol.
  13101. * If so, it shall clean up the pending context.
  13102. *
  13103. * Return
  13104. * true -- if there is matching pending context of the sequence cleaned
  13105. * at ulp;
  13106. * false -- if there is no matching pending context of the sequence present
  13107. * at ulp.
  13108. **/
  13109. static bool
  13110. lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  13111. {
  13112. struct lpfc_hba *phba = vport->phba;
  13113. int handled;
  13114. /* Accepting abort at ulp with SLI4 only */
  13115. if (phba->sli_rev < LPFC_SLI_REV4)
  13116. return false;
  13117. /* Register all caring upper level protocols to attend abort */
  13118. handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
  13119. if (handled)
  13120. return true;
  13121. return false;
  13122. }
  13123. /**
  13124. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  13125. * @phba: Pointer to HBA context object.
  13126. * @cmd_iocbq: pointer to the command iocbq structure.
  13127. * @rsp_iocbq: pointer to the response iocbq structure.
  13128. *
  13129. * This function handles the sequence abort response iocb command complete
  13130. * event. It properly releases the memory allocated to the sequence abort
  13131. * accept iocb.
  13132. **/
  13133. static void
  13134. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  13135. struct lpfc_iocbq *cmd_iocbq,
  13136. struct lpfc_iocbq *rsp_iocbq)
  13137. {
  13138. struct lpfc_nodelist *ndlp;
  13139. if (cmd_iocbq) {
  13140. ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
  13141. lpfc_nlp_put(ndlp);
  13142. lpfc_nlp_not_used(ndlp);
  13143. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  13144. }
  13145. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  13146. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  13147. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13148. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  13149. rsp_iocbq->iocb.ulpStatus,
  13150. rsp_iocbq->iocb.un.ulpWord[4]);
  13151. }
  13152. /**
  13153. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  13154. * @phba: Pointer to HBA context object.
  13155. * @xri: xri id in transaction.
  13156. *
  13157. * This function validates the xri maps to the known range of XRIs allocated an
  13158. * used by the driver.
  13159. **/
  13160. uint16_t
  13161. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  13162. uint16_t xri)
  13163. {
  13164. int i;
  13165. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  13166. if (xri == phba->sli4_hba.xri_ids[i])
  13167. return i;
  13168. }
  13169. return NO_XRI;
  13170. }
  13171. /**
  13172. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  13173. * @phba: Pointer to HBA context object.
  13174. * @fc_hdr: pointer to a FC frame header.
  13175. *
  13176. * This function sends a basic response to a previous unsol sequence abort
  13177. * event after aborting the sequence handling.
  13178. **/
  13179. static void
  13180. lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
  13181. struct fc_frame_header *fc_hdr, bool aborted)
  13182. {
  13183. struct lpfc_hba *phba = vport->phba;
  13184. struct lpfc_iocbq *ctiocb = NULL;
  13185. struct lpfc_nodelist *ndlp;
  13186. uint16_t oxid, rxid, xri, lxri;
  13187. uint32_t sid, fctl;
  13188. IOCB_t *icmd;
  13189. int rc;
  13190. if (!lpfc_is_link_up(phba))
  13191. return;
  13192. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13193. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  13194. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  13195. ndlp = lpfc_findnode_did(vport, sid);
  13196. if (!ndlp) {
  13197. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  13198. if (!ndlp) {
  13199. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13200. "1268 Failed to allocate ndlp for "
  13201. "oxid:x%x SID:x%x\n", oxid, sid);
  13202. return;
  13203. }
  13204. lpfc_nlp_init(vport, ndlp, sid);
  13205. /* Put ndlp onto pport node list */
  13206. lpfc_enqueue_node(vport, ndlp);
  13207. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  13208. /* re-setup ndlp without removing from node list */
  13209. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  13210. if (!ndlp) {
  13211. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  13212. "3275 Failed to active ndlp found "
  13213. "for oxid:x%x SID:x%x\n", oxid, sid);
  13214. return;
  13215. }
  13216. }
  13217. /* Allocate buffer for rsp iocb */
  13218. ctiocb = lpfc_sli_get_iocbq(phba);
  13219. if (!ctiocb)
  13220. return;
  13221. /* Extract the F_CTL field from FC_HDR */
  13222. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  13223. icmd = &ctiocb->iocb;
  13224. icmd->un.xseq64.bdl.bdeSize = 0;
  13225. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  13226. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  13227. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  13228. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  13229. /* Fill in the rest of iocb fields */
  13230. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  13231. icmd->ulpBdeCount = 0;
  13232. icmd->ulpLe = 1;
  13233. icmd->ulpClass = CLASS3;
  13234. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  13235. ctiocb->context1 = lpfc_nlp_get(ndlp);
  13236. ctiocb->iocb_cmpl = NULL;
  13237. ctiocb->vport = phba->pport;
  13238. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  13239. ctiocb->sli4_lxritag = NO_XRI;
  13240. ctiocb->sli4_xritag = NO_XRI;
  13241. if (fctl & FC_FC_EX_CTX)
  13242. /* Exchange responder sent the abort so we
  13243. * own the oxid.
  13244. */
  13245. xri = oxid;
  13246. else
  13247. xri = rxid;
  13248. lxri = lpfc_sli4_xri_inrange(phba, xri);
  13249. if (lxri != NO_XRI)
  13250. lpfc_set_rrq_active(phba, ndlp, lxri,
  13251. (xri == oxid) ? rxid : oxid, 0);
  13252. /* For BA_ABTS from exchange responder, if the logical xri with
  13253. * the oxid maps to the FCP XRI range, the port no longer has
  13254. * that exchange context, send a BLS_RJT. Override the IOCB for
  13255. * a BA_RJT.
  13256. */
  13257. if ((fctl & FC_FC_EX_CTX) &&
  13258. (lxri > lpfc_sli4_get_els_iocb_cnt(phba))) {
  13259. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  13260. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  13261. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  13262. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  13263. }
  13264. /* If BA_ABTS failed to abort a partially assembled receive sequence,
  13265. * the driver no longer has that exchange, send a BLS_RJT. Override
  13266. * the IOCB for a BA_RJT.
  13267. */
  13268. if (aborted == false) {
  13269. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  13270. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  13271. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  13272. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  13273. }
  13274. if (fctl & FC_FC_EX_CTX) {
  13275. /* ABTS sent by responder to CT exchange, construction
  13276. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  13277. * field and RX_ID from ABTS for RX_ID field.
  13278. */
  13279. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  13280. } else {
  13281. /* ABTS sent by initiator to CT exchange, construction
  13282. * of BA_ACC will need to allocate a new XRI as for the
  13283. * XRI_TAG field.
  13284. */
  13285. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  13286. }
  13287. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  13288. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  13289. /* Xmit CT abts response on exchange <xid> */
  13290. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  13291. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  13292. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  13293. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  13294. if (rc == IOCB_ERROR) {
  13295. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  13296. "2925 Failed to issue CT ABTS RSP x%x on "
  13297. "xri x%x, Data x%x\n",
  13298. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  13299. phba->link_state);
  13300. lpfc_nlp_put(ndlp);
  13301. ctiocb->context1 = NULL;
  13302. lpfc_sli_release_iocbq(phba, ctiocb);
  13303. }
  13304. }
  13305. /**
  13306. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  13307. * @vport: Pointer to the vport on which this sequence was received
  13308. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13309. *
  13310. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  13311. * receive sequence is only partially assembed by the driver, it shall abort
  13312. * the partially assembled frames for the sequence. Otherwise, if the
  13313. * unsolicited receive sequence has been completely assembled and passed to
  13314. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  13315. * unsolicited sequence has been aborted. After that, it will issue a basic
  13316. * accept to accept the abort.
  13317. **/
  13318. void
  13319. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  13320. struct hbq_dmabuf *dmabuf)
  13321. {
  13322. struct lpfc_hba *phba = vport->phba;
  13323. struct fc_frame_header fc_hdr;
  13324. uint32_t fctl;
  13325. bool aborted;
  13326. /* Make a copy of fc_hdr before the dmabuf being released */
  13327. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  13328. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  13329. if (fctl & FC_FC_EX_CTX) {
  13330. /* ABTS by responder to exchange, no cleanup needed */
  13331. aborted = true;
  13332. } else {
  13333. /* ABTS by initiator to exchange, need to do cleanup */
  13334. aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  13335. if (aborted == false)
  13336. aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
  13337. }
  13338. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13339. /* Respond with BA_ACC or BA_RJT accordingly */
  13340. lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
  13341. }
  13342. /**
  13343. * lpfc_seq_complete - Indicates if a sequence is complete
  13344. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13345. *
  13346. * This function checks the sequence, starting with the frame described by
  13347. * @dmabuf, to see if all the frames associated with this sequence are present.
  13348. * the frames associated with this sequence are linked to the @dmabuf using the
  13349. * dbuf list. This function looks for two major things. 1) That the first frame
  13350. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  13351. * set. 3) That there are no holes in the sequence count. The function will
  13352. * return 1 when the sequence is complete, otherwise it will return 0.
  13353. **/
  13354. static int
  13355. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  13356. {
  13357. struct fc_frame_header *hdr;
  13358. struct lpfc_dmabuf *d_buf;
  13359. struct hbq_dmabuf *seq_dmabuf;
  13360. uint32_t fctl;
  13361. int seq_count = 0;
  13362. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13363. /* make sure first fame of sequence has a sequence count of zero */
  13364. if (hdr->fh_seq_cnt != seq_count)
  13365. return 0;
  13366. fctl = (hdr->fh_f_ctl[0] << 16 |
  13367. hdr->fh_f_ctl[1] << 8 |
  13368. hdr->fh_f_ctl[2]);
  13369. /* If last frame of sequence we can return success. */
  13370. if (fctl & FC_FC_END_SEQ)
  13371. return 1;
  13372. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  13373. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13374. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13375. /* If there is a hole in the sequence count then fail. */
  13376. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  13377. return 0;
  13378. fctl = (hdr->fh_f_ctl[0] << 16 |
  13379. hdr->fh_f_ctl[1] << 8 |
  13380. hdr->fh_f_ctl[2]);
  13381. /* If last frame of sequence we can return success. */
  13382. if (fctl & FC_FC_END_SEQ)
  13383. return 1;
  13384. }
  13385. return 0;
  13386. }
  13387. /**
  13388. * lpfc_prep_seq - Prep sequence for ULP processing
  13389. * @vport: Pointer to the vport on which this sequence was received
  13390. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13391. *
  13392. * This function takes a sequence, described by a list of frames, and creates
  13393. * a list of iocbq structures to describe the sequence. This iocbq list will be
  13394. * used to issue to the generic unsolicited sequence handler. This routine
  13395. * returns a pointer to the first iocbq in the list. If the function is unable
  13396. * to allocate an iocbq then it throw out the received frames that were not
  13397. * able to be described and return a pointer to the first iocbq. If unable to
  13398. * allocate any iocbqs (including the first) this function will return NULL.
  13399. **/
  13400. static struct lpfc_iocbq *
  13401. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  13402. {
  13403. struct hbq_dmabuf *hbq_buf;
  13404. struct lpfc_dmabuf *d_buf, *n_buf;
  13405. struct lpfc_iocbq *first_iocbq, *iocbq;
  13406. struct fc_frame_header *fc_hdr;
  13407. uint32_t sid;
  13408. uint32_t len, tot_len;
  13409. struct ulp_bde64 *pbde;
  13410. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13411. /* remove from receive buffer list */
  13412. list_del_init(&seq_dmabuf->hbuf.list);
  13413. lpfc_update_rcv_time_stamp(vport);
  13414. /* get the Remote Port's SID */
  13415. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13416. tot_len = 0;
  13417. /* Get an iocbq struct to fill in. */
  13418. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13419. if (first_iocbq) {
  13420. /* Initialize the first IOCB. */
  13421. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13422. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13423. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  13424. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  13425. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  13426. first_iocbq->iocb.un.rcvels.parmRo =
  13427. sli4_did_from_fc_hdr(fc_hdr);
  13428. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  13429. } else
  13430. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13431. first_iocbq->iocb.ulpContext = NO_XRI;
  13432. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13433. be16_to_cpu(fc_hdr->fh_ox_id);
  13434. /* iocbq is prepped for internal consumption. Physical vpi. */
  13435. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13436. vport->phba->vpi_ids[vport->vpi];
  13437. /* put the first buffer into the first IOCBq */
  13438. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13439. first_iocbq->context3 = NULL;
  13440. first_iocbq->iocb.ulpBdeCount = 1;
  13441. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13442. LPFC_DATA_BUF_SIZE;
  13443. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13444. tot_len = bf_get(lpfc_rcqe_length,
  13445. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13446. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13447. }
  13448. iocbq = first_iocbq;
  13449. /*
  13450. * Each IOCBq can have two Buffers assigned, so go through the list
  13451. * of buffers for this sequence and save two buffers in each IOCBq
  13452. */
  13453. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13454. if (!iocbq) {
  13455. lpfc_in_buf_free(vport->phba, d_buf);
  13456. continue;
  13457. }
  13458. if (!iocbq->context3) {
  13459. iocbq->context3 = d_buf;
  13460. iocbq->iocb.ulpBdeCount++;
  13461. pbde = (struct ulp_bde64 *)
  13462. &iocbq->iocb.unsli3.sli3Words[4];
  13463. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13464. /* We need to get the size out of the right CQE */
  13465. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13466. len = bf_get(lpfc_rcqe_length,
  13467. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13468. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13469. tot_len += len;
  13470. } else {
  13471. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13472. if (!iocbq) {
  13473. if (first_iocbq) {
  13474. first_iocbq->iocb.ulpStatus =
  13475. IOSTAT_FCP_RSP_ERROR;
  13476. first_iocbq->iocb.un.ulpWord[4] =
  13477. IOERR_NO_RESOURCES;
  13478. }
  13479. lpfc_in_buf_free(vport->phba, d_buf);
  13480. continue;
  13481. }
  13482. iocbq->context2 = d_buf;
  13483. iocbq->context3 = NULL;
  13484. iocbq->iocb.ulpBdeCount = 1;
  13485. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13486. LPFC_DATA_BUF_SIZE;
  13487. /* We need to get the size out of the right CQE */
  13488. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13489. len = bf_get(lpfc_rcqe_length,
  13490. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13491. tot_len += len;
  13492. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13493. iocbq->iocb.un.rcvels.remoteID = sid;
  13494. list_add_tail(&iocbq->list, &first_iocbq->list);
  13495. }
  13496. }
  13497. return first_iocbq;
  13498. }
  13499. static void
  13500. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13501. struct hbq_dmabuf *seq_dmabuf)
  13502. {
  13503. struct fc_frame_header *fc_hdr;
  13504. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13505. struct lpfc_hba *phba = vport->phba;
  13506. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13507. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13508. if (!iocbq) {
  13509. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13510. "2707 Ring %d handler: Failed to allocate "
  13511. "iocb Rctl x%x Type x%x received\n",
  13512. LPFC_ELS_RING,
  13513. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13514. return;
  13515. }
  13516. if (!lpfc_complete_unsol_iocb(phba,
  13517. &phba->sli.ring[LPFC_ELS_RING],
  13518. iocbq, fc_hdr->fh_r_ctl,
  13519. fc_hdr->fh_type))
  13520. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13521. "2540 Ring %d handler: unexpected Rctl "
  13522. "x%x Type x%x received\n",
  13523. LPFC_ELS_RING,
  13524. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13525. /* Free iocb created in lpfc_prep_seq */
  13526. list_for_each_entry_safe(curr_iocb, next_iocb,
  13527. &iocbq->list, list) {
  13528. list_del_init(&curr_iocb->list);
  13529. lpfc_sli_release_iocbq(phba, curr_iocb);
  13530. }
  13531. lpfc_sli_release_iocbq(phba, iocbq);
  13532. }
  13533. /**
  13534. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13535. * @phba: Pointer to HBA context object.
  13536. *
  13537. * This function is called with no lock held. This function processes all
  13538. * the received buffers and gives it to upper layers when a received buffer
  13539. * indicates that it is the final frame in the sequence. The interrupt
  13540. * service routine processes received buffers at interrupt contexts and adds
  13541. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13542. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13543. * appropriate receive function when the final frame in a sequence is received.
  13544. **/
  13545. void
  13546. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13547. struct hbq_dmabuf *dmabuf)
  13548. {
  13549. struct hbq_dmabuf *seq_dmabuf;
  13550. struct fc_frame_header *fc_hdr;
  13551. struct lpfc_vport *vport;
  13552. uint32_t fcfi;
  13553. uint32_t did;
  13554. /* Process each received buffer */
  13555. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13556. /* check to see if this a valid type of frame */
  13557. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13558. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13559. return;
  13560. }
  13561. if ((bf_get(lpfc_cqe_code,
  13562. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13563. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13564. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13565. else
  13566. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13567. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13568. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13569. if (!vport) {
  13570. /* throw out the frame */
  13571. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13572. return;
  13573. }
  13574. /* d_id this frame is directed to */
  13575. did = sli4_did_from_fc_hdr(fc_hdr);
  13576. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  13577. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  13578. (did != Fabric_DID)) {
  13579. /*
  13580. * Throw out the frame if we are not pt2pt.
  13581. * The pt2pt protocol allows for discovery frames
  13582. * to be received without a registered VPI.
  13583. */
  13584. if (!(vport->fc_flag & FC_PT2PT) ||
  13585. (phba->link_state == LPFC_HBA_READY)) {
  13586. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13587. return;
  13588. }
  13589. }
  13590. /* Handle the basic abort sequence (BA_ABTS) event */
  13591. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13592. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13593. return;
  13594. }
  13595. /* Link this frame */
  13596. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13597. if (!seq_dmabuf) {
  13598. /* unable to add frame to vport - throw it out */
  13599. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13600. return;
  13601. }
  13602. /* If not last frame in sequence continue processing frames. */
  13603. if (!lpfc_seq_complete(seq_dmabuf))
  13604. return;
  13605. /* Send the complete sequence to the upper layer protocol */
  13606. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13607. }
  13608. /**
  13609. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13610. * @phba: pointer to lpfc hba data structure.
  13611. *
  13612. * This routine is invoked to post rpi header templates to the
  13613. * HBA consistent with the SLI-4 interface spec. This routine
  13614. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13615. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13616. *
  13617. * This routine does not require any locks. It's usage is expected
  13618. * to be driver load or reset recovery when the driver is
  13619. * sequential.
  13620. *
  13621. * Return codes
  13622. * 0 - successful
  13623. * -EIO - The mailbox failed to complete successfully.
  13624. * When this error occurs, the driver is not guaranteed
  13625. * to have any rpi regions posted to the device and
  13626. * must either attempt to repost the regions or take a
  13627. * fatal error.
  13628. **/
  13629. int
  13630. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13631. {
  13632. struct lpfc_rpi_hdr *rpi_page;
  13633. uint32_t rc = 0;
  13634. uint16_t lrpi = 0;
  13635. /* SLI4 ports that support extents do not require RPI headers. */
  13636. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13637. goto exit;
  13638. if (phba->sli4_hba.extents_in_use)
  13639. return -EIO;
  13640. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13641. /*
  13642. * Assign the rpi headers a physical rpi only if the driver
  13643. * has not initialized those resources. A port reset only
  13644. * needs the headers posted.
  13645. */
  13646. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13647. LPFC_RPI_RSRC_RDY)
  13648. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13649. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13650. if (rc != MBX_SUCCESS) {
  13651. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13652. "2008 Error %d posting all rpi "
  13653. "headers\n", rc);
  13654. rc = -EIO;
  13655. break;
  13656. }
  13657. }
  13658. exit:
  13659. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13660. LPFC_RPI_RSRC_RDY);
  13661. return rc;
  13662. }
  13663. /**
  13664. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13665. * @phba: pointer to lpfc hba data structure.
  13666. * @rpi_page: pointer to the rpi memory region.
  13667. *
  13668. * This routine is invoked to post a single rpi header to the
  13669. * HBA consistent with the SLI-4 interface spec. This memory region
  13670. * maps up to 64 rpi context regions.
  13671. *
  13672. * Return codes
  13673. * 0 - successful
  13674. * -ENOMEM - No available memory
  13675. * -EIO - The mailbox failed to complete successfully.
  13676. **/
  13677. int
  13678. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13679. {
  13680. LPFC_MBOXQ_t *mboxq;
  13681. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13682. uint32_t rc = 0;
  13683. uint32_t shdr_status, shdr_add_status;
  13684. union lpfc_sli4_cfg_shdr *shdr;
  13685. /* SLI4 ports that support extents do not require RPI headers. */
  13686. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13687. return rc;
  13688. if (phba->sli4_hba.extents_in_use)
  13689. return -EIO;
  13690. /* The port is notified of the header region via a mailbox command. */
  13691. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13692. if (!mboxq) {
  13693. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13694. "2001 Unable to allocate memory for issuing "
  13695. "SLI_CONFIG_SPECIAL mailbox command\n");
  13696. return -ENOMEM;
  13697. }
  13698. /* Post all rpi memory regions to the port. */
  13699. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13700. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13701. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13702. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13703. sizeof(struct lpfc_sli4_cfg_mhdr),
  13704. LPFC_SLI4_MBX_EMBED);
  13705. /* Post the physical rpi to the port for this rpi header. */
  13706. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13707. rpi_page->start_rpi);
  13708. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13709. hdr_tmpl, rpi_page->page_count);
  13710. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13711. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13712. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13713. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13714. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13715. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13716. if (rc != MBX_TIMEOUT)
  13717. mempool_free(mboxq, phba->mbox_mem_pool);
  13718. if (shdr_status || shdr_add_status || rc) {
  13719. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13720. "2514 POST_RPI_HDR mailbox failed with "
  13721. "status x%x add_status x%x, mbx status x%x\n",
  13722. shdr_status, shdr_add_status, rc);
  13723. rc = -ENXIO;
  13724. }
  13725. return rc;
  13726. }
  13727. /**
  13728. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13729. * @phba: pointer to lpfc hba data structure.
  13730. *
  13731. * This routine is invoked to post rpi header templates to the
  13732. * HBA consistent with the SLI-4 interface spec. This routine
  13733. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13734. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13735. *
  13736. * Returns
  13737. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13738. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13739. **/
  13740. int
  13741. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13742. {
  13743. unsigned long rpi;
  13744. uint16_t max_rpi, rpi_limit;
  13745. uint16_t rpi_remaining, lrpi = 0;
  13746. struct lpfc_rpi_hdr *rpi_hdr;
  13747. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13748. rpi_limit = phba->sli4_hba.next_rpi;
  13749. /*
  13750. * Fetch the next logical rpi. Because this index is logical,
  13751. * the driver starts at 0 each time.
  13752. */
  13753. spin_lock_irq(&phba->hbalock);
  13754. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13755. if (rpi >= rpi_limit)
  13756. rpi = LPFC_RPI_ALLOC_ERROR;
  13757. else {
  13758. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13759. phba->sli4_hba.max_cfg_param.rpi_used++;
  13760. phba->sli4_hba.rpi_count++;
  13761. }
  13762. /*
  13763. * Don't try to allocate more rpi header regions if the device limit
  13764. * has been exhausted.
  13765. */
  13766. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13767. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13768. spin_unlock_irq(&phba->hbalock);
  13769. return rpi;
  13770. }
  13771. /*
  13772. * RPI header postings are not required for SLI4 ports capable of
  13773. * extents.
  13774. */
  13775. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13776. spin_unlock_irq(&phba->hbalock);
  13777. return rpi;
  13778. }
  13779. /*
  13780. * If the driver is running low on rpi resources, allocate another
  13781. * page now. Note that the next_rpi value is used because
  13782. * it represents how many are actually in use whereas max_rpi notes
  13783. * how many are supported max by the device.
  13784. */
  13785. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13786. spin_unlock_irq(&phba->hbalock);
  13787. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13788. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13789. if (!rpi_hdr) {
  13790. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13791. "2002 Error Could not grow rpi "
  13792. "count\n");
  13793. } else {
  13794. lrpi = rpi_hdr->start_rpi;
  13795. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13796. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13797. }
  13798. }
  13799. return rpi;
  13800. }
  13801. /**
  13802. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13803. * @phba: pointer to lpfc hba data structure.
  13804. *
  13805. * This routine is invoked to release an rpi to the pool of
  13806. * available rpis maintained by the driver.
  13807. **/
  13808. void
  13809. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13810. {
  13811. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13812. phba->sli4_hba.rpi_count--;
  13813. phba->sli4_hba.max_cfg_param.rpi_used--;
  13814. }
  13815. }
  13816. /**
  13817. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13818. * @phba: pointer to lpfc hba data structure.
  13819. *
  13820. * This routine is invoked to release an rpi to the pool of
  13821. * available rpis maintained by the driver.
  13822. **/
  13823. void
  13824. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13825. {
  13826. spin_lock_irq(&phba->hbalock);
  13827. __lpfc_sli4_free_rpi(phba, rpi);
  13828. spin_unlock_irq(&phba->hbalock);
  13829. }
  13830. /**
  13831. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13832. * @phba: pointer to lpfc hba data structure.
  13833. *
  13834. * This routine is invoked to remove the memory region that
  13835. * provided rpi via a bitmask.
  13836. **/
  13837. void
  13838. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13839. {
  13840. kfree(phba->sli4_hba.rpi_bmask);
  13841. kfree(phba->sli4_hba.rpi_ids);
  13842. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13843. }
  13844. /**
  13845. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13846. * @phba: pointer to lpfc hba data structure.
  13847. *
  13848. * This routine is invoked to remove the memory region that
  13849. * provided rpi via a bitmask.
  13850. **/
  13851. int
  13852. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  13853. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  13854. {
  13855. LPFC_MBOXQ_t *mboxq;
  13856. struct lpfc_hba *phba = ndlp->phba;
  13857. int rc;
  13858. /* The port is notified of the header region via a mailbox command. */
  13859. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13860. if (!mboxq)
  13861. return -ENOMEM;
  13862. /* Post all rpi memory regions to the port. */
  13863. lpfc_resume_rpi(mboxq, ndlp);
  13864. if (cmpl) {
  13865. mboxq->mbox_cmpl = cmpl;
  13866. mboxq->context1 = arg;
  13867. mboxq->context2 = ndlp;
  13868. } else
  13869. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13870. mboxq->vport = ndlp->vport;
  13871. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13872. if (rc == MBX_NOT_FINISHED) {
  13873. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13874. "2010 Resume RPI Mailbox failed "
  13875. "status %d, mbxStatus x%x\n", rc,
  13876. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13877. mempool_free(mboxq, phba->mbox_mem_pool);
  13878. return -EIO;
  13879. }
  13880. return 0;
  13881. }
  13882. /**
  13883. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13884. * @vport: Pointer to the vport for which the vpi is being initialized
  13885. *
  13886. * This routine is invoked to activate a vpi with the port.
  13887. *
  13888. * Returns:
  13889. * 0 success
  13890. * -Evalue otherwise
  13891. **/
  13892. int
  13893. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13894. {
  13895. LPFC_MBOXQ_t *mboxq;
  13896. int rc = 0;
  13897. int retval = MBX_SUCCESS;
  13898. uint32_t mbox_tmo;
  13899. struct lpfc_hba *phba = vport->phba;
  13900. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13901. if (!mboxq)
  13902. return -ENOMEM;
  13903. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13904. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13905. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13906. if (rc != MBX_SUCCESS) {
  13907. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13908. "2022 INIT VPI Mailbox failed "
  13909. "status %d, mbxStatus x%x\n", rc,
  13910. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13911. retval = -EIO;
  13912. }
  13913. if (rc != MBX_TIMEOUT)
  13914. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13915. return retval;
  13916. }
  13917. /**
  13918. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13919. * @phba: pointer to lpfc hba data structure.
  13920. * @mboxq: Pointer to mailbox object.
  13921. *
  13922. * This routine is invoked to manually add a single FCF record. The caller
  13923. * must pass a completely initialized FCF_Record. This routine takes
  13924. * care of the nonembedded mailbox operations.
  13925. **/
  13926. static void
  13927. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13928. {
  13929. void *virt_addr;
  13930. union lpfc_sli4_cfg_shdr *shdr;
  13931. uint32_t shdr_status, shdr_add_status;
  13932. virt_addr = mboxq->sge_array->addr[0];
  13933. /* The IOCTL status is embedded in the mailbox subheader. */
  13934. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13935. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13936. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13937. if ((shdr_status || shdr_add_status) &&
  13938. (shdr_status != STATUS_FCF_IN_USE))
  13939. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13940. "2558 ADD_FCF_RECORD mailbox failed with "
  13941. "status x%x add_status x%x\n",
  13942. shdr_status, shdr_add_status);
  13943. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13944. }
  13945. /**
  13946. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13947. * @phba: pointer to lpfc hba data structure.
  13948. * @fcf_record: pointer to the initialized fcf record to add.
  13949. *
  13950. * This routine is invoked to manually add a single FCF record. The caller
  13951. * must pass a completely initialized FCF_Record. This routine takes
  13952. * care of the nonembedded mailbox operations.
  13953. **/
  13954. int
  13955. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13956. {
  13957. int rc = 0;
  13958. LPFC_MBOXQ_t *mboxq;
  13959. uint8_t *bytep;
  13960. void *virt_addr;
  13961. dma_addr_t phys_addr;
  13962. struct lpfc_mbx_sge sge;
  13963. uint32_t alloc_len, req_len;
  13964. uint32_t fcfindex;
  13965. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13966. if (!mboxq) {
  13967. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13968. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13969. return -ENOMEM;
  13970. }
  13971. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13972. sizeof(uint32_t);
  13973. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13974. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13975. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13976. req_len, LPFC_SLI4_MBX_NEMBED);
  13977. if (alloc_len < req_len) {
  13978. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13979. "2523 Allocated DMA memory size (x%x) is "
  13980. "less than the requested DMA memory "
  13981. "size (x%x)\n", alloc_len, req_len);
  13982. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13983. return -ENOMEM;
  13984. }
  13985. /*
  13986. * Get the first SGE entry from the non-embedded DMA memory. This
  13987. * routine only uses a single SGE.
  13988. */
  13989. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13990. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13991. virt_addr = mboxq->sge_array->addr[0];
  13992. /*
  13993. * Configure the FCF record for FCFI 0. This is the driver's
  13994. * hardcoded default and gets used in nonFIP mode.
  13995. */
  13996. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  13997. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  13998. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  13999. /*
  14000. * Copy the fcf_index and the FCF Record Data. The data starts after
  14001. * the FCoE header plus word10. The data copy needs to be endian
  14002. * correct.
  14003. */
  14004. bytep += sizeof(uint32_t);
  14005. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  14006. mboxq->vport = phba->pport;
  14007. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  14008. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14009. if (rc == MBX_NOT_FINISHED) {
  14010. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14011. "2515 ADD_FCF_RECORD mailbox failed with "
  14012. "status 0x%x\n", rc);
  14013. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14014. rc = -EIO;
  14015. } else
  14016. rc = 0;
  14017. return rc;
  14018. }
  14019. /**
  14020. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  14021. * @phba: pointer to lpfc hba data structure.
  14022. * @fcf_record: pointer to the fcf record to write the default data.
  14023. * @fcf_index: FCF table entry index.
  14024. *
  14025. * This routine is invoked to build the driver's default FCF record. The
  14026. * values used are hardcoded. This routine handles memory initialization.
  14027. *
  14028. **/
  14029. void
  14030. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  14031. struct fcf_record *fcf_record,
  14032. uint16_t fcf_index)
  14033. {
  14034. memset(fcf_record, 0, sizeof(struct fcf_record));
  14035. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  14036. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  14037. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  14038. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  14039. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  14040. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  14041. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  14042. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  14043. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  14044. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  14045. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  14046. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  14047. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  14048. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  14049. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  14050. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  14051. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  14052. /* Set the VLAN bit map */
  14053. if (phba->valid_vlan) {
  14054. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  14055. = 1 << (phba->vlan_id % 8);
  14056. }
  14057. }
  14058. /**
  14059. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  14060. * @phba: pointer to lpfc hba data structure.
  14061. * @fcf_index: FCF table entry offset.
  14062. *
  14063. * This routine is invoked to scan the entire FCF table by reading FCF
  14064. * record and processing it one at a time starting from the @fcf_index
  14065. * for initial FCF discovery or fast FCF failover rediscovery.
  14066. *
  14067. * Return 0 if the mailbox command is submitted successfully, none 0
  14068. * otherwise.
  14069. **/
  14070. int
  14071. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14072. {
  14073. int rc = 0, error;
  14074. LPFC_MBOXQ_t *mboxq;
  14075. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  14076. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  14077. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14078. if (!mboxq) {
  14079. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14080. "2000 Failed to allocate mbox for "
  14081. "READ_FCF cmd\n");
  14082. error = -ENOMEM;
  14083. goto fail_fcf_scan;
  14084. }
  14085. /* Construct the read FCF record mailbox command */
  14086. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14087. if (rc) {
  14088. error = -EINVAL;
  14089. goto fail_fcf_scan;
  14090. }
  14091. /* Issue the mailbox command asynchronously */
  14092. mboxq->vport = phba->pport;
  14093. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  14094. spin_lock_irq(&phba->hbalock);
  14095. phba->hba_flag |= FCF_TS_INPROG;
  14096. spin_unlock_irq(&phba->hbalock);
  14097. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14098. if (rc == MBX_NOT_FINISHED)
  14099. error = -EIO;
  14100. else {
  14101. /* Reset eligible FCF count for new scan */
  14102. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  14103. phba->fcf.eligible_fcf_cnt = 0;
  14104. error = 0;
  14105. }
  14106. fail_fcf_scan:
  14107. if (error) {
  14108. if (mboxq)
  14109. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14110. /* FCF scan failed, clear FCF_TS_INPROG flag */
  14111. spin_lock_irq(&phba->hbalock);
  14112. phba->hba_flag &= ~FCF_TS_INPROG;
  14113. spin_unlock_irq(&phba->hbalock);
  14114. }
  14115. return error;
  14116. }
  14117. /**
  14118. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  14119. * @phba: pointer to lpfc hba data structure.
  14120. * @fcf_index: FCF table entry offset.
  14121. *
  14122. * This routine is invoked to read an FCF record indicated by @fcf_index
  14123. * and to use it for FLOGI roundrobin FCF failover.
  14124. *
  14125. * Return 0 if the mailbox command is submitted successfully, none 0
  14126. * otherwise.
  14127. **/
  14128. int
  14129. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14130. {
  14131. int rc = 0, error;
  14132. LPFC_MBOXQ_t *mboxq;
  14133. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14134. if (!mboxq) {
  14135. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14136. "2763 Failed to allocate mbox for "
  14137. "READ_FCF cmd\n");
  14138. error = -ENOMEM;
  14139. goto fail_fcf_read;
  14140. }
  14141. /* Construct the read FCF record mailbox command */
  14142. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14143. if (rc) {
  14144. error = -EINVAL;
  14145. goto fail_fcf_read;
  14146. }
  14147. /* Issue the mailbox command asynchronously */
  14148. mboxq->vport = phba->pport;
  14149. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  14150. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14151. if (rc == MBX_NOT_FINISHED)
  14152. error = -EIO;
  14153. else
  14154. error = 0;
  14155. fail_fcf_read:
  14156. if (error && mboxq)
  14157. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14158. return error;
  14159. }
  14160. /**
  14161. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  14162. * @phba: pointer to lpfc hba data structure.
  14163. * @fcf_index: FCF table entry offset.
  14164. *
  14165. * This routine is invoked to read an FCF record indicated by @fcf_index to
  14166. * determine whether it's eligible for FLOGI roundrobin failover list.
  14167. *
  14168. * Return 0 if the mailbox command is submitted successfully, none 0
  14169. * otherwise.
  14170. **/
  14171. int
  14172. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  14173. {
  14174. int rc = 0, error;
  14175. LPFC_MBOXQ_t *mboxq;
  14176. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14177. if (!mboxq) {
  14178. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  14179. "2758 Failed to allocate mbox for "
  14180. "READ_FCF cmd\n");
  14181. error = -ENOMEM;
  14182. goto fail_fcf_read;
  14183. }
  14184. /* Construct the read FCF record mailbox command */
  14185. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  14186. if (rc) {
  14187. error = -EINVAL;
  14188. goto fail_fcf_read;
  14189. }
  14190. /* Issue the mailbox command asynchronously */
  14191. mboxq->vport = phba->pport;
  14192. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  14193. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  14194. if (rc == MBX_NOT_FINISHED)
  14195. error = -EIO;
  14196. else
  14197. error = 0;
  14198. fail_fcf_read:
  14199. if (error && mboxq)
  14200. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  14201. return error;
  14202. }
  14203. /**
  14204. * lpfc_check_next_fcf_pri
  14205. * phba pointer to the lpfc_hba struct for this port.
  14206. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  14207. * routine when the rr_bmask is empty. The FCF indecies are put into the
  14208. * rr_bmask based on their priority level. Starting from the highest priority
  14209. * to the lowest. The most likely FCF candidate will be in the highest
  14210. * priority group. When this routine is called it searches the fcf_pri list for
  14211. * next lowest priority group and repopulates the rr_bmask with only those
  14212. * fcf_indexes.
  14213. * returns:
  14214. * 1=success 0=failure
  14215. **/
  14216. int
  14217. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  14218. {
  14219. uint16_t next_fcf_pri;
  14220. uint16_t last_index;
  14221. struct lpfc_fcf_pri *fcf_pri;
  14222. int rc;
  14223. int ret = 0;
  14224. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  14225. LPFC_SLI4_FCF_TBL_INDX_MAX);
  14226. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14227. "3060 Last IDX %d\n", last_index);
  14228. /* Verify the priority list has 2 or more entries */
  14229. spin_lock_irq(&phba->hbalock);
  14230. if (list_empty(&phba->fcf.fcf_pri_list) ||
  14231. list_is_singular(&phba->fcf.fcf_pri_list)) {
  14232. spin_unlock_irq(&phba->hbalock);
  14233. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14234. "3061 Last IDX %d\n", last_index);
  14235. return 0; /* Empty rr list */
  14236. }
  14237. spin_unlock_irq(&phba->hbalock);
  14238. next_fcf_pri = 0;
  14239. /*
  14240. * Clear the rr_bmask and set all of the bits that are at this
  14241. * priority.
  14242. */
  14243. memset(phba->fcf.fcf_rr_bmask, 0,
  14244. sizeof(*phba->fcf.fcf_rr_bmask));
  14245. spin_lock_irq(&phba->hbalock);
  14246. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14247. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  14248. continue;
  14249. /*
  14250. * the 1st priority that has not FLOGI failed
  14251. * will be the highest.
  14252. */
  14253. if (!next_fcf_pri)
  14254. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14255. spin_unlock_irq(&phba->hbalock);
  14256. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14257. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14258. fcf_pri->fcf_rec.fcf_index);
  14259. if (rc)
  14260. return 0;
  14261. }
  14262. spin_lock_irq(&phba->hbalock);
  14263. }
  14264. /*
  14265. * if next_fcf_pri was not set above and the list is not empty then
  14266. * we have failed flogis on all of them. So reset flogi failed
  14267. * and start at the beginning.
  14268. */
  14269. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  14270. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14271. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  14272. /*
  14273. * the 1st priority that has not FLOGI failed
  14274. * will be the highest.
  14275. */
  14276. if (!next_fcf_pri)
  14277. next_fcf_pri = fcf_pri->fcf_rec.priority;
  14278. spin_unlock_irq(&phba->hbalock);
  14279. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  14280. rc = lpfc_sli4_fcf_rr_index_set(phba,
  14281. fcf_pri->fcf_rec.fcf_index);
  14282. if (rc)
  14283. return 0;
  14284. }
  14285. spin_lock_irq(&phba->hbalock);
  14286. }
  14287. } else
  14288. ret = 1;
  14289. spin_unlock_irq(&phba->hbalock);
  14290. return ret;
  14291. }
  14292. /**
  14293. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  14294. * @phba: pointer to lpfc hba data structure.
  14295. *
  14296. * This routine is to get the next eligible FCF record index in a round
  14297. * robin fashion. If the next eligible FCF record index equals to the
  14298. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  14299. * shall be returned, otherwise, the next eligible FCF record's index
  14300. * shall be returned.
  14301. **/
  14302. uint16_t
  14303. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  14304. {
  14305. uint16_t next_fcf_index;
  14306. initial_priority:
  14307. /* Search start from next bit of currently registered FCF index */
  14308. next_fcf_index = phba->fcf.current_rec.fcf_indx;
  14309. next_priority:
  14310. /* Determine the next fcf index to check */
  14311. next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
  14312. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14313. LPFC_SLI4_FCF_TBL_INDX_MAX,
  14314. next_fcf_index);
  14315. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  14316. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14317. /*
  14318. * If we have wrapped then we need to clear the bits that
  14319. * have been tested so that we can detect when we should
  14320. * change the priority level.
  14321. */
  14322. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14323. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  14324. }
  14325. /* Check roundrobin failover list empty condition */
  14326. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  14327. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  14328. /*
  14329. * If next fcf index is not found check if there are lower
  14330. * Priority level fcf's in the fcf_priority list.
  14331. * Set up the rr_bmask with all of the avaiable fcf bits
  14332. * at that level and continue the selection process.
  14333. */
  14334. if (lpfc_check_next_fcf_pri_level(phba))
  14335. goto initial_priority;
  14336. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14337. "2844 No roundrobin failover FCF available\n");
  14338. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  14339. return LPFC_FCOE_FCF_NEXT_NONE;
  14340. else {
  14341. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14342. "3063 Only FCF available idx %d, flag %x\n",
  14343. next_fcf_index,
  14344. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  14345. return next_fcf_index;
  14346. }
  14347. }
  14348. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  14349. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  14350. LPFC_FCF_FLOGI_FAILED)
  14351. goto next_priority;
  14352. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14353. "2845 Get next roundrobin failover FCF (x%x)\n",
  14354. next_fcf_index);
  14355. return next_fcf_index;
  14356. }
  14357. /**
  14358. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  14359. * @phba: pointer to lpfc hba data structure.
  14360. *
  14361. * This routine sets the FCF record index in to the eligible bmask for
  14362. * roundrobin failover search. It checks to make sure that the index
  14363. * does not go beyond the range of the driver allocated bmask dimension
  14364. * before setting the bit.
  14365. *
  14366. * Returns 0 if the index bit successfully set, otherwise, it returns
  14367. * -EINVAL.
  14368. **/
  14369. int
  14370. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  14371. {
  14372. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14373. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14374. "2610 FCF (x%x) reached driver's book "
  14375. "keeping dimension:x%x\n",
  14376. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14377. return -EINVAL;
  14378. }
  14379. /* Set the eligible FCF record index bmask */
  14380. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14381. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14382. "2790 Set FCF (x%x) to roundrobin FCF failover "
  14383. "bmask\n", fcf_index);
  14384. return 0;
  14385. }
  14386. /**
  14387. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  14388. * @phba: pointer to lpfc hba data structure.
  14389. *
  14390. * This routine clears the FCF record index from the eligible bmask for
  14391. * roundrobin failover search. It checks to make sure that the index
  14392. * does not go beyond the range of the driver allocated bmask dimension
  14393. * before clearing the bit.
  14394. **/
  14395. void
  14396. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  14397. {
  14398. struct lpfc_fcf_pri *fcf_pri;
  14399. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14400. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14401. "2762 FCF (x%x) reached driver's book "
  14402. "keeping dimension:x%x\n",
  14403. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14404. return;
  14405. }
  14406. /* Clear the eligible FCF record index bmask */
  14407. spin_lock_irq(&phba->hbalock);
  14408. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14409. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  14410. list_del_init(&fcf_pri->list);
  14411. break;
  14412. }
  14413. }
  14414. spin_unlock_irq(&phba->hbalock);
  14415. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14416. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14417. "2791 Clear FCF (x%x) from roundrobin failover "
  14418. "bmask\n", fcf_index);
  14419. }
  14420. /**
  14421. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  14422. * @phba: pointer to lpfc hba data structure.
  14423. *
  14424. * This routine is the completion routine for the rediscover FCF table mailbox
  14425. * command. If the mailbox command returned failure, it will try to stop the
  14426. * FCF rediscover wait timer.
  14427. **/
  14428. void
  14429. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14430. {
  14431. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14432. uint32_t shdr_status, shdr_add_status;
  14433. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14434. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14435. &redisc_fcf->header.cfg_shdr.response);
  14436. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14437. &redisc_fcf->header.cfg_shdr.response);
  14438. if (shdr_status || shdr_add_status) {
  14439. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14440. "2746 Requesting for FCF rediscovery failed "
  14441. "status x%x add_status x%x\n",
  14442. shdr_status, shdr_add_status);
  14443. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14444. spin_lock_irq(&phba->hbalock);
  14445. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14446. spin_unlock_irq(&phba->hbalock);
  14447. /*
  14448. * CVL event triggered FCF rediscover request failed,
  14449. * last resort to re-try current registered FCF entry.
  14450. */
  14451. lpfc_retry_pport_discovery(phba);
  14452. } else {
  14453. spin_lock_irq(&phba->hbalock);
  14454. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14455. spin_unlock_irq(&phba->hbalock);
  14456. /*
  14457. * DEAD FCF event triggered FCF rediscover request
  14458. * failed, last resort to fail over as a link down
  14459. * to FCF registration.
  14460. */
  14461. lpfc_sli4_fcf_dead_failthrough(phba);
  14462. }
  14463. } else {
  14464. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14465. "2775 Start FCF rediscover quiescent timer\n");
  14466. /*
  14467. * Start FCF rediscovery wait timer for pending FCF
  14468. * before rescan FCF record table.
  14469. */
  14470. lpfc_fcf_redisc_wait_start_timer(phba);
  14471. }
  14472. mempool_free(mbox, phba->mbox_mem_pool);
  14473. }
  14474. /**
  14475. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14476. * @phba: pointer to lpfc hba data structure.
  14477. *
  14478. * This routine is invoked to request for rediscovery of the entire FCF table
  14479. * by the port.
  14480. **/
  14481. int
  14482. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14483. {
  14484. LPFC_MBOXQ_t *mbox;
  14485. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14486. int rc, length;
  14487. /* Cancel retry delay timers to all vports before FCF rediscover */
  14488. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14489. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14490. if (!mbox) {
  14491. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14492. "2745 Failed to allocate mbox for "
  14493. "requesting FCF rediscover.\n");
  14494. return -ENOMEM;
  14495. }
  14496. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14497. sizeof(struct lpfc_sli4_cfg_mhdr));
  14498. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14499. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14500. length, LPFC_SLI4_MBX_EMBED);
  14501. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14502. /* Set count to 0 for invalidating the entire FCF database */
  14503. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14504. /* Issue the mailbox command asynchronously */
  14505. mbox->vport = phba->pport;
  14506. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14507. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14508. if (rc == MBX_NOT_FINISHED) {
  14509. mempool_free(mbox, phba->mbox_mem_pool);
  14510. return -EIO;
  14511. }
  14512. return 0;
  14513. }
  14514. /**
  14515. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14516. * @phba: pointer to lpfc hba data structure.
  14517. *
  14518. * This function is the failover routine as a last resort to the FCF DEAD
  14519. * event when driver failed to perform fast FCF failover.
  14520. **/
  14521. void
  14522. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14523. {
  14524. uint32_t link_state;
  14525. /*
  14526. * Last resort as FCF DEAD event failover will treat this as
  14527. * a link down, but save the link state because we don't want
  14528. * it to be changed to Link Down unless it is already down.
  14529. */
  14530. link_state = phba->link_state;
  14531. lpfc_linkdown(phba);
  14532. phba->link_state = link_state;
  14533. /* Unregister FCF if no devices connected to it */
  14534. lpfc_unregister_unused_fcf(phba);
  14535. }
  14536. /**
  14537. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14538. * @phba: pointer to lpfc hba data structure.
  14539. * @rgn23_data: pointer to configure region 23 data.
  14540. *
  14541. * This function gets SLI3 port configure region 23 data through memory dump
  14542. * mailbox command. When it successfully retrieves data, the size of the data
  14543. * will be returned, otherwise, 0 will be returned.
  14544. **/
  14545. static uint32_t
  14546. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14547. {
  14548. LPFC_MBOXQ_t *pmb = NULL;
  14549. MAILBOX_t *mb;
  14550. uint32_t offset = 0;
  14551. int rc;
  14552. if (!rgn23_data)
  14553. return 0;
  14554. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14555. if (!pmb) {
  14556. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14557. "2600 failed to allocate mailbox memory\n");
  14558. return 0;
  14559. }
  14560. mb = &pmb->u.mb;
  14561. do {
  14562. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14563. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14564. if (rc != MBX_SUCCESS) {
  14565. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14566. "2601 failed to read config "
  14567. "region 23, rc 0x%x Status 0x%x\n",
  14568. rc, mb->mbxStatus);
  14569. mb->un.varDmp.word_cnt = 0;
  14570. }
  14571. /*
  14572. * dump mem may return a zero when finished or we got a
  14573. * mailbox error, either way we are done.
  14574. */
  14575. if (mb->un.varDmp.word_cnt == 0)
  14576. break;
  14577. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14578. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14579. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14580. rgn23_data + offset,
  14581. mb->un.varDmp.word_cnt);
  14582. offset += mb->un.varDmp.word_cnt;
  14583. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14584. mempool_free(pmb, phba->mbox_mem_pool);
  14585. return offset;
  14586. }
  14587. /**
  14588. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14589. * @phba: pointer to lpfc hba data structure.
  14590. * @rgn23_data: pointer to configure region 23 data.
  14591. *
  14592. * This function gets SLI4 port configure region 23 data through memory dump
  14593. * mailbox command. When it successfully retrieves data, the size of the data
  14594. * will be returned, otherwise, 0 will be returned.
  14595. **/
  14596. static uint32_t
  14597. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14598. {
  14599. LPFC_MBOXQ_t *mboxq = NULL;
  14600. struct lpfc_dmabuf *mp = NULL;
  14601. struct lpfc_mqe *mqe;
  14602. uint32_t data_length = 0;
  14603. int rc;
  14604. if (!rgn23_data)
  14605. return 0;
  14606. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14607. if (!mboxq) {
  14608. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14609. "3105 failed to allocate mailbox memory\n");
  14610. return 0;
  14611. }
  14612. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14613. goto out;
  14614. mqe = &mboxq->u.mqe;
  14615. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14616. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14617. if (rc)
  14618. goto out;
  14619. data_length = mqe->un.mb_words[5];
  14620. if (data_length == 0)
  14621. goto out;
  14622. if (data_length > DMP_RGN23_SIZE) {
  14623. data_length = 0;
  14624. goto out;
  14625. }
  14626. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14627. out:
  14628. mempool_free(mboxq, phba->mbox_mem_pool);
  14629. if (mp) {
  14630. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14631. kfree(mp);
  14632. }
  14633. return data_length;
  14634. }
  14635. /**
  14636. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14637. * @phba: pointer to lpfc hba data structure.
  14638. *
  14639. * This function read region 23 and parse TLV for port status to
  14640. * decide if the user disaled the port. If the TLV indicates the
  14641. * port is disabled, the hba_flag is set accordingly.
  14642. **/
  14643. void
  14644. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14645. {
  14646. uint8_t *rgn23_data = NULL;
  14647. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14648. uint32_t offset = 0;
  14649. /* Get adapter Region 23 data */
  14650. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14651. if (!rgn23_data)
  14652. goto out;
  14653. if (phba->sli_rev < LPFC_SLI_REV4)
  14654. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14655. else {
  14656. if_type = bf_get(lpfc_sli_intf_if_type,
  14657. &phba->sli4_hba.sli_intf);
  14658. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14659. goto out;
  14660. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14661. }
  14662. if (!data_size)
  14663. goto out;
  14664. /* Check the region signature first */
  14665. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14666. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14667. "2619 Config region 23 has bad signature\n");
  14668. goto out;
  14669. }
  14670. offset += 4;
  14671. /* Check the data structure version */
  14672. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14673. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14674. "2620 Config region 23 has bad version\n");
  14675. goto out;
  14676. }
  14677. offset += 4;
  14678. /* Parse TLV entries in the region */
  14679. while (offset < data_size) {
  14680. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14681. break;
  14682. /*
  14683. * If the TLV is not driver specific TLV or driver id is
  14684. * not linux driver id, skip the record.
  14685. */
  14686. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14687. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14688. (rgn23_data[offset + 3] != 0)) {
  14689. offset += rgn23_data[offset + 1] * 4 + 4;
  14690. continue;
  14691. }
  14692. /* Driver found a driver specific TLV in the config region */
  14693. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14694. offset += 4;
  14695. tlv_offset = 0;
  14696. /*
  14697. * Search for configured port state sub-TLV.
  14698. */
  14699. while ((offset < data_size) &&
  14700. (tlv_offset < sub_tlv_len)) {
  14701. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14702. offset += 4;
  14703. tlv_offset += 4;
  14704. break;
  14705. }
  14706. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14707. offset += rgn23_data[offset + 1] * 4 + 4;
  14708. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14709. continue;
  14710. }
  14711. /* This HBA contains PORT_STE configured */
  14712. if (!rgn23_data[offset + 2])
  14713. phba->hba_flag |= LINK_DISABLED;
  14714. goto out;
  14715. }
  14716. }
  14717. out:
  14718. kfree(rgn23_data);
  14719. return;
  14720. }
  14721. /**
  14722. * lpfc_wr_object - write an object to the firmware
  14723. * @phba: HBA structure that indicates port to create a queue on.
  14724. * @dmabuf_list: list of dmabufs to write to the port.
  14725. * @size: the total byte value of the objects to write to the port.
  14726. * @offset: the current offset to be used to start the transfer.
  14727. *
  14728. * This routine will create a wr_object mailbox command to send to the port.
  14729. * the mailbox command will be constructed using the dma buffers described in
  14730. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14731. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14732. * used to indicate the starting offset of the transfer and will also return
  14733. * the offset after the write object mailbox has completed. @size is used to
  14734. * determine the end of the object and whether the eof bit should be set.
  14735. *
  14736. * Return 0 is successful and offset will contain the the new offset to use
  14737. * for the next write.
  14738. * Return negative value for error cases.
  14739. **/
  14740. int
  14741. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14742. uint32_t size, uint32_t *offset)
  14743. {
  14744. struct lpfc_mbx_wr_object *wr_object;
  14745. LPFC_MBOXQ_t *mbox;
  14746. int rc = 0, i = 0;
  14747. uint32_t shdr_status, shdr_add_status;
  14748. uint32_t mbox_tmo;
  14749. union lpfc_sli4_cfg_shdr *shdr;
  14750. struct lpfc_dmabuf *dmabuf;
  14751. uint32_t written = 0;
  14752. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14753. if (!mbox)
  14754. return -ENOMEM;
  14755. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14756. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14757. sizeof(struct lpfc_mbx_wr_object) -
  14758. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14759. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14760. wr_object->u.request.write_offset = *offset;
  14761. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14762. wr_object->u.request.object_name[0] =
  14763. cpu_to_le32(wr_object->u.request.object_name[0]);
  14764. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14765. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14766. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14767. break;
  14768. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14769. wr_object->u.request.bde[i].addrHigh =
  14770. putPaddrHigh(dmabuf->phys);
  14771. if (written + SLI4_PAGE_SIZE >= size) {
  14772. wr_object->u.request.bde[i].tus.f.bdeSize =
  14773. (size - written);
  14774. written += (size - written);
  14775. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14776. } else {
  14777. wr_object->u.request.bde[i].tus.f.bdeSize =
  14778. SLI4_PAGE_SIZE;
  14779. written += SLI4_PAGE_SIZE;
  14780. }
  14781. i++;
  14782. }
  14783. wr_object->u.request.bde_count = i;
  14784. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14785. if (!phba->sli4_hba.intr_enable)
  14786. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14787. else {
  14788. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14789. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14790. }
  14791. /* The IOCTL status is embedded in the mailbox subheader. */
  14792. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14793. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14794. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14795. if (rc != MBX_TIMEOUT)
  14796. mempool_free(mbox, phba->mbox_mem_pool);
  14797. if (shdr_status || shdr_add_status || rc) {
  14798. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14799. "3025 Write Object mailbox failed with "
  14800. "status x%x add_status x%x, mbx status x%x\n",
  14801. shdr_status, shdr_add_status, rc);
  14802. rc = -ENXIO;
  14803. } else
  14804. *offset += wr_object->u.response.actual_write_length;
  14805. return rc;
  14806. }
  14807. /**
  14808. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14809. * @vport: pointer to vport data structure.
  14810. *
  14811. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14812. * and REG_VPI mailbox commands associated with the vport. This function
  14813. * is called when driver want to restart discovery of the vport due to
  14814. * a Clear Virtual Link event.
  14815. **/
  14816. void
  14817. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14818. {
  14819. struct lpfc_hba *phba = vport->phba;
  14820. LPFC_MBOXQ_t *mb, *nextmb;
  14821. struct lpfc_dmabuf *mp;
  14822. struct lpfc_nodelist *ndlp;
  14823. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14824. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14825. LIST_HEAD(mbox_cmd_list);
  14826. uint8_t restart_loop;
  14827. /* Clean up internally queued mailbox commands with the vport */
  14828. spin_lock_irq(&phba->hbalock);
  14829. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14830. if (mb->vport != vport)
  14831. continue;
  14832. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14833. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14834. continue;
  14835. list_del(&mb->list);
  14836. list_add_tail(&mb->list, &mbox_cmd_list);
  14837. }
  14838. /* Clean up active mailbox command with the vport */
  14839. mb = phba->sli.mbox_active;
  14840. if (mb && (mb->vport == vport)) {
  14841. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14842. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14843. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14844. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14845. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14846. /* Put reference count for delayed processing */
  14847. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14848. /* Unregister the RPI when mailbox complete */
  14849. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14850. }
  14851. }
  14852. /* Cleanup any mailbox completions which are not yet processed */
  14853. do {
  14854. restart_loop = 0;
  14855. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14856. /*
  14857. * If this mailox is already processed or it is
  14858. * for another vport ignore it.
  14859. */
  14860. if ((mb->vport != vport) ||
  14861. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14862. continue;
  14863. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14864. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14865. continue;
  14866. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14867. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14868. ndlp = (struct lpfc_nodelist *)mb->context2;
  14869. /* Unregister the RPI when mailbox complete */
  14870. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14871. restart_loop = 1;
  14872. spin_unlock_irq(&phba->hbalock);
  14873. spin_lock(shost->host_lock);
  14874. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14875. spin_unlock(shost->host_lock);
  14876. spin_lock_irq(&phba->hbalock);
  14877. break;
  14878. }
  14879. }
  14880. } while (restart_loop);
  14881. spin_unlock_irq(&phba->hbalock);
  14882. /* Release the cleaned-up mailbox commands */
  14883. while (!list_empty(&mbox_cmd_list)) {
  14884. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14885. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14886. mp = (struct lpfc_dmabuf *) (mb->context1);
  14887. if (mp) {
  14888. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14889. kfree(mp);
  14890. }
  14891. ndlp = (struct lpfc_nodelist *) mb->context2;
  14892. mb->context2 = NULL;
  14893. if (ndlp) {
  14894. spin_lock(shost->host_lock);
  14895. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14896. spin_unlock(shost->host_lock);
  14897. lpfc_nlp_put(ndlp);
  14898. }
  14899. }
  14900. mempool_free(mb, phba->mbox_mem_pool);
  14901. }
  14902. /* Release the ndlp with the cleaned-up active mailbox command */
  14903. if (act_mbx_ndlp) {
  14904. spin_lock(shost->host_lock);
  14905. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14906. spin_unlock(shost->host_lock);
  14907. lpfc_nlp_put(act_mbx_ndlp);
  14908. }
  14909. }
  14910. /**
  14911. * lpfc_drain_txq - Drain the txq
  14912. * @phba: Pointer to HBA context object.
  14913. *
  14914. * This function attempt to submit IOCBs on the txq
  14915. * to the adapter. For SLI4 adapters, the txq contains
  14916. * ELS IOCBs that have been deferred because the there
  14917. * are no SGLs. This congestion can occur with large
  14918. * vport counts during node discovery.
  14919. **/
  14920. uint32_t
  14921. lpfc_drain_txq(struct lpfc_hba *phba)
  14922. {
  14923. LIST_HEAD(completions);
  14924. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14925. struct lpfc_iocbq *piocbq = 0;
  14926. unsigned long iflags = 0;
  14927. char *fail_msg = NULL;
  14928. struct lpfc_sglq *sglq;
  14929. union lpfc_wqe wqe;
  14930. int txq_cnt = 0;
  14931. spin_lock_irqsave(&phba->hbalock, iflags);
  14932. list_for_each_entry(piocbq, &pring->txq, list) {
  14933. txq_cnt++;
  14934. }
  14935. if (txq_cnt > pring->txq_max)
  14936. pring->txq_max = txq_cnt;
  14937. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14938. while (!list_empty(&pring->txq)) {
  14939. spin_lock_irqsave(&phba->hbalock, iflags);
  14940. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14941. if (!piocbq) {
  14942. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14943. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14944. "2823 txq empty and txq_cnt is %d\n ",
  14945. txq_cnt);
  14946. break;
  14947. }
  14948. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14949. if (!sglq) {
  14950. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14951. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14952. break;
  14953. }
  14954. txq_cnt--;
  14955. /* The xri and iocb resources secured,
  14956. * attempt to issue request
  14957. */
  14958. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14959. piocbq->sli4_xritag = sglq->sli4_xritag;
  14960. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14961. fail_msg = "to convert bpl to sgl";
  14962. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14963. fail_msg = "to convert iocb to wqe";
  14964. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14965. fail_msg = " - Wq is full";
  14966. else
  14967. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14968. if (fail_msg) {
  14969. /* Failed means we can't issue and need to cancel */
  14970. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14971. "2822 IOCB failed %s iotag 0x%x "
  14972. "xri 0x%x\n",
  14973. fail_msg,
  14974. piocbq->iotag, piocbq->sli4_xritag);
  14975. list_add_tail(&piocbq->list, &completions);
  14976. }
  14977. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14978. }
  14979. /* Cancel all the IOCBs that cannot be issued */
  14980. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14981. IOERR_SLI_ABORTED);
  14982. return txq_cnt;
  14983. }