lpfc_sli.c 487 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907
  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 IOCB_t *
  67. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  68. {
  69. return &iocbq->iocb;
  70. }
  71. /**
  72. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  73. * @q: The Work Queue to operate on.
  74. * @wqe: The work Queue Entry to put on the Work queue.
  75. *
  76. * This routine will copy the contents of @wqe to the next available entry on
  77. * the @q. This function will then ring the Work Queue Doorbell to signal the
  78. * HBA to start processing the Work Queue Entry. This function returns 0 if
  79. * successful. If no entries are available on @q then this function will return
  80. * -ENOMEM.
  81. * The caller is expected to hold the hbalock when calling this routine.
  82. **/
  83. static uint32_t
  84. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  85. {
  86. union lpfc_wqe *temp_wqe;
  87. struct lpfc_register doorbell;
  88. uint32_t host_index;
  89. /* sanity check on queue memory */
  90. if (unlikely(!q))
  91. return -ENOMEM;
  92. temp_wqe = q->qe[q->host_index].wqe;
  93. /* If the host has not yet processed the next entry then we are done */
  94. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  95. return -ENOMEM;
  96. /* set consumption flag every once in a while */
  97. if (!((q->host_index + 1) % q->entry_repost))
  98. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  99. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  100. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  101. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  102. /* Update the host index before invoking device */
  103. host_index = q->host_index;
  104. q->host_index = ((q->host_index + 1) % q->entry_count);
  105. /* Ring Doorbell */
  106. doorbell.word0 = 0;
  107. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  108. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  109. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  110. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  111. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  112. return 0;
  113. }
  114. /**
  115. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  116. * @q: The Work Queue to operate on.
  117. * @index: The index to advance the hba index to.
  118. *
  119. * This routine will update the HBA index of a queue to reflect consumption of
  120. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  121. * an entry the host calls this function to update the queue's internal
  122. * pointers. This routine returns the number of entries that were consumed by
  123. * the HBA.
  124. **/
  125. static uint32_t
  126. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  127. {
  128. uint32_t released = 0;
  129. /* sanity check on queue memory */
  130. if (unlikely(!q))
  131. return 0;
  132. if (q->hba_index == index)
  133. return 0;
  134. do {
  135. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  136. released++;
  137. } while (q->hba_index != index);
  138. return released;
  139. }
  140. /**
  141. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  142. * @q: The Mailbox Queue to operate on.
  143. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  144. *
  145. * This routine will copy the contents of @mqe to the next available entry on
  146. * the @q. This function will then ring the Work Queue Doorbell to signal the
  147. * HBA to start processing the Work Queue Entry. This function returns 0 if
  148. * successful. If no entries are available on @q then this function will return
  149. * -ENOMEM.
  150. * The caller is expected to hold the hbalock when calling this routine.
  151. **/
  152. static uint32_t
  153. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  154. {
  155. struct lpfc_mqe *temp_mqe;
  156. struct lpfc_register doorbell;
  157. uint32_t host_index;
  158. /* sanity check on queue memory */
  159. if (unlikely(!q))
  160. return -ENOMEM;
  161. temp_mqe = q->qe[q->host_index].mqe;
  162. /* If the host has not yet processed the next entry then we are done */
  163. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  164. return -ENOMEM;
  165. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  166. /* Save off the mailbox pointer for completion */
  167. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  168. /* Update the host index before invoking device */
  169. host_index = q->host_index;
  170. q->host_index = ((q->host_index + 1) % q->entry_count);
  171. /* Ring Doorbell */
  172. doorbell.word0 = 0;
  173. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  174. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  175. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  176. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  177. return 0;
  178. }
  179. /**
  180. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  181. * @q: The Mailbox Queue to operate on.
  182. *
  183. * This routine will update the HBA index of a queue to reflect consumption of
  184. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  185. * an entry the host calls this function to update the queue's internal
  186. * pointers. This routine returns the number of entries that were consumed by
  187. * the HBA.
  188. **/
  189. static uint32_t
  190. lpfc_sli4_mq_release(struct lpfc_queue *q)
  191. {
  192. /* sanity check on queue memory */
  193. if (unlikely(!q))
  194. return 0;
  195. /* Clear the mailbox pointer for completion */
  196. q->phba->mbox = NULL;
  197. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  198. return 1;
  199. }
  200. /**
  201. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  202. * @q: The Event Queue to get the first valid EQE from
  203. *
  204. * This routine will get the first valid Event Queue Entry from @q, update
  205. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  206. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  207. * processed, but not popped back to the HBA then this routine will return NULL.
  208. **/
  209. static struct lpfc_eqe *
  210. lpfc_sli4_eq_get(struct lpfc_queue *q)
  211. {
  212. struct lpfc_eqe *eqe;
  213. /* sanity check on queue memory */
  214. if (unlikely(!q))
  215. return NULL;
  216. eqe = q->qe[q->hba_index].eqe;
  217. /* If the next EQE is not valid then we are done */
  218. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  219. return NULL;
  220. /* If the host has not yet processed the next entry then we are done */
  221. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  222. return NULL;
  223. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  224. return eqe;
  225. }
  226. /**
  227. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  228. * @q: The Event Queue that the host has completed processing for.
  229. * @arm: Indicates whether the host wants to arms this CQ.
  230. *
  231. * This routine will mark all Event Queue Entries on @q, from the last
  232. * known completed entry to the last entry that was processed, as completed
  233. * by clearing the valid bit for each completion queue entry. Then it will
  234. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  235. * The internal host index in the @q will be updated by this routine to indicate
  236. * that the host has finished processing the entries. The @arm parameter
  237. * indicates that the queue should be rearmed when ringing the doorbell.
  238. *
  239. * This function will return the number of EQEs that were popped.
  240. **/
  241. uint32_t
  242. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  243. {
  244. uint32_t released = 0;
  245. struct lpfc_eqe *temp_eqe;
  246. struct lpfc_register doorbell;
  247. /* sanity check on queue memory */
  248. if (unlikely(!q))
  249. return 0;
  250. /* while there are valid entries */
  251. while (q->hba_index != q->host_index) {
  252. temp_eqe = q->qe[q->host_index].eqe;
  253. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  254. released++;
  255. q->host_index = ((q->host_index + 1) % q->entry_count);
  256. }
  257. if (unlikely(released == 0 && !arm))
  258. return 0;
  259. /* ring doorbell for number popped */
  260. doorbell.word0 = 0;
  261. if (arm) {
  262. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  263. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  264. }
  265. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  266. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  267. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  268. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  269. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  270. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  271. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  272. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  273. readl(q->phba->sli4_hba.EQCQDBregaddr);
  274. return released;
  275. }
  276. /**
  277. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  278. * @q: The Completion Queue to get the first valid CQE from
  279. *
  280. * This routine will get the first valid Completion Queue Entry from @q, update
  281. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  282. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  283. * processed, but not popped back to the HBA then this routine will return NULL.
  284. **/
  285. static struct lpfc_cqe *
  286. lpfc_sli4_cq_get(struct lpfc_queue *q)
  287. {
  288. struct lpfc_cqe *cqe;
  289. /* sanity check on queue memory */
  290. if (unlikely(!q))
  291. return NULL;
  292. /* If the next CQE is not valid then we are done */
  293. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  294. return NULL;
  295. /* If the host has not yet processed the next entry then we are done */
  296. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  297. return NULL;
  298. cqe = q->qe[q->hba_index].cqe;
  299. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  300. return cqe;
  301. }
  302. /**
  303. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  304. * @q: The Completion Queue that the host has completed processing for.
  305. * @arm: Indicates whether the host wants to arms this CQ.
  306. *
  307. * This routine will mark all Completion queue entries on @q, from the last
  308. * known completed entry to the last entry that was processed, as completed
  309. * by clearing the valid bit for each completion queue entry. Then it will
  310. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  311. * The internal host index in the @q will be updated by this routine to indicate
  312. * that the host has finished processing the entries. The @arm parameter
  313. * indicates that the queue should be rearmed when ringing the doorbell.
  314. *
  315. * This function will return the number of CQEs that were released.
  316. **/
  317. uint32_t
  318. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  319. {
  320. uint32_t released = 0;
  321. struct lpfc_cqe *temp_qe;
  322. struct lpfc_register doorbell;
  323. /* sanity check on queue memory */
  324. if (unlikely(!q))
  325. return 0;
  326. /* while there are valid entries */
  327. while (q->hba_index != q->host_index) {
  328. temp_qe = q->qe[q->host_index].cqe;
  329. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  330. released++;
  331. q->host_index = ((q->host_index + 1) % q->entry_count);
  332. }
  333. if (unlikely(released == 0 && !arm))
  334. return 0;
  335. /* ring doorbell for number popped */
  336. doorbell.word0 = 0;
  337. if (arm)
  338. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  339. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  340. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  341. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  342. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  343. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  344. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  345. return released;
  346. }
  347. /**
  348. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  349. * @q: The Header Receive Queue to operate on.
  350. * @wqe: The Receive Queue Entry to put on the Receive queue.
  351. *
  352. * This routine will copy the contents of @wqe to the next available entry on
  353. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  354. * HBA to start processing the Receive Queue Entry. This function returns the
  355. * index that the rqe was copied to if successful. If no entries are available
  356. * on @q then this function will return -ENOMEM.
  357. * The caller is expected to hold the hbalock when calling this routine.
  358. **/
  359. static int
  360. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  361. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  362. {
  363. struct lpfc_rqe *temp_hrqe;
  364. struct lpfc_rqe *temp_drqe;
  365. struct lpfc_register doorbell;
  366. int put_index = hq->host_index;
  367. /* sanity check on queue memory */
  368. if (unlikely(!hq) || unlikely(!dq))
  369. return -ENOMEM;
  370. temp_hrqe = hq->qe[hq->host_index].rqe;
  371. temp_drqe = dq->qe[dq->host_index].rqe;
  372. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  373. return -EINVAL;
  374. if (hq->host_index != dq->host_index)
  375. return -EINVAL;
  376. /* If the host has not yet processed the next entry then we are done */
  377. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  378. return -EBUSY;
  379. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  380. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  381. /* Update the host index to point to the next slot */
  382. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  383. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  384. /* Ring The Header Receive Queue Doorbell */
  385. if (!(hq->host_index % hq->entry_repost)) {
  386. doorbell.word0 = 0;
  387. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  388. hq->entry_repost);
  389. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  390. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  391. }
  392. return put_index;
  393. }
  394. /**
  395. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  396. * @q: The Header Receive Queue to operate on.
  397. *
  398. * This routine will update the HBA index of a queue to reflect consumption of
  399. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  400. * consumed an entry the host calls this function to update the queue's
  401. * internal pointers. This routine returns the number of entries that were
  402. * consumed by the HBA.
  403. **/
  404. static uint32_t
  405. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  406. {
  407. /* sanity check on queue memory */
  408. if (unlikely(!hq) || unlikely(!dq))
  409. return 0;
  410. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  411. return 0;
  412. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  413. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  414. return 1;
  415. }
  416. /**
  417. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  418. * @phba: Pointer to HBA context object.
  419. * @pring: Pointer to driver SLI ring object.
  420. *
  421. * This function returns pointer to next command iocb entry
  422. * in the command ring. The caller must hold hbalock to prevent
  423. * other threads consume the next command iocb.
  424. * SLI-2/SLI-3 provide different sized iocbs.
  425. **/
  426. static inline IOCB_t *
  427. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  428. {
  429. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  430. pring->cmdidx * phba->iocb_cmd_size);
  431. }
  432. /**
  433. * lpfc_resp_iocb - Get next response iocb entry in the ring
  434. * @phba: Pointer to HBA context object.
  435. * @pring: Pointer to driver SLI ring object.
  436. *
  437. * This function returns pointer to next response iocb entry
  438. * in the response ring. The caller must hold hbalock to make sure
  439. * that no other thread consume the next response iocb.
  440. * SLI-2/SLI-3 provide different sized iocbs.
  441. **/
  442. static inline IOCB_t *
  443. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  444. {
  445. return (IOCB_t *) (((char *) pring->rspringaddr) +
  446. pring->rspidx * phba->iocb_rsp_size);
  447. }
  448. /**
  449. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  450. * @phba: Pointer to HBA context object.
  451. *
  452. * This function is called with hbalock held. This function
  453. * allocates a new driver iocb object from the iocb pool. If the
  454. * allocation is successful, it returns pointer to the newly
  455. * allocated iocb object else it returns NULL.
  456. **/
  457. struct lpfc_iocbq *
  458. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  459. {
  460. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  461. struct lpfc_iocbq * iocbq = NULL;
  462. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  463. if (iocbq)
  464. phba->iocb_cnt++;
  465. if (phba->iocb_cnt > phba->iocb_max)
  466. phba->iocb_max = phba->iocb_cnt;
  467. return iocbq;
  468. }
  469. /**
  470. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  471. * @phba: Pointer to HBA context object.
  472. * @xritag: XRI value.
  473. *
  474. * This function clears the sglq pointer from the array of acive
  475. * sglq's. The xritag that is passed in is used to index into the
  476. * array. Before the xritag can be used it needs to be adjusted
  477. * by subtracting the xribase.
  478. *
  479. * Returns sglq ponter = success, NULL = Failure.
  480. **/
  481. static struct lpfc_sglq *
  482. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  483. {
  484. struct lpfc_sglq *sglq;
  485. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  486. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  487. return sglq;
  488. }
  489. /**
  490. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  491. * @phba: Pointer to HBA context object.
  492. * @xritag: XRI value.
  493. *
  494. * This function returns the sglq pointer from the array of acive
  495. * sglq's. The xritag that is passed in is used to index into the
  496. * array. Before the xritag can be used it needs to be adjusted
  497. * by subtracting the xribase.
  498. *
  499. * Returns sglq ponter = success, NULL = Failure.
  500. **/
  501. struct lpfc_sglq *
  502. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  503. {
  504. struct lpfc_sglq *sglq;
  505. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  506. return sglq;
  507. }
  508. /**
  509. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  510. * @phba: Pointer to HBA context object.
  511. * @xritag: xri used in this exchange.
  512. * @rrq: The RRQ to be cleared.
  513. *
  514. **/
  515. void
  516. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  517. uint16_t xritag,
  518. struct lpfc_node_rrq *rrq)
  519. {
  520. struct lpfc_nodelist *ndlp = NULL;
  521. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  522. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  523. /* The target DID could have been swapped (cable swap)
  524. * we should use the ndlp from the findnode if it is
  525. * available.
  526. */
  527. if ((!ndlp) && rrq->ndlp)
  528. ndlp = rrq->ndlp;
  529. if (!ndlp)
  530. goto out;
  531. if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
  532. rrq->send_rrq = 0;
  533. rrq->xritag = 0;
  534. rrq->rrq_stop_time = 0;
  535. }
  536. out:
  537. mempool_free(rrq, phba->rrq_pool);
  538. }
  539. /**
  540. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  541. * @phba: Pointer to HBA context object.
  542. *
  543. * This function is called with hbalock held. This function
  544. * Checks if stop_time (ratov from setting rrq active) has
  545. * been reached, if it has and the send_rrq flag is set then
  546. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  547. * then it will just call the routine to clear the rrq and
  548. * free the rrq resource.
  549. * The timer is set to the next rrq that is going to expire before
  550. * leaving the routine.
  551. *
  552. **/
  553. void
  554. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  555. {
  556. struct lpfc_node_rrq *rrq;
  557. struct lpfc_node_rrq *nextrrq;
  558. unsigned long next_time;
  559. unsigned long iflags;
  560. LIST_HEAD(send_rrq);
  561. spin_lock_irqsave(&phba->hbalock, iflags);
  562. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  563. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  564. list_for_each_entry_safe(rrq, nextrrq,
  565. &phba->active_rrq_list, list) {
  566. if (time_after(jiffies, rrq->rrq_stop_time))
  567. list_move(&rrq->list, &send_rrq);
  568. else if (time_before(rrq->rrq_stop_time, next_time))
  569. next_time = rrq->rrq_stop_time;
  570. }
  571. spin_unlock_irqrestore(&phba->hbalock, iflags);
  572. if (!list_empty(&phba->active_rrq_list))
  573. mod_timer(&phba->rrq_tmr, next_time);
  574. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  575. list_del(&rrq->list);
  576. if (!rrq->send_rrq)
  577. /* this call will free the rrq */
  578. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  579. else if (lpfc_send_rrq(phba, rrq)) {
  580. /* if we send the rrq then the completion handler
  581. * will clear the bit in the xribitmap.
  582. */
  583. lpfc_clr_rrq_active(phba, rrq->xritag,
  584. rrq);
  585. }
  586. }
  587. }
  588. /**
  589. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  590. * @vport: Pointer to vport context object.
  591. * @xri: The xri used in the exchange.
  592. * @did: The targets DID for this exchange.
  593. *
  594. * returns NULL = rrq not found in the phba->active_rrq_list.
  595. * rrq = rrq for this xri and target.
  596. **/
  597. struct lpfc_node_rrq *
  598. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  599. {
  600. struct lpfc_hba *phba = vport->phba;
  601. struct lpfc_node_rrq *rrq;
  602. struct lpfc_node_rrq *nextrrq;
  603. unsigned long iflags;
  604. if (phba->sli_rev != LPFC_SLI_REV4)
  605. return NULL;
  606. spin_lock_irqsave(&phba->hbalock, iflags);
  607. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  608. if (rrq->vport == vport && rrq->xritag == xri &&
  609. rrq->nlp_DID == did){
  610. list_del(&rrq->list);
  611. spin_unlock_irqrestore(&phba->hbalock, iflags);
  612. return rrq;
  613. }
  614. }
  615. spin_unlock_irqrestore(&phba->hbalock, iflags);
  616. return NULL;
  617. }
  618. /**
  619. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  620. * @vport: Pointer to vport context object.
  621. * @ndlp: Pointer to the lpfc_node_list structure.
  622. * If ndlp is NULL Remove all active RRQs for this vport from the
  623. * phba->active_rrq_list and clear the rrq.
  624. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  625. **/
  626. void
  627. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  628. {
  629. struct lpfc_hba *phba = vport->phba;
  630. struct lpfc_node_rrq *rrq;
  631. struct lpfc_node_rrq *nextrrq;
  632. unsigned long iflags;
  633. LIST_HEAD(rrq_list);
  634. if (phba->sli_rev != LPFC_SLI_REV4)
  635. return;
  636. if (!ndlp) {
  637. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  638. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  639. }
  640. spin_lock_irqsave(&phba->hbalock, iflags);
  641. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  642. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  643. list_move(&rrq->list, &rrq_list);
  644. spin_unlock_irqrestore(&phba->hbalock, iflags);
  645. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  646. list_del(&rrq->list);
  647. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  648. }
  649. }
  650. /**
  651. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  652. * @phba: Pointer to HBA context object.
  653. *
  654. * Remove all rrqs from the phba->active_rrq_list and free them by
  655. * calling __lpfc_clr_active_rrq
  656. *
  657. **/
  658. void
  659. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  660. {
  661. struct lpfc_node_rrq *rrq;
  662. struct lpfc_node_rrq *nextrrq;
  663. unsigned long next_time;
  664. unsigned long iflags;
  665. LIST_HEAD(rrq_list);
  666. if (phba->sli_rev != LPFC_SLI_REV4)
  667. return;
  668. spin_lock_irqsave(&phba->hbalock, iflags);
  669. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  670. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  671. list_splice_init(&phba->active_rrq_list, &rrq_list);
  672. spin_unlock_irqrestore(&phba->hbalock, iflags);
  673. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  674. list_del(&rrq->list);
  675. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  676. }
  677. if (!list_empty(&phba->active_rrq_list))
  678. mod_timer(&phba->rrq_tmr, next_time);
  679. }
  680. /**
  681. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  682. * @phba: Pointer to HBA context object.
  683. * @ndlp: Targets nodelist pointer for this exchange.
  684. * @xritag the xri in the bitmap to test.
  685. *
  686. * This function is called with hbalock held. This function
  687. * returns 0 = rrq not active for this xri
  688. * 1 = rrq is valid for this xri.
  689. **/
  690. int
  691. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  692. uint16_t xritag)
  693. {
  694. if (!ndlp)
  695. return 0;
  696. if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  697. return 1;
  698. else
  699. return 0;
  700. }
  701. /**
  702. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  703. * @phba: Pointer to HBA context object.
  704. * @ndlp: nodelist pointer for this target.
  705. * @xritag: xri used in this exchange.
  706. * @rxid: Remote Exchange ID.
  707. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  708. *
  709. * This function takes the hbalock.
  710. * The active bit is always set in the active rrq xri_bitmap even
  711. * if there is no slot avaiable for the other rrq information.
  712. *
  713. * returns 0 rrq actived for this xri
  714. * < 0 No memory or invalid ndlp.
  715. **/
  716. int
  717. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  718. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  719. {
  720. unsigned long iflags;
  721. struct lpfc_node_rrq *rrq;
  722. int empty;
  723. if (!ndlp)
  724. return -EINVAL;
  725. if (!phba->cfg_enable_rrq)
  726. return -EINVAL;
  727. spin_lock_irqsave(&phba->hbalock, iflags);
  728. if (phba->pport->load_flag & FC_UNLOADING) {
  729. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  730. goto out;
  731. }
  732. /*
  733. * set the active bit even if there is no mem available.
  734. */
  735. if (NLP_CHK_FREE_REQ(ndlp))
  736. goto out;
  737. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  738. goto out;
  739. if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  740. goto out;
  741. spin_unlock_irqrestore(&phba->hbalock, iflags);
  742. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  743. if (!rrq) {
  744. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  745. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  746. " DID:0x%x Send:%d\n",
  747. xritag, rxid, ndlp->nlp_DID, send_rrq);
  748. return -EINVAL;
  749. }
  750. rrq->send_rrq = send_rrq;
  751. rrq->xritag = xritag;
  752. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  753. rrq->ndlp = ndlp;
  754. rrq->nlp_DID = ndlp->nlp_DID;
  755. rrq->vport = ndlp->vport;
  756. rrq->rxid = rxid;
  757. rrq->send_rrq = send_rrq;
  758. spin_lock_irqsave(&phba->hbalock, iflags);
  759. empty = list_empty(&phba->active_rrq_list);
  760. list_add_tail(&rrq->list, &phba->active_rrq_list);
  761. phba->hba_flag |= HBA_RRQ_ACTIVE;
  762. if (empty)
  763. lpfc_worker_wake_up(phba);
  764. spin_unlock_irqrestore(&phba->hbalock, iflags);
  765. return 0;
  766. out:
  767. spin_unlock_irqrestore(&phba->hbalock, iflags);
  768. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  769. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  770. " DID:0x%x Send:%d\n",
  771. xritag, rxid, ndlp->nlp_DID, send_rrq);
  772. return -EINVAL;
  773. }
  774. /**
  775. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  776. * @phba: Pointer to HBA context object.
  777. * @piocb: Pointer to the iocbq.
  778. *
  779. * This function is called with hbalock held. This function
  780. * gets a new driver sglq object from the sglq list. If the
  781. * list is not empty then it is successful, it returns pointer to the newly
  782. * allocated sglq object else it returns NULL.
  783. **/
  784. static struct lpfc_sglq *
  785. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  786. {
  787. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  788. struct lpfc_sglq *sglq = NULL;
  789. struct lpfc_sglq *start_sglq = NULL;
  790. struct lpfc_scsi_buf *lpfc_cmd;
  791. struct lpfc_nodelist *ndlp;
  792. int found = 0;
  793. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  794. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  795. ndlp = lpfc_cmd->rdata->pnode;
  796. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  797. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  798. ndlp = piocbq->context_un.ndlp;
  799. else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) &&
  800. (piocbq->iocb_flag & LPFC_IO_LIBDFC))
  801. ndlp = piocbq->context_un.ndlp;
  802. else
  803. ndlp = piocbq->context1;
  804. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  805. start_sglq = sglq;
  806. while (!found) {
  807. if (!sglq)
  808. return NULL;
  809. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) {
  810. /* This xri has an rrq outstanding for this DID.
  811. * put it back in the list and get another xri.
  812. */
  813. list_add_tail(&sglq->list, lpfc_sgl_list);
  814. sglq = NULL;
  815. list_remove_head(lpfc_sgl_list, sglq,
  816. struct lpfc_sglq, list);
  817. if (sglq == start_sglq) {
  818. sglq = NULL;
  819. break;
  820. } else
  821. continue;
  822. }
  823. sglq->ndlp = ndlp;
  824. found = 1;
  825. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  826. sglq->state = SGL_ALLOCATED;
  827. }
  828. return sglq;
  829. }
  830. /**
  831. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  832. * @phba: Pointer to HBA context object.
  833. *
  834. * This function is called with no lock held. This function
  835. * allocates a new driver iocb object from the iocb pool. If the
  836. * allocation is successful, it returns pointer to the newly
  837. * allocated iocb object else it returns NULL.
  838. **/
  839. struct lpfc_iocbq *
  840. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  841. {
  842. struct lpfc_iocbq * iocbq = NULL;
  843. unsigned long iflags;
  844. spin_lock_irqsave(&phba->hbalock, iflags);
  845. iocbq = __lpfc_sli_get_iocbq(phba);
  846. spin_unlock_irqrestore(&phba->hbalock, iflags);
  847. return iocbq;
  848. }
  849. /**
  850. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  851. * @phba: Pointer to HBA context object.
  852. * @iocbq: Pointer to driver iocb object.
  853. *
  854. * This function is called with hbalock held to release driver
  855. * iocb object to the iocb pool. The iotag in the iocb object
  856. * does not change for each use of the iocb object. This function
  857. * clears all other fields of the iocb object when it is freed.
  858. * The sqlq structure that holds the xritag and phys and virtual
  859. * mappings for the scatter gather list is retrieved from the
  860. * active array of sglq. The get of the sglq pointer also clears
  861. * the entry in the array. If the status of the IO indiactes that
  862. * this IO was aborted then the sglq entry it put on the
  863. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  864. * IO has good status or fails for any other reason then the sglq
  865. * entry is added to the free list (lpfc_sgl_list).
  866. **/
  867. static void
  868. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  869. {
  870. struct lpfc_sglq *sglq;
  871. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  872. unsigned long iflag = 0;
  873. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  874. if (iocbq->sli4_xritag == NO_XRI)
  875. sglq = NULL;
  876. else
  877. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  878. if (sglq) {
  879. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  880. (sglq->state != SGL_XRI_ABORTED)) {
  881. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  882. iflag);
  883. list_add(&sglq->list,
  884. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  885. spin_unlock_irqrestore(
  886. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  887. } else {
  888. sglq->state = SGL_FREED;
  889. sglq->ndlp = NULL;
  890. list_add_tail(&sglq->list,
  891. &phba->sli4_hba.lpfc_sgl_list);
  892. /* Check if TXQ queue needs to be serviced */
  893. if (pring->txq_cnt)
  894. lpfc_worker_wake_up(phba);
  895. }
  896. }
  897. /*
  898. * Clean all volatile data fields, preserve iotag and node struct.
  899. */
  900. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  901. iocbq->sli4_lxritag = NO_XRI;
  902. iocbq->sli4_xritag = NO_XRI;
  903. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  904. }
  905. /**
  906. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  907. * @phba: Pointer to HBA context object.
  908. * @iocbq: Pointer to driver iocb object.
  909. *
  910. * This function is called with hbalock held to release driver
  911. * iocb object to the iocb pool. The iotag in the iocb object
  912. * does not change for each use of the iocb object. This function
  913. * clears all other fields of the iocb object when it is freed.
  914. **/
  915. static void
  916. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  917. {
  918. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  919. /*
  920. * Clean all volatile data fields, preserve iotag and node struct.
  921. */
  922. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  923. iocbq->sli4_xritag = NO_XRI;
  924. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  925. }
  926. /**
  927. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  928. * @phba: Pointer to HBA context object.
  929. * @iocbq: Pointer to driver iocb object.
  930. *
  931. * This function is called with hbalock held to release driver
  932. * iocb object to the iocb pool. The iotag in the iocb object
  933. * does not change for each use of the iocb object. This function
  934. * clears all other fields of the iocb object when it is freed.
  935. **/
  936. static void
  937. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  938. {
  939. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  940. phba->iocb_cnt--;
  941. }
  942. /**
  943. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  944. * @phba: Pointer to HBA context object.
  945. * @iocbq: Pointer to driver iocb object.
  946. *
  947. * This function is called with no lock held to release the iocb to
  948. * iocb pool.
  949. **/
  950. void
  951. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  952. {
  953. unsigned long iflags;
  954. /*
  955. * Clean all volatile data fields, preserve iotag and node struct.
  956. */
  957. spin_lock_irqsave(&phba->hbalock, iflags);
  958. __lpfc_sli_release_iocbq(phba, iocbq);
  959. spin_unlock_irqrestore(&phba->hbalock, iflags);
  960. }
  961. /**
  962. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  963. * @phba: Pointer to HBA context object.
  964. * @iocblist: List of IOCBs.
  965. * @ulpstatus: ULP status in IOCB command field.
  966. * @ulpWord4: ULP word-4 in IOCB command field.
  967. *
  968. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  969. * on the list by invoking the complete callback function associated with the
  970. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  971. * fields.
  972. **/
  973. void
  974. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  975. uint32_t ulpstatus, uint32_t ulpWord4)
  976. {
  977. struct lpfc_iocbq *piocb;
  978. while (!list_empty(iocblist)) {
  979. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  980. if (!piocb->iocb_cmpl)
  981. lpfc_sli_release_iocbq(phba, piocb);
  982. else {
  983. piocb->iocb.ulpStatus = ulpstatus;
  984. piocb->iocb.un.ulpWord[4] = ulpWord4;
  985. (piocb->iocb_cmpl) (phba, piocb, piocb);
  986. }
  987. }
  988. return;
  989. }
  990. /**
  991. * lpfc_sli_iocb_cmd_type - Get the iocb type
  992. * @iocb_cmnd: iocb command code.
  993. *
  994. * This function is called by ring event handler function to get the iocb type.
  995. * This function translates the iocb command to an iocb command type used to
  996. * decide the final disposition of each completed IOCB.
  997. * The function returns
  998. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  999. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1000. * LPFC_ABORT_IOCB if it is an abort iocb
  1001. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1002. *
  1003. * The caller is not required to hold any lock.
  1004. **/
  1005. static lpfc_iocb_type
  1006. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1007. {
  1008. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1009. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1010. return 0;
  1011. switch (iocb_cmnd) {
  1012. case CMD_XMIT_SEQUENCE_CR:
  1013. case CMD_XMIT_SEQUENCE_CX:
  1014. case CMD_XMIT_BCAST_CN:
  1015. case CMD_XMIT_BCAST_CX:
  1016. case CMD_ELS_REQUEST_CR:
  1017. case CMD_ELS_REQUEST_CX:
  1018. case CMD_CREATE_XRI_CR:
  1019. case CMD_CREATE_XRI_CX:
  1020. case CMD_GET_RPI_CN:
  1021. case CMD_XMIT_ELS_RSP_CX:
  1022. case CMD_GET_RPI_CR:
  1023. case CMD_FCP_IWRITE_CR:
  1024. case CMD_FCP_IWRITE_CX:
  1025. case CMD_FCP_IREAD_CR:
  1026. case CMD_FCP_IREAD_CX:
  1027. case CMD_FCP_ICMND_CR:
  1028. case CMD_FCP_ICMND_CX:
  1029. case CMD_FCP_TSEND_CX:
  1030. case CMD_FCP_TRSP_CX:
  1031. case CMD_FCP_TRECEIVE_CX:
  1032. case CMD_FCP_AUTO_TRSP_CX:
  1033. case CMD_ADAPTER_MSG:
  1034. case CMD_ADAPTER_DUMP:
  1035. case CMD_XMIT_SEQUENCE64_CR:
  1036. case CMD_XMIT_SEQUENCE64_CX:
  1037. case CMD_XMIT_BCAST64_CN:
  1038. case CMD_XMIT_BCAST64_CX:
  1039. case CMD_ELS_REQUEST64_CR:
  1040. case CMD_ELS_REQUEST64_CX:
  1041. case CMD_FCP_IWRITE64_CR:
  1042. case CMD_FCP_IWRITE64_CX:
  1043. case CMD_FCP_IREAD64_CR:
  1044. case CMD_FCP_IREAD64_CX:
  1045. case CMD_FCP_ICMND64_CR:
  1046. case CMD_FCP_ICMND64_CX:
  1047. case CMD_FCP_TSEND64_CX:
  1048. case CMD_FCP_TRSP64_CX:
  1049. case CMD_FCP_TRECEIVE64_CX:
  1050. case CMD_GEN_REQUEST64_CR:
  1051. case CMD_GEN_REQUEST64_CX:
  1052. case CMD_XMIT_ELS_RSP64_CX:
  1053. case DSSCMD_IWRITE64_CR:
  1054. case DSSCMD_IWRITE64_CX:
  1055. case DSSCMD_IREAD64_CR:
  1056. case DSSCMD_IREAD64_CX:
  1057. type = LPFC_SOL_IOCB;
  1058. break;
  1059. case CMD_ABORT_XRI_CN:
  1060. case CMD_ABORT_XRI_CX:
  1061. case CMD_CLOSE_XRI_CN:
  1062. case CMD_CLOSE_XRI_CX:
  1063. case CMD_XRI_ABORTED_CX:
  1064. case CMD_ABORT_MXRI64_CN:
  1065. case CMD_XMIT_BLS_RSP64_CX:
  1066. type = LPFC_ABORT_IOCB;
  1067. break;
  1068. case CMD_RCV_SEQUENCE_CX:
  1069. case CMD_RCV_ELS_REQ_CX:
  1070. case CMD_RCV_SEQUENCE64_CX:
  1071. case CMD_RCV_ELS_REQ64_CX:
  1072. case CMD_ASYNC_STATUS:
  1073. case CMD_IOCB_RCV_SEQ64_CX:
  1074. case CMD_IOCB_RCV_ELS64_CX:
  1075. case CMD_IOCB_RCV_CONT64_CX:
  1076. case CMD_IOCB_RET_XRI64_CX:
  1077. type = LPFC_UNSOL_IOCB;
  1078. break;
  1079. case CMD_IOCB_XMIT_MSEQ64_CR:
  1080. case CMD_IOCB_XMIT_MSEQ64_CX:
  1081. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1082. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1083. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1084. case CMD_IOCB_ABORT_EXTENDED_CN:
  1085. case CMD_IOCB_RET_HBQE64_CN:
  1086. case CMD_IOCB_FCP_IBIDIR64_CR:
  1087. case CMD_IOCB_FCP_IBIDIR64_CX:
  1088. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1089. case CMD_IOCB_LOGENTRY_CN:
  1090. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1091. printk("%s - Unhandled SLI-3 Command x%x\n",
  1092. __func__, iocb_cmnd);
  1093. type = LPFC_UNKNOWN_IOCB;
  1094. break;
  1095. default:
  1096. type = LPFC_UNKNOWN_IOCB;
  1097. break;
  1098. }
  1099. return type;
  1100. }
  1101. /**
  1102. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1103. * @phba: Pointer to HBA context object.
  1104. *
  1105. * This function is called from SLI initialization code
  1106. * to configure every ring of the HBA's SLI interface. The
  1107. * caller is not required to hold any lock. This function issues
  1108. * a config_ring mailbox command for each ring.
  1109. * This function returns zero if successful else returns a negative
  1110. * error code.
  1111. **/
  1112. static int
  1113. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1114. {
  1115. struct lpfc_sli *psli = &phba->sli;
  1116. LPFC_MBOXQ_t *pmb;
  1117. MAILBOX_t *pmbox;
  1118. int i, rc, ret = 0;
  1119. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1120. if (!pmb)
  1121. return -ENOMEM;
  1122. pmbox = &pmb->u.mb;
  1123. phba->link_state = LPFC_INIT_MBX_CMDS;
  1124. for (i = 0; i < psli->num_rings; i++) {
  1125. lpfc_config_ring(phba, i, pmb);
  1126. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1127. if (rc != MBX_SUCCESS) {
  1128. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1129. "0446 Adapter failed to init (%d), "
  1130. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1131. "ring %d\n",
  1132. rc, pmbox->mbxCommand,
  1133. pmbox->mbxStatus, i);
  1134. phba->link_state = LPFC_HBA_ERROR;
  1135. ret = -ENXIO;
  1136. break;
  1137. }
  1138. }
  1139. mempool_free(pmb, phba->mbox_mem_pool);
  1140. return ret;
  1141. }
  1142. /**
  1143. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1144. * @phba: Pointer to HBA context object.
  1145. * @pring: Pointer to driver SLI ring object.
  1146. * @piocb: Pointer to the driver iocb object.
  1147. *
  1148. * This function is called with hbalock held. The function adds the
  1149. * new iocb to txcmplq of the given ring. This function always returns
  1150. * 0. If this function is called for ELS ring, this function checks if
  1151. * there is a vport associated with the ELS command. This function also
  1152. * starts els_tmofunc timer if this is an ELS command.
  1153. **/
  1154. static int
  1155. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1156. struct lpfc_iocbq *piocb)
  1157. {
  1158. list_add_tail(&piocb->list, &pring->txcmplq);
  1159. piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
  1160. pring->txcmplq_cnt++;
  1161. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1162. pring->txcmplq_max = pring->txcmplq_cnt;
  1163. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1164. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1165. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1166. if (!piocb->vport)
  1167. BUG();
  1168. else
  1169. mod_timer(&piocb->vport->els_tmofunc,
  1170. jiffies + HZ * (phba->fc_ratov << 1));
  1171. }
  1172. return 0;
  1173. }
  1174. /**
  1175. * lpfc_sli_ringtx_get - Get first element of the txq
  1176. * @phba: Pointer to HBA context object.
  1177. * @pring: Pointer to driver SLI ring object.
  1178. *
  1179. * This function is called with hbalock held to get next
  1180. * iocb in txq of the given ring. If there is any iocb in
  1181. * the txq, the function returns first iocb in the list after
  1182. * removing the iocb from the list, else it returns NULL.
  1183. **/
  1184. struct lpfc_iocbq *
  1185. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1186. {
  1187. struct lpfc_iocbq *cmd_iocb;
  1188. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1189. if (cmd_iocb != NULL)
  1190. pring->txq_cnt--;
  1191. return cmd_iocb;
  1192. }
  1193. /**
  1194. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1195. * @phba: Pointer to HBA context object.
  1196. * @pring: Pointer to driver SLI ring object.
  1197. *
  1198. * This function is called with hbalock held and the caller must post the
  1199. * iocb without releasing the lock. If the caller releases the lock,
  1200. * iocb slot returned by the function is not guaranteed to be available.
  1201. * The function returns pointer to the next available iocb slot if there
  1202. * is available slot in the ring, else it returns NULL.
  1203. * If the get index of the ring is ahead of the put index, the function
  1204. * will post an error attention event to the worker thread to take the
  1205. * HBA to offline state.
  1206. **/
  1207. static IOCB_t *
  1208. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1209. {
  1210. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1211. uint32_t max_cmd_idx = pring->numCiocb;
  1212. if ((pring->next_cmdidx == pring->cmdidx) &&
  1213. (++pring->next_cmdidx >= max_cmd_idx))
  1214. pring->next_cmdidx = 0;
  1215. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1216. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1217. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1218. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1219. "0315 Ring %d issue: portCmdGet %d "
  1220. "is bigger than cmd ring %d\n",
  1221. pring->ringno,
  1222. pring->local_getidx, max_cmd_idx);
  1223. phba->link_state = LPFC_HBA_ERROR;
  1224. /*
  1225. * All error attention handlers are posted to
  1226. * worker thread
  1227. */
  1228. phba->work_ha |= HA_ERATT;
  1229. phba->work_hs = HS_FFER3;
  1230. lpfc_worker_wake_up(phba);
  1231. return NULL;
  1232. }
  1233. if (pring->local_getidx == pring->next_cmdidx)
  1234. return NULL;
  1235. }
  1236. return lpfc_cmd_iocb(phba, pring);
  1237. }
  1238. /**
  1239. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1240. * @phba: Pointer to HBA context object.
  1241. * @iocbq: Pointer to driver iocb object.
  1242. *
  1243. * This function gets an iotag for the iocb. If there is no unused iotag and
  1244. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1245. * array and assigns a new iotag.
  1246. * The function returns the allocated iotag if successful, else returns zero.
  1247. * Zero is not a valid iotag.
  1248. * The caller is not required to hold any lock.
  1249. **/
  1250. uint16_t
  1251. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1252. {
  1253. struct lpfc_iocbq **new_arr;
  1254. struct lpfc_iocbq **old_arr;
  1255. size_t new_len;
  1256. struct lpfc_sli *psli = &phba->sli;
  1257. uint16_t iotag;
  1258. spin_lock_irq(&phba->hbalock);
  1259. iotag = psli->last_iotag;
  1260. if(++iotag < psli->iocbq_lookup_len) {
  1261. psli->last_iotag = iotag;
  1262. psli->iocbq_lookup[iotag] = iocbq;
  1263. spin_unlock_irq(&phba->hbalock);
  1264. iocbq->iotag = iotag;
  1265. return iotag;
  1266. } else if (psli->iocbq_lookup_len < (0xffff
  1267. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1268. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1269. spin_unlock_irq(&phba->hbalock);
  1270. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1271. GFP_KERNEL);
  1272. if (new_arr) {
  1273. spin_lock_irq(&phba->hbalock);
  1274. old_arr = psli->iocbq_lookup;
  1275. if (new_len <= psli->iocbq_lookup_len) {
  1276. /* highly unprobable case */
  1277. kfree(new_arr);
  1278. iotag = psli->last_iotag;
  1279. if(++iotag < psli->iocbq_lookup_len) {
  1280. psli->last_iotag = iotag;
  1281. psli->iocbq_lookup[iotag] = iocbq;
  1282. spin_unlock_irq(&phba->hbalock);
  1283. iocbq->iotag = iotag;
  1284. return iotag;
  1285. }
  1286. spin_unlock_irq(&phba->hbalock);
  1287. return 0;
  1288. }
  1289. if (psli->iocbq_lookup)
  1290. memcpy(new_arr, old_arr,
  1291. ((psli->last_iotag + 1) *
  1292. sizeof (struct lpfc_iocbq *)));
  1293. psli->iocbq_lookup = new_arr;
  1294. psli->iocbq_lookup_len = new_len;
  1295. psli->last_iotag = iotag;
  1296. psli->iocbq_lookup[iotag] = iocbq;
  1297. spin_unlock_irq(&phba->hbalock);
  1298. iocbq->iotag = iotag;
  1299. kfree(old_arr);
  1300. return iotag;
  1301. }
  1302. } else
  1303. spin_unlock_irq(&phba->hbalock);
  1304. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1305. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1306. psli->last_iotag);
  1307. return 0;
  1308. }
  1309. /**
  1310. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1311. * @phba: Pointer to HBA context object.
  1312. * @pring: Pointer to driver SLI ring object.
  1313. * @iocb: Pointer to iocb slot in the ring.
  1314. * @nextiocb: Pointer to driver iocb object which need to be
  1315. * posted to firmware.
  1316. *
  1317. * This function is called with hbalock held to post a new iocb to
  1318. * the firmware. This function copies the new iocb to ring iocb slot and
  1319. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1320. * a completion call back for this iocb else the function will free the
  1321. * iocb object.
  1322. **/
  1323. static void
  1324. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1325. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1326. {
  1327. /*
  1328. * Set up an iotag
  1329. */
  1330. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1331. if (pring->ringno == LPFC_ELS_RING) {
  1332. lpfc_debugfs_slow_ring_trc(phba,
  1333. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1334. *(((uint32_t *) &nextiocb->iocb) + 4),
  1335. *(((uint32_t *) &nextiocb->iocb) + 6),
  1336. *(((uint32_t *) &nextiocb->iocb) + 7));
  1337. }
  1338. /*
  1339. * Issue iocb command to adapter
  1340. */
  1341. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1342. wmb();
  1343. pring->stats.iocb_cmd++;
  1344. /*
  1345. * If there is no completion routine to call, we can release the
  1346. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1347. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1348. */
  1349. if (nextiocb->iocb_cmpl)
  1350. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1351. else
  1352. __lpfc_sli_release_iocbq(phba, nextiocb);
  1353. /*
  1354. * Let the HBA know what IOCB slot will be the next one the
  1355. * driver will put a command into.
  1356. */
  1357. pring->cmdidx = pring->next_cmdidx;
  1358. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1359. }
  1360. /**
  1361. * lpfc_sli_update_full_ring - Update the chip attention register
  1362. * @phba: Pointer to HBA context object.
  1363. * @pring: Pointer to driver SLI ring object.
  1364. *
  1365. * The caller is not required to hold any lock for calling this function.
  1366. * This function updates the chip attention bits for the ring to inform firmware
  1367. * that there are pending work to be done for this ring and requests an
  1368. * interrupt when there is space available in the ring. This function is
  1369. * called when the driver is unable to post more iocbs to the ring due
  1370. * to unavailability of space in the ring.
  1371. **/
  1372. static void
  1373. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1374. {
  1375. int ringno = pring->ringno;
  1376. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1377. wmb();
  1378. /*
  1379. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1380. * The HBA will tell us when an IOCB entry is available.
  1381. */
  1382. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1383. readl(phba->CAregaddr); /* flush */
  1384. pring->stats.iocb_cmd_full++;
  1385. }
  1386. /**
  1387. * lpfc_sli_update_ring - Update chip attention register
  1388. * @phba: Pointer to HBA context object.
  1389. * @pring: Pointer to driver SLI ring object.
  1390. *
  1391. * This function updates the chip attention register bit for the
  1392. * given ring to inform HBA that there is more work to be done
  1393. * in this ring. The caller is not required to hold any lock.
  1394. **/
  1395. static void
  1396. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1397. {
  1398. int ringno = pring->ringno;
  1399. /*
  1400. * Tell the HBA that there is work to do in this ring.
  1401. */
  1402. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1403. wmb();
  1404. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1405. readl(phba->CAregaddr); /* flush */
  1406. }
  1407. }
  1408. /**
  1409. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1410. * @phba: Pointer to HBA context object.
  1411. * @pring: Pointer to driver SLI ring object.
  1412. *
  1413. * This function is called with hbalock held to post pending iocbs
  1414. * in the txq to the firmware. This function is called when driver
  1415. * detects space available in the ring.
  1416. **/
  1417. static void
  1418. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1419. {
  1420. IOCB_t *iocb;
  1421. struct lpfc_iocbq *nextiocb;
  1422. /*
  1423. * Check to see if:
  1424. * (a) there is anything on the txq to send
  1425. * (b) link is up
  1426. * (c) link attention events can be processed (fcp ring only)
  1427. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1428. */
  1429. if (pring->txq_cnt &&
  1430. lpfc_is_link_up(phba) &&
  1431. (pring->ringno != phba->sli.fcp_ring ||
  1432. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1433. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1434. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1435. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1436. if (iocb)
  1437. lpfc_sli_update_ring(phba, pring);
  1438. else
  1439. lpfc_sli_update_full_ring(phba, pring);
  1440. }
  1441. return;
  1442. }
  1443. /**
  1444. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1445. * @phba: Pointer to HBA context object.
  1446. * @hbqno: HBQ number.
  1447. *
  1448. * This function is called with hbalock held to get the next
  1449. * available slot for the given HBQ. If there is free slot
  1450. * available for the HBQ it will return pointer to the next available
  1451. * HBQ entry else it will return NULL.
  1452. **/
  1453. static struct lpfc_hbq_entry *
  1454. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1455. {
  1456. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1457. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1458. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1459. hbqp->next_hbqPutIdx = 0;
  1460. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1461. uint32_t raw_index = phba->hbq_get[hbqno];
  1462. uint32_t getidx = le32_to_cpu(raw_index);
  1463. hbqp->local_hbqGetIdx = getidx;
  1464. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1465. lpfc_printf_log(phba, KERN_ERR,
  1466. LOG_SLI | LOG_VPORT,
  1467. "1802 HBQ %d: local_hbqGetIdx "
  1468. "%u is > than hbqp->entry_count %u\n",
  1469. hbqno, hbqp->local_hbqGetIdx,
  1470. hbqp->entry_count);
  1471. phba->link_state = LPFC_HBA_ERROR;
  1472. return NULL;
  1473. }
  1474. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1475. return NULL;
  1476. }
  1477. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1478. hbqp->hbqPutIdx;
  1479. }
  1480. /**
  1481. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1482. * @phba: Pointer to HBA context object.
  1483. *
  1484. * This function is called with no lock held to free all the
  1485. * hbq buffers while uninitializing the SLI interface. It also
  1486. * frees the HBQ buffers returned by the firmware but not yet
  1487. * processed by the upper layers.
  1488. **/
  1489. void
  1490. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1491. {
  1492. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1493. struct hbq_dmabuf *hbq_buf;
  1494. unsigned long flags;
  1495. int i, hbq_count;
  1496. uint32_t hbqno;
  1497. hbq_count = lpfc_sli_hbq_count();
  1498. /* Return all memory used by all HBQs */
  1499. spin_lock_irqsave(&phba->hbalock, flags);
  1500. for (i = 0; i < hbq_count; ++i) {
  1501. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1502. &phba->hbqs[i].hbq_buffer_list, list) {
  1503. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1504. list_del(&hbq_buf->dbuf.list);
  1505. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1506. }
  1507. phba->hbqs[i].buffer_count = 0;
  1508. }
  1509. /* Return all HBQ buffer that are in-fly */
  1510. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1511. list) {
  1512. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1513. list_del(&hbq_buf->dbuf.list);
  1514. if (hbq_buf->tag == -1) {
  1515. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1516. (phba, hbq_buf);
  1517. } else {
  1518. hbqno = hbq_buf->tag >> 16;
  1519. if (hbqno >= LPFC_MAX_HBQS)
  1520. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1521. (phba, hbq_buf);
  1522. else
  1523. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1524. hbq_buf);
  1525. }
  1526. }
  1527. /* Mark the HBQs not in use */
  1528. phba->hbq_in_use = 0;
  1529. spin_unlock_irqrestore(&phba->hbalock, flags);
  1530. }
  1531. /**
  1532. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1533. * @phba: Pointer to HBA context object.
  1534. * @hbqno: HBQ number.
  1535. * @hbq_buf: Pointer to HBQ buffer.
  1536. *
  1537. * This function is called with the hbalock held to post a
  1538. * hbq buffer to the firmware. If the function finds an empty
  1539. * slot in the HBQ, it will post the buffer. The function will return
  1540. * pointer to the hbq entry if it successfully post the buffer
  1541. * else it will return NULL.
  1542. **/
  1543. static int
  1544. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1545. struct hbq_dmabuf *hbq_buf)
  1546. {
  1547. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1548. }
  1549. /**
  1550. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1551. * @phba: Pointer to HBA context object.
  1552. * @hbqno: HBQ number.
  1553. * @hbq_buf: Pointer to HBQ buffer.
  1554. *
  1555. * This function is called with the hbalock held to post a hbq buffer to the
  1556. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1557. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1558. * it successfully post the buffer else it will return an error.
  1559. **/
  1560. static int
  1561. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1562. struct hbq_dmabuf *hbq_buf)
  1563. {
  1564. struct lpfc_hbq_entry *hbqe;
  1565. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1566. /* Get next HBQ entry slot to use */
  1567. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1568. if (hbqe) {
  1569. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1570. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1571. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1572. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1573. hbqe->bde.tus.f.bdeFlags = 0;
  1574. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1575. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1576. /* Sync SLIM */
  1577. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1578. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1579. /* flush */
  1580. readl(phba->hbq_put + hbqno);
  1581. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1582. return 0;
  1583. } else
  1584. return -ENOMEM;
  1585. }
  1586. /**
  1587. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1588. * @phba: Pointer to HBA context object.
  1589. * @hbqno: HBQ number.
  1590. * @hbq_buf: Pointer to HBQ buffer.
  1591. *
  1592. * This function is called with the hbalock held to post an RQE to the SLI4
  1593. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1594. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1595. **/
  1596. static int
  1597. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1598. struct hbq_dmabuf *hbq_buf)
  1599. {
  1600. int rc;
  1601. struct lpfc_rqe hrqe;
  1602. struct lpfc_rqe drqe;
  1603. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1604. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1605. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1606. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1607. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1608. &hrqe, &drqe);
  1609. if (rc < 0)
  1610. return rc;
  1611. hbq_buf->tag = rc;
  1612. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1613. return 0;
  1614. }
  1615. /* HBQ for ELS and CT traffic. */
  1616. static struct lpfc_hbq_init lpfc_els_hbq = {
  1617. .rn = 1,
  1618. .entry_count = 256,
  1619. .mask_count = 0,
  1620. .profile = 0,
  1621. .ring_mask = (1 << LPFC_ELS_RING),
  1622. .buffer_count = 0,
  1623. .init_count = 40,
  1624. .add_count = 40,
  1625. };
  1626. /* HBQ for the extra ring if needed */
  1627. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1628. .rn = 1,
  1629. .entry_count = 200,
  1630. .mask_count = 0,
  1631. .profile = 0,
  1632. .ring_mask = (1 << LPFC_EXTRA_RING),
  1633. .buffer_count = 0,
  1634. .init_count = 0,
  1635. .add_count = 5,
  1636. };
  1637. /* Array of HBQs */
  1638. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1639. &lpfc_els_hbq,
  1640. &lpfc_extra_hbq,
  1641. };
  1642. /**
  1643. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1644. * @phba: Pointer to HBA context object.
  1645. * @hbqno: HBQ number.
  1646. * @count: Number of HBQ buffers to be posted.
  1647. *
  1648. * This function is called with no lock held to post more hbq buffers to the
  1649. * given HBQ. The function returns the number of HBQ buffers successfully
  1650. * posted.
  1651. **/
  1652. static int
  1653. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1654. {
  1655. uint32_t i, posted = 0;
  1656. unsigned long flags;
  1657. struct hbq_dmabuf *hbq_buffer;
  1658. LIST_HEAD(hbq_buf_list);
  1659. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1660. return 0;
  1661. if ((phba->hbqs[hbqno].buffer_count + count) >
  1662. lpfc_hbq_defs[hbqno]->entry_count)
  1663. count = lpfc_hbq_defs[hbqno]->entry_count -
  1664. phba->hbqs[hbqno].buffer_count;
  1665. if (!count)
  1666. return 0;
  1667. /* Allocate HBQ entries */
  1668. for (i = 0; i < count; i++) {
  1669. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1670. if (!hbq_buffer)
  1671. break;
  1672. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1673. }
  1674. /* Check whether HBQ is still in use */
  1675. spin_lock_irqsave(&phba->hbalock, flags);
  1676. if (!phba->hbq_in_use)
  1677. goto err;
  1678. while (!list_empty(&hbq_buf_list)) {
  1679. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1680. dbuf.list);
  1681. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1682. (hbqno << 16));
  1683. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1684. phba->hbqs[hbqno].buffer_count++;
  1685. posted++;
  1686. } else
  1687. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1688. }
  1689. spin_unlock_irqrestore(&phba->hbalock, flags);
  1690. return posted;
  1691. err:
  1692. spin_unlock_irqrestore(&phba->hbalock, flags);
  1693. while (!list_empty(&hbq_buf_list)) {
  1694. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1695. dbuf.list);
  1696. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1697. }
  1698. return 0;
  1699. }
  1700. /**
  1701. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1702. * @phba: Pointer to HBA context object.
  1703. * @qno: HBQ number.
  1704. *
  1705. * This function posts more buffers to the HBQ. This function
  1706. * is called with no lock held. The function returns the number of HBQ entries
  1707. * successfully allocated.
  1708. **/
  1709. int
  1710. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1711. {
  1712. if (phba->sli_rev == LPFC_SLI_REV4)
  1713. return 0;
  1714. else
  1715. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1716. lpfc_hbq_defs[qno]->add_count);
  1717. }
  1718. /**
  1719. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1720. * @phba: Pointer to HBA context object.
  1721. * @qno: HBQ queue number.
  1722. *
  1723. * This function is called from SLI initialization code path with
  1724. * no lock held to post initial HBQ buffers to firmware. The
  1725. * function returns the number of HBQ entries successfully allocated.
  1726. **/
  1727. static int
  1728. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1729. {
  1730. if (phba->sli_rev == LPFC_SLI_REV4)
  1731. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1732. lpfc_hbq_defs[qno]->entry_count);
  1733. else
  1734. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1735. lpfc_hbq_defs[qno]->init_count);
  1736. }
  1737. /**
  1738. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1739. * @phba: Pointer to HBA context object.
  1740. * @hbqno: HBQ number.
  1741. *
  1742. * This function removes the first hbq buffer on an hbq list and returns a
  1743. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1744. **/
  1745. static struct hbq_dmabuf *
  1746. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1747. {
  1748. struct lpfc_dmabuf *d_buf;
  1749. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1750. if (!d_buf)
  1751. return NULL;
  1752. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1753. }
  1754. /**
  1755. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1756. * @phba: Pointer to HBA context object.
  1757. * @tag: Tag of the hbq buffer.
  1758. *
  1759. * This function is called with hbalock held. This function searches
  1760. * for the hbq buffer associated with the given tag in the hbq buffer
  1761. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1762. * it returns NULL.
  1763. **/
  1764. static struct hbq_dmabuf *
  1765. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1766. {
  1767. struct lpfc_dmabuf *d_buf;
  1768. struct hbq_dmabuf *hbq_buf;
  1769. uint32_t hbqno;
  1770. hbqno = tag >> 16;
  1771. if (hbqno >= LPFC_MAX_HBQS)
  1772. return NULL;
  1773. spin_lock_irq(&phba->hbalock);
  1774. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1775. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1776. if (hbq_buf->tag == tag) {
  1777. spin_unlock_irq(&phba->hbalock);
  1778. return hbq_buf;
  1779. }
  1780. }
  1781. spin_unlock_irq(&phba->hbalock);
  1782. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1783. "1803 Bad hbq tag. Data: x%x x%x\n",
  1784. tag, phba->hbqs[tag >> 16].buffer_count);
  1785. return NULL;
  1786. }
  1787. /**
  1788. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1789. * @phba: Pointer to HBA context object.
  1790. * @hbq_buffer: Pointer to HBQ buffer.
  1791. *
  1792. * This function is called with hbalock. This function gives back
  1793. * the hbq buffer to firmware. If the HBQ does not have space to
  1794. * post the buffer, it will free the buffer.
  1795. **/
  1796. void
  1797. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1798. {
  1799. uint32_t hbqno;
  1800. if (hbq_buffer) {
  1801. hbqno = hbq_buffer->tag >> 16;
  1802. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1803. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1804. }
  1805. }
  1806. /**
  1807. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1808. * @mbxCommand: mailbox command code.
  1809. *
  1810. * This function is called by the mailbox event handler function to verify
  1811. * that the completed mailbox command is a legitimate mailbox command. If the
  1812. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1813. * and the mailbox event handler will take the HBA offline.
  1814. **/
  1815. static int
  1816. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1817. {
  1818. uint8_t ret;
  1819. switch (mbxCommand) {
  1820. case MBX_LOAD_SM:
  1821. case MBX_READ_NV:
  1822. case MBX_WRITE_NV:
  1823. case MBX_WRITE_VPARMS:
  1824. case MBX_RUN_BIU_DIAG:
  1825. case MBX_INIT_LINK:
  1826. case MBX_DOWN_LINK:
  1827. case MBX_CONFIG_LINK:
  1828. case MBX_CONFIG_RING:
  1829. case MBX_RESET_RING:
  1830. case MBX_READ_CONFIG:
  1831. case MBX_READ_RCONFIG:
  1832. case MBX_READ_SPARM:
  1833. case MBX_READ_STATUS:
  1834. case MBX_READ_RPI:
  1835. case MBX_READ_XRI:
  1836. case MBX_READ_REV:
  1837. case MBX_READ_LNK_STAT:
  1838. case MBX_REG_LOGIN:
  1839. case MBX_UNREG_LOGIN:
  1840. case MBX_CLEAR_LA:
  1841. case MBX_DUMP_MEMORY:
  1842. case MBX_DUMP_CONTEXT:
  1843. case MBX_RUN_DIAGS:
  1844. case MBX_RESTART:
  1845. case MBX_UPDATE_CFG:
  1846. case MBX_DOWN_LOAD:
  1847. case MBX_DEL_LD_ENTRY:
  1848. case MBX_RUN_PROGRAM:
  1849. case MBX_SET_MASK:
  1850. case MBX_SET_VARIABLE:
  1851. case MBX_UNREG_D_ID:
  1852. case MBX_KILL_BOARD:
  1853. case MBX_CONFIG_FARP:
  1854. case MBX_BEACON:
  1855. case MBX_LOAD_AREA:
  1856. case MBX_RUN_BIU_DIAG64:
  1857. case MBX_CONFIG_PORT:
  1858. case MBX_READ_SPARM64:
  1859. case MBX_READ_RPI64:
  1860. case MBX_REG_LOGIN64:
  1861. case MBX_READ_TOPOLOGY:
  1862. case MBX_WRITE_WWN:
  1863. case MBX_SET_DEBUG:
  1864. case MBX_LOAD_EXP_ROM:
  1865. case MBX_ASYNCEVT_ENABLE:
  1866. case MBX_REG_VPI:
  1867. case MBX_UNREG_VPI:
  1868. case MBX_HEARTBEAT:
  1869. case MBX_PORT_CAPABILITIES:
  1870. case MBX_PORT_IOV_CONTROL:
  1871. case MBX_SLI4_CONFIG:
  1872. case MBX_SLI4_REQ_FTRS:
  1873. case MBX_REG_FCFI:
  1874. case MBX_UNREG_FCFI:
  1875. case MBX_REG_VFI:
  1876. case MBX_UNREG_VFI:
  1877. case MBX_INIT_VPI:
  1878. case MBX_INIT_VFI:
  1879. case MBX_RESUME_RPI:
  1880. case MBX_READ_EVENT_LOG_STATUS:
  1881. case MBX_READ_EVENT_LOG:
  1882. case MBX_SECURITY_MGMT:
  1883. case MBX_AUTH_PORT:
  1884. ret = mbxCommand;
  1885. break;
  1886. default:
  1887. ret = MBX_SHUTDOWN;
  1888. break;
  1889. }
  1890. return ret;
  1891. }
  1892. /**
  1893. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1894. * @phba: Pointer to HBA context object.
  1895. * @pmboxq: Pointer to mailbox command.
  1896. *
  1897. * This is completion handler function for mailbox commands issued from
  1898. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1899. * mailbox event handler function with no lock held. This function
  1900. * will wake up thread waiting on the wait queue pointed by context1
  1901. * of the mailbox.
  1902. **/
  1903. void
  1904. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1905. {
  1906. wait_queue_head_t *pdone_q;
  1907. unsigned long drvr_flag;
  1908. /*
  1909. * If pdone_q is empty, the driver thread gave up waiting and
  1910. * continued running.
  1911. */
  1912. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1913. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1914. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1915. if (pdone_q)
  1916. wake_up_interruptible(pdone_q);
  1917. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1918. return;
  1919. }
  1920. /**
  1921. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1922. * @phba: Pointer to HBA context object.
  1923. * @pmb: Pointer to mailbox object.
  1924. *
  1925. * This function is the default mailbox completion handler. It
  1926. * frees the memory resources associated with the completed mailbox
  1927. * command. If the completed command is a REG_LOGIN mailbox command,
  1928. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1929. **/
  1930. void
  1931. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1932. {
  1933. struct lpfc_vport *vport = pmb->vport;
  1934. struct lpfc_dmabuf *mp;
  1935. struct lpfc_nodelist *ndlp;
  1936. struct Scsi_Host *shost;
  1937. uint16_t rpi, vpi;
  1938. int rc;
  1939. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1940. if (mp) {
  1941. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1942. kfree(mp);
  1943. }
  1944. /*
  1945. * If a REG_LOGIN succeeded after node is destroyed or node
  1946. * is in re-discovery driver need to cleanup the RPI.
  1947. */
  1948. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1949. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1950. !pmb->u.mb.mbxStatus) {
  1951. rpi = pmb->u.mb.un.varWords[0];
  1952. vpi = pmb->u.mb.un.varRegLogin.vpi;
  1953. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1954. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1955. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1956. if (rc != MBX_NOT_FINISHED)
  1957. return;
  1958. }
  1959. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1960. !(phba->pport->load_flag & FC_UNLOADING) &&
  1961. !pmb->u.mb.mbxStatus) {
  1962. shost = lpfc_shost_from_vport(vport);
  1963. spin_lock_irq(shost->host_lock);
  1964. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1965. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1966. spin_unlock_irq(shost->host_lock);
  1967. }
  1968. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1969. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1970. lpfc_nlp_put(ndlp);
  1971. pmb->context2 = NULL;
  1972. }
  1973. /* Check security permission status on INIT_LINK mailbox command */
  1974. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1975. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1976. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1977. "2860 SLI authentication is required "
  1978. "for INIT_LINK but has not done yet\n");
  1979. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1980. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1981. else
  1982. mempool_free(pmb, phba->mbox_mem_pool);
  1983. }
  1984. /**
  1985. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  1986. * @phba: Pointer to HBA context object.
  1987. *
  1988. * This function is called with no lock held. This function processes all
  1989. * the completed mailbox commands and gives it to upper layers. The interrupt
  1990. * service routine processes mailbox completion interrupt and adds completed
  1991. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  1992. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  1993. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  1994. * function returns the mailbox commands to the upper layer by calling the
  1995. * completion handler function of each mailbox.
  1996. **/
  1997. int
  1998. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  1999. {
  2000. MAILBOX_t *pmbox;
  2001. LPFC_MBOXQ_t *pmb;
  2002. int rc;
  2003. LIST_HEAD(cmplq);
  2004. phba->sli.slistat.mbox_event++;
  2005. /* Get all completed mailboxe buffers into the cmplq */
  2006. spin_lock_irq(&phba->hbalock);
  2007. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2008. spin_unlock_irq(&phba->hbalock);
  2009. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2010. do {
  2011. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2012. if (pmb == NULL)
  2013. break;
  2014. pmbox = &pmb->u.mb;
  2015. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2016. if (pmb->vport) {
  2017. lpfc_debugfs_disc_trc(pmb->vport,
  2018. LPFC_DISC_TRC_MBOX_VPORT,
  2019. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2020. (uint32_t)pmbox->mbxCommand,
  2021. pmbox->un.varWords[0],
  2022. pmbox->un.varWords[1]);
  2023. }
  2024. else {
  2025. lpfc_debugfs_disc_trc(phba->pport,
  2026. LPFC_DISC_TRC_MBOX,
  2027. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2028. (uint32_t)pmbox->mbxCommand,
  2029. pmbox->un.varWords[0],
  2030. pmbox->un.varWords[1]);
  2031. }
  2032. }
  2033. /*
  2034. * It is a fatal error if unknown mbox command completion.
  2035. */
  2036. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2037. MBX_SHUTDOWN) {
  2038. /* Unknown mailbox command compl */
  2039. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2040. "(%d):0323 Unknown Mailbox command "
  2041. "x%x (x%x/x%x) Cmpl\n",
  2042. pmb->vport ? pmb->vport->vpi : 0,
  2043. pmbox->mbxCommand,
  2044. lpfc_sli_config_mbox_subsys_get(phba,
  2045. pmb),
  2046. lpfc_sli_config_mbox_opcode_get(phba,
  2047. pmb));
  2048. phba->link_state = LPFC_HBA_ERROR;
  2049. phba->work_hs = HS_FFER3;
  2050. lpfc_handle_eratt(phba);
  2051. continue;
  2052. }
  2053. if (pmbox->mbxStatus) {
  2054. phba->sli.slistat.mbox_stat_err++;
  2055. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2056. /* Mbox cmd cmpl error - RETRYing */
  2057. lpfc_printf_log(phba, KERN_INFO,
  2058. LOG_MBOX | LOG_SLI,
  2059. "(%d):0305 Mbox cmd cmpl "
  2060. "error - RETRYing Data: x%x "
  2061. "(x%x/x%x) x%x x%x x%x\n",
  2062. pmb->vport ? pmb->vport->vpi : 0,
  2063. pmbox->mbxCommand,
  2064. lpfc_sli_config_mbox_subsys_get(phba,
  2065. pmb),
  2066. lpfc_sli_config_mbox_opcode_get(phba,
  2067. pmb),
  2068. pmbox->mbxStatus,
  2069. pmbox->un.varWords[0],
  2070. pmb->vport->port_state);
  2071. pmbox->mbxStatus = 0;
  2072. pmbox->mbxOwner = OWN_HOST;
  2073. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2074. if (rc != MBX_NOT_FINISHED)
  2075. continue;
  2076. }
  2077. }
  2078. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2079. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2080. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2081. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2082. pmb->vport ? pmb->vport->vpi : 0,
  2083. pmbox->mbxCommand,
  2084. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2085. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2086. pmb->mbox_cmpl,
  2087. *((uint32_t *) pmbox),
  2088. pmbox->un.varWords[0],
  2089. pmbox->un.varWords[1],
  2090. pmbox->un.varWords[2],
  2091. pmbox->un.varWords[3],
  2092. pmbox->un.varWords[4],
  2093. pmbox->un.varWords[5],
  2094. pmbox->un.varWords[6],
  2095. pmbox->un.varWords[7]);
  2096. if (pmb->mbox_cmpl)
  2097. pmb->mbox_cmpl(phba,pmb);
  2098. } while (1);
  2099. return 0;
  2100. }
  2101. /**
  2102. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2103. * @phba: Pointer to HBA context object.
  2104. * @pring: Pointer to driver SLI ring object.
  2105. * @tag: buffer tag.
  2106. *
  2107. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2108. * is set in the tag the buffer is posted for a particular exchange,
  2109. * the function will return the buffer without replacing the buffer.
  2110. * If the buffer is for unsolicited ELS or CT traffic, this function
  2111. * returns the buffer and also posts another buffer to the firmware.
  2112. **/
  2113. static struct lpfc_dmabuf *
  2114. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2115. struct lpfc_sli_ring *pring,
  2116. uint32_t tag)
  2117. {
  2118. struct hbq_dmabuf *hbq_entry;
  2119. if (tag & QUE_BUFTAG_BIT)
  2120. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2121. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2122. if (!hbq_entry)
  2123. return NULL;
  2124. return &hbq_entry->dbuf;
  2125. }
  2126. /**
  2127. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2128. * @phba: Pointer to HBA context object.
  2129. * @pring: Pointer to driver SLI ring object.
  2130. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2131. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2132. * @fch_type: the type for the first frame of the sequence.
  2133. *
  2134. * This function is called with no lock held. This function uses the r_ctl and
  2135. * type of the received sequence to find the correct callback function to call
  2136. * to process the sequence.
  2137. **/
  2138. static int
  2139. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2140. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2141. uint32_t fch_type)
  2142. {
  2143. int i;
  2144. /* unSolicited Responses */
  2145. if (pring->prt[0].profile) {
  2146. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2147. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2148. saveq);
  2149. return 1;
  2150. }
  2151. /* We must search, based on rctl / type
  2152. for the right routine */
  2153. for (i = 0; i < pring->num_mask; i++) {
  2154. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2155. (pring->prt[i].type == fch_type)) {
  2156. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2157. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2158. (phba, pring, saveq);
  2159. return 1;
  2160. }
  2161. }
  2162. return 0;
  2163. }
  2164. /**
  2165. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2166. * @phba: Pointer to HBA context object.
  2167. * @pring: Pointer to driver SLI ring object.
  2168. * @saveq: Pointer to the unsolicited iocb.
  2169. *
  2170. * This function is called with no lock held by the ring event handler
  2171. * when there is an unsolicited iocb posted to the response ring by the
  2172. * firmware. This function gets the buffer associated with the iocbs
  2173. * and calls the event handler for the ring. This function handles both
  2174. * qring buffers and hbq buffers.
  2175. * When the function returns 1 the caller can free the iocb object otherwise
  2176. * upper layer functions will free the iocb objects.
  2177. **/
  2178. static int
  2179. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2180. struct lpfc_iocbq *saveq)
  2181. {
  2182. IOCB_t * irsp;
  2183. WORD5 * w5p;
  2184. uint32_t Rctl, Type;
  2185. uint32_t match;
  2186. struct lpfc_iocbq *iocbq;
  2187. struct lpfc_dmabuf *dmzbuf;
  2188. match = 0;
  2189. irsp = &(saveq->iocb);
  2190. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2191. if (pring->lpfc_sli_rcv_async_status)
  2192. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2193. else
  2194. lpfc_printf_log(phba,
  2195. KERN_WARNING,
  2196. LOG_SLI,
  2197. "0316 Ring %d handler: unexpected "
  2198. "ASYNC_STATUS iocb received evt_code "
  2199. "0x%x\n",
  2200. pring->ringno,
  2201. irsp->un.asyncstat.evt_code);
  2202. return 1;
  2203. }
  2204. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2205. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2206. if (irsp->ulpBdeCount > 0) {
  2207. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2208. irsp->un.ulpWord[3]);
  2209. lpfc_in_buf_free(phba, dmzbuf);
  2210. }
  2211. if (irsp->ulpBdeCount > 1) {
  2212. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2213. irsp->unsli3.sli3Words[3]);
  2214. lpfc_in_buf_free(phba, dmzbuf);
  2215. }
  2216. if (irsp->ulpBdeCount > 2) {
  2217. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2218. irsp->unsli3.sli3Words[7]);
  2219. lpfc_in_buf_free(phba, dmzbuf);
  2220. }
  2221. return 1;
  2222. }
  2223. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2224. if (irsp->ulpBdeCount != 0) {
  2225. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2226. irsp->un.ulpWord[3]);
  2227. if (!saveq->context2)
  2228. lpfc_printf_log(phba,
  2229. KERN_ERR,
  2230. LOG_SLI,
  2231. "0341 Ring %d Cannot find buffer for "
  2232. "an unsolicited iocb. tag 0x%x\n",
  2233. pring->ringno,
  2234. irsp->un.ulpWord[3]);
  2235. }
  2236. if (irsp->ulpBdeCount == 2) {
  2237. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2238. irsp->unsli3.sli3Words[7]);
  2239. if (!saveq->context3)
  2240. lpfc_printf_log(phba,
  2241. KERN_ERR,
  2242. LOG_SLI,
  2243. "0342 Ring %d Cannot find buffer for an"
  2244. " unsolicited iocb. tag 0x%x\n",
  2245. pring->ringno,
  2246. irsp->unsli3.sli3Words[7]);
  2247. }
  2248. list_for_each_entry(iocbq, &saveq->list, list) {
  2249. irsp = &(iocbq->iocb);
  2250. if (irsp->ulpBdeCount != 0) {
  2251. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2252. irsp->un.ulpWord[3]);
  2253. if (!iocbq->context2)
  2254. lpfc_printf_log(phba,
  2255. KERN_ERR,
  2256. LOG_SLI,
  2257. "0343 Ring %d Cannot find "
  2258. "buffer for an unsolicited iocb"
  2259. ". tag 0x%x\n", pring->ringno,
  2260. irsp->un.ulpWord[3]);
  2261. }
  2262. if (irsp->ulpBdeCount == 2) {
  2263. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2264. irsp->unsli3.sli3Words[7]);
  2265. if (!iocbq->context3)
  2266. lpfc_printf_log(phba,
  2267. KERN_ERR,
  2268. LOG_SLI,
  2269. "0344 Ring %d Cannot find "
  2270. "buffer for an unsolicited "
  2271. "iocb. tag 0x%x\n",
  2272. pring->ringno,
  2273. irsp->unsli3.sli3Words[7]);
  2274. }
  2275. }
  2276. }
  2277. if (irsp->ulpBdeCount != 0 &&
  2278. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2279. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2280. int found = 0;
  2281. /* search continue save q for same XRI */
  2282. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2283. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2284. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2285. list_add_tail(&saveq->list, &iocbq->list);
  2286. found = 1;
  2287. break;
  2288. }
  2289. }
  2290. if (!found)
  2291. list_add_tail(&saveq->clist,
  2292. &pring->iocb_continue_saveq);
  2293. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2294. list_del_init(&iocbq->clist);
  2295. saveq = iocbq;
  2296. irsp = &(saveq->iocb);
  2297. } else
  2298. return 0;
  2299. }
  2300. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2301. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2302. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2303. Rctl = FC_RCTL_ELS_REQ;
  2304. Type = FC_TYPE_ELS;
  2305. } else {
  2306. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2307. Rctl = w5p->hcsw.Rctl;
  2308. Type = w5p->hcsw.Type;
  2309. /* Firmware Workaround */
  2310. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2311. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2312. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2313. Rctl = FC_RCTL_ELS_REQ;
  2314. Type = FC_TYPE_ELS;
  2315. w5p->hcsw.Rctl = Rctl;
  2316. w5p->hcsw.Type = Type;
  2317. }
  2318. }
  2319. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2320. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2321. "0313 Ring %d handler: unexpected Rctl x%x "
  2322. "Type x%x received\n",
  2323. pring->ringno, Rctl, Type);
  2324. return 1;
  2325. }
  2326. /**
  2327. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2328. * @phba: Pointer to HBA context object.
  2329. * @pring: Pointer to driver SLI ring object.
  2330. * @prspiocb: Pointer to response iocb object.
  2331. *
  2332. * This function looks up the iocb_lookup table to get the command iocb
  2333. * corresponding to the given response iocb using the iotag of the
  2334. * response iocb. This function is called with the hbalock held.
  2335. * This function returns the command iocb object if it finds the command
  2336. * iocb else returns NULL.
  2337. **/
  2338. static struct lpfc_iocbq *
  2339. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2340. struct lpfc_sli_ring *pring,
  2341. struct lpfc_iocbq *prspiocb)
  2342. {
  2343. struct lpfc_iocbq *cmd_iocb = NULL;
  2344. uint16_t iotag;
  2345. iotag = prspiocb->iocb.ulpIoTag;
  2346. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2347. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2348. list_del_init(&cmd_iocb->list);
  2349. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2350. pring->txcmplq_cnt--;
  2351. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2352. }
  2353. return cmd_iocb;
  2354. }
  2355. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2356. "0317 iotag x%x is out off "
  2357. "range: max iotag x%x wd0 x%x\n",
  2358. iotag, phba->sli.last_iotag,
  2359. *(((uint32_t *) &prspiocb->iocb) + 7));
  2360. return NULL;
  2361. }
  2362. /**
  2363. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2364. * @phba: Pointer to HBA context object.
  2365. * @pring: Pointer to driver SLI ring object.
  2366. * @iotag: IOCB tag.
  2367. *
  2368. * This function looks up the iocb_lookup table to get the command iocb
  2369. * corresponding to the given iotag. This function is called with the
  2370. * hbalock held.
  2371. * This function returns the command iocb object if it finds the command
  2372. * iocb else returns NULL.
  2373. **/
  2374. static struct lpfc_iocbq *
  2375. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2376. struct lpfc_sli_ring *pring, uint16_t iotag)
  2377. {
  2378. struct lpfc_iocbq *cmd_iocb;
  2379. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2380. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2381. if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
  2382. /* remove from txcmpl queue list */
  2383. list_del_init(&cmd_iocb->list);
  2384. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
  2385. pring->txcmplq_cnt--;
  2386. return cmd_iocb;
  2387. }
  2388. }
  2389. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2390. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2391. iotag, phba->sli.last_iotag);
  2392. return NULL;
  2393. }
  2394. /**
  2395. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2396. * @phba: Pointer to HBA context object.
  2397. * @pring: Pointer to driver SLI ring object.
  2398. * @saveq: Pointer to the response iocb to be processed.
  2399. *
  2400. * This function is called by the ring event handler for non-fcp
  2401. * rings when there is a new response iocb in the response ring.
  2402. * The caller is not required to hold any locks. This function
  2403. * gets the command iocb associated with the response iocb and
  2404. * calls the completion handler for the command iocb. If there
  2405. * is no completion handler, the function will free the resources
  2406. * associated with command iocb. If the response iocb is for
  2407. * an already aborted command iocb, the status of the completion
  2408. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2409. * This function always returns 1.
  2410. **/
  2411. static int
  2412. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2413. struct lpfc_iocbq *saveq)
  2414. {
  2415. struct lpfc_iocbq *cmdiocbp;
  2416. int rc = 1;
  2417. unsigned long iflag;
  2418. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2419. spin_lock_irqsave(&phba->hbalock, iflag);
  2420. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2421. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2422. if (cmdiocbp) {
  2423. if (cmdiocbp->iocb_cmpl) {
  2424. /*
  2425. * If an ELS command failed send an event to mgmt
  2426. * application.
  2427. */
  2428. if (saveq->iocb.ulpStatus &&
  2429. (pring->ringno == LPFC_ELS_RING) &&
  2430. (cmdiocbp->iocb.ulpCommand ==
  2431. CMD_ELS_REQUEST64_CR))
  2432. lpfc_send_els_failure_event(phba,
  2433. cmdiocbp, saveq);
  2434. /*
  2435. * Post all ELS completions to the worker thread.
  2436. * All other are passed to the completion callback.
  2437. */
  2438. if (pring->ringno == LPFC_ELS_RING) {
  2439. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2440. (cmdiocbp->iocb_flag &
  2441. LPFC_DRIVER_ABORTED)) {
  2442. spin_lock_irqsave(&phba->hbalock,
  2443. iflag);
  2444. cmdiocbp->iocb_flag &=
  2445. ~LPFC_DRIVER_ABORTED;
  2446. spin_unlock_irqrestore(&phba->hbalock,
  2447. iflag);
  2448. saveq->iocb.ulpStatus =
  2449. IOSTAT_LOCAL_REJECT;
  2450. saveq->iocb.un.ulpWord[4] =
  2451. IOERR_SLI_ABORTED;
  2452. /* Firmware could still be in progress
  2453. * of DMAing payload, so don't free data
  2454. * buffer till after a hbeat.
  2455. */
  2456. spin_lock_irqsave(&phba->hbalock,
  2457. iflag);
  2458. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2459. spin_unlock_irqrestore(&phba->hbalock,
  2460. iflag);
  2461. }
  2462. if (phba->sli_rev == LPFC_SLI_REV4) {
  2463. if (saveq->iocb_flag &
  2464. LPFC_EXCHANGE_BUSY) {
  2465. /* Set cmdiocb flag for the
  2466. * exchange busy so sgl (xri)
  2467. * will not be released until
  2468. * the abort xri is received
  2469. * from hba.
  2470. */
  2471. spin_lock_irqsave(
  2472. &phba->hbalock, iflag);
  2473. cmdiocbp->iocb_flag |=
  2474. LPFC_EXCHANGE_BUSY;
  2475. spin_unlock_irqrestore(
  2476. &phba->hbalock, iflag);
  2477. }
  2478. if (cmdiocbp->iocb_flag &
  2479. LPFC_DRIVER_ABORTED) {
  2480. /*
  2481. * Clear LPFC_DRIVER_ABORTED
  2482. * bit in case it was driver
  2483. * initiated abort.
  2484. */
  2485. spin_lock_irqsave(
  2486. &phba->hbalock, iflag);
  2487. cmdiocbp->iocb_flag &=
  2488. ~LPFC_DRIVER_ABORTED;
  2489. spin_unlock_irqrestore(
  2490. &phba->hbalock, iflag);
  2491. cmdiocbp->iocb.ulpStatus =
  2492. IOSTAT_LOCAL_REJECT;
  2493. cmdiocbp->iocb.un.ulpWord[4] =
  2494. IOERR_ABORT_REQUESTED;
  2495. /*
  2496. * For SLI4, irsiocb contains
  2497. * NO_XRI in sli_xritag, it
  2498. * shall not affect releasing
  2499. * sgl (xri) process.
  2500. */
  2501. saveq->iocb.ulpStatus =
  2502. IOSTAT_LOCAL_REJECT;
  2503. saveq->iocb.un.ulpWord[4] =
  2504. IOERR_SLI_ABORTED;
  2505. spin_lock_irqsave(
  2506. &phba->hbalock, iflag);
  2507. saveq->iocb_flag |=
  2508. LPFC_DELAY_MEM_FREE;
  2509. spin_unlock_irqrestore(
  2510. &phba->hbalock, iflag);
  2511. }
  2512. }
  2513. }
  2514. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2515. } else
  2516. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2517. } else {
  2518. /*
  2519. * Unknown initiating command based on the response iotag.
  2520. * This could be the case on the ELS ring because of
  2521. * lpfc_els_abort().
  2522. */
  2523. if (pring->ringno != LPFC_ELS_RING) {
  2524. /*
  2525. * Ring <ringno> handler: unexpected completion IoTag
  2526. * <IoTag>
  2527. */
  2528. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2529. "0322 Ring %d handler: "
  2530. "unexpected completion IoTag x%x "
  2531. "Data: x%x x%x x%x x%x\n",
  2532. pring->ringno,
  2533. saveq->iocb.ulpIoTag,
  2534. saveq->iocb.ulpStatus,
  2535. saveq->iocb.un.ulpWord[4],
  2536. saveq->iocb.ulpCommand,
  2537. saveq->iocb.ulpContext);
  2538. }
  2539. }
  2540. return rc;
  2541. }
  2542. /**
  2543. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2544. * @phba: Pointer to HBA context object.
  2545. * @pring: Pointer to driver SLI ring object.
  2546. *
  2547. * This function is called from the iocb ring event handlers when
  2548. * put pointer is ahead of the get pointer for a ring. This function signal
  2549. * an error attention condition to the worker thread and the worker
  2550. * thread will transition the HBA to offline state.
  2551. **/
  2552. static void
  2553. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2554. {
  2555. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2556. /*
  2557. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2558. * rsp ring <portRspMax>
  2559. */
  2560. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2561. "0312 Ring %d handler: portRspPut %d "
  2562. "is bigger than rsp ring %d\n",
  2563. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2564. pring->numRiocb);
  2565. phba->link_state = LPFC_HBA_ERROR;
  2566. /*
  2567. * All error attention handlers are posted to
  2568. * worker thread
  2569. */
  2570. phba->work_ha |= HA_ERATT;
  2571. phba->work_hs = HS_FFER3;
  2572. lpfc_worker_wake_up(phba);
  2573. return;
  2574. }
  2575. /**
  2576. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2577. * @ptr: Pointer to address of HBA context object.
  2578. *
  2579. * This function is invoked by the Error Attention polling timer when the
  2580. * timer times out. It will check the SLI Error Attention register for
  2581. * possible attention events. If so, it will post an Error Attention event
  2582. * and wake up worker thread to process it. Otherwise, it will set up the
  2583. * Error Attention polling timer for the next poll.
  2584. **/
  2585. void lpfc_poll_eratt(unsigned long ptr)
  2586. {
  2587. struct lpfc_hba *phba;
  2588. uint32_t eratt = 0;
  2589. phba = (struct lpfc_hba *)ptr;
  2590. /* Check chip HA register for error event */
  2591. eratt = lpfc_sli_check_eratt(phba);
  2592. if (eratt)
  2593. /* Tell the worker thread there is work to do */
  2594. lpfc_worker_wake_up(phba);
  2595. else
  2596. /* Restart the timer for next eratt poll */
  2597. mod_timer(&phba->eratt_poll, jiffies +
  2598. HZ * LPFC_ERATT_POLL_INTERVAL);
  2599. return;
  2600. }
  2601. /**
  2602. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2603. * @phba: Pointer to HBA context object.
  2604. * @pring: Pointer to driver SLI ring object.
  2605. * @mask: Host attention register mask for this ring.
  2606. *
  2607. * This function is called from the interrupt context when there is a ring
  2608. * event for the fcp ring. The caller does not hold any lock.
  2609. * The function processes each response iocb in the response ring until it
  2610. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2611. * LE bit set. The function will call the completion handler of the command iocb
  2612. * if the response iocb indicates a completion for a command iocb or it is
  2613. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2614. * function if this is an unsolicited iocb.
  2615. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2616. * to check it explicitly.
  2617. */
  2618. int
  2619. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2620. struct lpfc_sli_ring *pring, uint32_t mask)
  2621. {
  2622. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2623. IOCB_t *irsp = NULL;
  2624. IOCB_t *entry = NULL;
  2625. struct lpfc_iocbq *cmdiocbq = NULL;
  2626. struct lpfc_iocbq rspiocbq;
  2627. uint32_t status;
  2628. uint32_t portRspPut, portRspMax;
  2629. int rc = 1;
  2630. lpfc_iocb_type type;
  2631. unsigned long iflag;
  2632. uint32_t rsp_cmpl = 0;
  2633. spin_lock_irqsave(&phba->hbalock, iflag);
  2634. pring->stats.iocb_event++;
  2635. /*
  2636. * The next available response entry should never exceed the maximum
  2637. * entries. If it does, treat it as an adapter hardware error.
  2638. */
  2639. portRspMax = pring->numRiocb;
  2640. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2641. if (unlikely(portRspPut >= portRspMax)) {
  2642. lpfc_sli_rsp_pointers_error(phba, pring);
  2643. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2644. return 1;
  2645. }
  2646. if (phba->fcp_ring_in_use) {
  2647. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2648. return 1;
  2649. } else
  2650. phba->fcp_ring_in_use = 1;
  2651. rmb();
  2652. while (pring->rspidx != portRspPut) {
  2653. /*
  2654. * Fetch an entry off the ring and copy it into a local data
  2655. * structure. The copy involves a byte-swap since the
  2656. * network byte order and pci byte orders are different.
  2657. */
  2658. entry = lpfc_resp_iocb(phba, pring);
  2659. phba->last_completion_time = jiffies;
  2660. if (++pring->rspidx >= portRspMax)
  2661. pring->rspidx = 0;
  2662. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2663. (uint32_t *) &rspiocbq.iocb,
  2664. phba->iocb_rsp_size);
  2665. INIT_LIST_HEAD(&(rspiocbq.list));
  2666. irsp = &rspiocbq.iocb;
  2667. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2668. pring->stats.iocb_rsp++;
  2669. rsp_cmpl++;
  2670. if (unlikely(irsp->ulpStatus)) {
  2671. /*
  2672. * If resource errors reported from HBA, reduce
  2673. * queuedepths of the SCSI device.
  2674. */
  2675. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2676. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2677. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2678. phba->lpfc_rampdown_queue_depth(phba);
  2679. spin_lock_irqsave(&phba->hbalock, iflag);
  2680. }
  2681. /* Rsp ring <ringno> error: IOCB */
  2682. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2683. "0336 Rsp Ring %d error: IOCB Data: "
  2684. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2685. pring->ringno,
  2686. irsp->un.ulpWord[0],
  2687. irsp->un.ulpWord[1],
  2688. irsp->un.ulpWord[2],
  2689. irsp->un.ulpWord[3],
  2690. irsp->un.ulpWord[4],
  2691. irsp->un.ulpWord[5],
  2692. *(uint32_t *)&irsp->un1,
  2693. *((uint32_t *)&irsp->un1 + 1));
  2694. }
  2695. switch (type) {
  2696. case LPFC_ABORT_IOCB:
  2697. case LPFC_SOL_IOCB:
  2698. /*
  2699. * Idle exchange closed via ABTS from port. No iocb
  2700. * resources need to be recovered.
  2701. */
  2702. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2703. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2704. "0333 IOCB cmd 0x%x"
  2705. " processed. Skipping"
  2706. " completion\n",
  2707. irsp->ulpCommand);
  2708. break;
  2709. }
  2710. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2711. &rspiocbq);
  2712. if (unlikely(!cmdiocbq))
  2713. break;
  2714. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2715. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2716. if (cmdiocbq->iocb_cmpl) {
  2717. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2718. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2719. &rspiocbq);
  2720. spin_lock_irqsave(&phba->hbalock, iflag);
  2721. }
  2722. break;
  2723. case LPFC_UNSOL_IOCB:
  2724. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2725. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2726. spin_lock_irqsave(&phba->hbalock, iflag);
  2727. break;
  2728. default:
  2729. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2730. char adaptermsg[LPFC_MAX_ADPTMSG];
  2731. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2732. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2733. MAX_MSG_DATA);
  2734. dev_warn(&((phba->pcidev)->dev),
  2735. "lpfc%d: %s\n",
  2736. phba->brd_no, adaptermsg);
  2737. } else {
  2738. /* Unknown IOCB command */
  2739. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2740. "0334 Unknown IOCB command "
  2741. "Data: x%x, x%x x%x x%x x%x\n",
  2742. type, irsp->ulpCommand,
  2743. irsp->ulpStatus,
  2744. irsp->ulpIoTag,
  2745. irsp->ulpContext);
  2746. }
  2747. break;
  2748. }
  2749. /*
  2750. * The response IOCB has been processed. Update the ring
  2751. * pointer in SLIM. If the port response put pointer has not
  2752. * been updated, sync the pgp->rspPutInx and fetch the new port
  2753. * response put pointer.
  2754. */
  2755. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2756. if (pring->rspidx == portRspPut)
  2757. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2758. }
  2759. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2760. pring->stats.iocb_rsp_full++;
  2761. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2762. writel(status, phba->CAregaddr);
  2763. readl(phba->CAregaddr);
  2764. }
  2765. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2766. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2767. pring->stats.iocb_cmd_empty++;
  2768. /* Force update of the local copy of cmdGetInx */
  2769. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2770. lpfc_sli_resume_iocb(phba, pring);
  2771. if ((pring->lpfc_sli_cmd_available))
  2772. (pring->lpfc_sli_cmd_available) (phba, pring);
  2773. }
  2774. phba->fcp_ring_in_use = 0;
  2775. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2776. return rc;
  2777. }
  2778. /**
  2779. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2780. * @phba: Pointer to HBA context object.
  2781. * @pring: Pointer to driver SLI ring object.
  2782. * @rspiocbp: Pointer to driver response IOCB object.
  2783. *
  2784. * This function is called from the worker thread when there is a slow-path
  2785. * response IOCB to process. This function chains all the response iocbs until
  2786. * seeing the iocb with the LE bit set. The function will call
  2787. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2788. * completion of a command iocb. The function will call the
  2789. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2790. * The function frees the resources or calls the completion handler if this
  2791. * iocb is an abort completion. The function returns NULL when the response
  2792. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2793. * this function shall chain the iocb on to the iocb_continueq and return the
  2794. * response iocb passed in.
  2795. **/
  2796. static struct lpfc_iocbq *
  2797. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2798. struct lpfc_iocbq *rspiocbp)
  2799. {
  2800. struct lpfc_iocbq *saveq;
  2801. struct lpfc_iocbq *cmdiocbp;
  2802. struct lpfc_iocbq *next_iocb;
  2803. IOCB_t *irsp = NULL;
  2804. uint32_t free_saveq;
  2805. uint8_t iocb_cmd_type;
  2806. lpfc_iocb_type type;
  2807. unsigned long iflag;
  2808. int rc;
  2809. spin_lock_irqsave(&phba->hbalock, iflag);
  2810. /* First add the response iocb to the countinueq list */
  2811. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2812. pring->iocb_continueq_cnt++;
  2813. /* Now, determine whether the list is completed for processing */
  2814. irsp = &rspiocbp->iocb;
  2815. if (irsp->ulpLe) {
  2816. /*
  2817. * By default, the driver expects to free all resources
  2818. * associated with this iocb completion.
  2819. */
  2820. free_saveq = 1;
  2821. saveq = list_get_first(&pring->iocb_continueq,
  2822. struct lpfc_iocbq, list);
  2823. irsp = &(saveq->iocb);
  2824. list_del_init(&pring->iocb_continueq);
  2825. pring->iocb_continueq_cnt = 0;
  2826. pring->stats.iocb_rsp++;
  2827. /*
  2828. * If resource errors reported from HBA, reduce
  2829. * queuedepths of the SCSI device.
  2830. */
  2831. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2832. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2833. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2834. phba->lpfc_rampdown_queue_depth(phba);
  2835. spin_lock_irqsave(&phba->hbalock, iflag);
  2836. }
  2837. if (irsp->ulpStatus) {
  2838. /* Rsp ring <ringno> error: IOCB */
  2839. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2840. "0328 Rsp Ring %d error: "
  2841. "IOCB Data: "
  2842. "x%x x%x x%x x%x "
  2843. "x%x x%x x%x x%x "
  2844. "x%x x%x x%x x%x "
  2845. "x%x x%x x%x x%x\n",
  2846. pring->ringno,
  2847. irsp->un.ulpWord[0],
  2848. irsp->un.ulpWord[1],
  2849. irsp->un.ulpWord[2],
  2850. irsp->un.ulpWord[3],
  2851. irsp->un.ulpWord[4],
  2852. irsp->un.ulpWord[5],
  2853. *(((uint32_t *) irsp) + 6),
  2854. *(((uint32_t *) irsp) + 7),
  2855. *(((uint32_t *) irsp) + 8),
  2856. *(((uint32_t *) irsp) + 9),
  2857. *(((uint32_t *) irsp) + 10),
  2858. *(((uint32_t *) irsp) + 11),
  2859. *(((uint32_t *) irsp) + 12),
  2860. *(((uint32_t *) irsp) + 13),
  2861. *(((uint32_t *) irsp) + 14),
  2862. *(((uint32_t *) irsp) + 15));
  2863. }
  2864. /*
  2865. * Fetch the IOCB command type and call the correct completion
  2866. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2867. * get freed back to the lpfc_iocb_list by the discovery
  2868. * kernel thread.
  2869. */
  2870. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2871. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2872. switch (type) {
  2873. case LPFC_SOL_IOCB:
  2874. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2875. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2876. spin_lock_irqsave(&phba->hbalock, iflag);
  2877. break;
  2878. case LPFC_UNSOL_IOCB:
  2879. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2880. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2881. spin_lock_irqsave(&phba->hbalock, iflag);
  2882. if (!rc)
  2883. free_saveq = 0;
  2884. break;
  2885. case LPFC_ABORT_IOCB:
  2886. cmdiocbp = NULL;
  2887. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2888. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2889. saveq);
  2890. if (cmdiocbp) {
  2891. /* Call the specified completion routine */
  2892. if (cmdiocbp->iocb_cmpl) {
  2893. spin_unlock_irqrestore(&phba->hbalock,
  2894. iflag);
  2895. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2896. saveq);
  2897. spin_lock_irqsave(&phba->hbalock,
  2898. iflag);
  2899. } else
  2900. __lpfc_sli_release_iocbq(phba,
  2901. cmdiocbp);
  2902. }
  2903. break;
  2904. case LPFC_UNKNOWN_IOCB:
  2905. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2906. char adaptermsg[LPFC_MAX_ADPTMSG];
  2907. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2908. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2909. MAX_MSG_DATA);
  2910. dev_warn(&((phba->pcidev)->dev),
  2911. "lpfc%d: %s\n",
  2912. phba->brd_no, adaptermsg);
  2913. } else {
  2914. /* Unknown IOCB command */
  2915. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2916. "0335 Unknown IOCB "
  2917. "command Data: x%x "
  2918. "x%x x%x x%x\n",
  2919. irsp->ulpCommand,
  2920. irsp->ulpStatus,
  2921. irsp->ulpIoTag,
  2922. irsp->ulpContext);
  2923. }
  2924. break;
  2925. }
  2926. if (free_saveq) {
  2927. list_for_each_entry_safe(rspiocbp, next_iocb,
  2928. &saveq->list, list) {
  2929. list_del(&rspiocbp->list);
  2930. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2931. }
  2932. __lpfc_sli_release_iocbq(phba, saveq);
  2933. }
  2934. rspiocbp = NULL;
  2935. }
  2936. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2937. return rspiocbp;
  2938. }
  2939. /**
  2940. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2941. * @phba: Pointer to HBA context object.
  2942. * @pring: Pointer to driver SLI ring object.
  2943. * @mask: Host attention register mask for this ring.
  2944. *
  2945. * This routine wraps the actual slow_ring event process routine from the
  2946. * API jump table function pointer from the lpfc_hba struct.
  2947. **/
  2948. void
  2949. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2950. struct lpfc_sli_ring *pring, uint32_t mask)
  2951. {
  2952. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2953. }
  2954. /**
  2955. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2956. * @phba: Pointer to HBA context object.
  2957. * @pring: Pointer to driver SLI ring object.
  2958. * @mask: Host attention register mask for this ring.
  2959. *
  2960. * This function is called from the worker thread when there is a ring event
  2961. * for non-fcp rings. The caller does not hold any lock. The function will
  2962. * remove each response iocb in the response ring and calls the handle
  2963. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2964. **/
  2965. static void
  2966. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2967. struct lpfc_sli_ring *pring, uint32_t mask)
  2968. {
  2969. struct lpfc_pgp *pgp;
  2970. IOCB_t *entry;
  2971. IOCB_t *irsp = NULL;
  2972. struct lpfc_iocbq *rspiocbp = NULL;
  2973. uint32_t portRspPut, portRspMax;
  2974. unsigned long iflag;
  2975. uint32_t status;
  2976. pgp = &phba->port_gp[pring->ringno];
  2977. spin_lock_irqsave(&phba->hbalock, iflag);
  2978. pring->stats.iocb_event++;
  2979. /*
  2980. * The next available response entry should never exceed the maximum
  2981. * entries. If it does, treat it as an adapter hardware error.
  2982. */
  2983. portRspMax = pring->numRiocb;
  2984. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2985. if (portRspPut >= portRspMax) {
  2986. /*
  2987. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2988. * rsp ring <portRspMax>
  2989. */
  2990. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2991. "0303 Ring %d handler: portRspPut %d "
  2992. "is bigger than rsp ring %d\n",
  2993. pring->ringno, portRspPut, portRspMax);
  2994. phba->link_state = LPFC_HBA_ERROR;
  2995. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2996. phba->work_hs = HS_FFER3;
  2997. lpfc_handle_eratt(phba);
  2998. return;
  2999. }
  3000. rmb();
  3001. while (pring->rspidx != portRspPut) {
  3002. /*
  3003. * Build a completion list and call the appropriate handler.
  3004. * The process is to get the next available response iocb, get
  3005. * a free iocb from the list, copy the response data into the
  3006. * free iocb, insert to the continuation list, and update the
  3007. * next response index to slim. This process makes response
  3008. * iocb's in the ring available to DMA as fast as possible but
  3009. * pays a penalty for a copy operation. Since the iocb is
  3010. * only 32 bytes, this penalty is considered small relative to
  3011. * the PCI reads for register values and a slim write. When
  3012. * the ulpLe field is set, the entire Command has been
  3013. * received.
  3014. */
  3015. entry = lpfc_resp_iocb(phba, pring);
  3016. phba->last_completion_time = jiffies;
  3017. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3018. if (rspiocbp == NULL) {
  3019. printk(KERN_ERR "%s: out of buffers! Failing "
  3020. "completion.\n", __func__);
  3021. break;
  3022. }
  3023. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3024. phba->iocb_rsp_size);
  3025. irsp = &rspiocbp->iocb;
  3026. if (++pring->rspidx >= portRspMax)
  3027. pring->rspidx = 0;
  3028. if (pring->ringno == LPFC_ELS_RING) {
  3029. lpfc_debugfs_slow_ring_trc(phba,
  3030. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3031. *(((uint32_t *) irsp) + 4),
  3032. *(((uint32_t *) irsp) + 6),
  3033. *(((uint32_t *) irsp) + 7));
  3034. }
  3035. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3036. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3037. /* Handle the response IOCB */
  3038. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3039. spin_lock_irqsave(&phba->hbalock, iflag);
  3040. /*
  3041. * If the port response put pointer has not been updated, sync
  3042. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3043. * response put pointer.
  3044. */
  3045. if (pring->rspidx == portRspPut) {
  3046. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3047. }
  3048. } /* while (pring->rspidx != portRspPut) */
  3049. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3050. /* At least one response entry has been freed */
  3051. pring->stats.iocb_rsp_full++;
  3052. /* SET RxRE_RSP in Chip Att register */
  3053. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3054. writel(status, phba->CAregaddr);
  3055. readl(phba->CAregaddr); /* flush */
  3056. }
  3057. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3058. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3059. pring->stats.iocb_cmd_empty++;
  3060. /* Force update of the local copy of cmdGetInx */
  3061. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3062. lpfc_sli_resume_iocb(phba, pring);
  3063. if ((pring->lpfc_sli_cmd_available))
  3064. (pring->lpfc_sli_cmd_available) (phba, pring);
  3065. }
  3066. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3067. return;
  3068. }
  3069. /**
  3070. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3071. * @phba: Pointer to HBA context object.
  3072. * @pring: Pointer to driver SLI ring object.
  3073. * @mask: Host attention register mask for this ring.
  3074. *
  3075. * This function is called from the worker thread when there is a pending
  3076. * ELS response iocb on the driver internal slow-path response iocb worker
  3077. * queue. The caller does not hold any lock. The function will remove each
  3078. * response iocb from the response worker queue and calls the handle
  3079. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3080. **/
  3081. static void
  3082. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3083. struct lpfc_sli_ring *pring, uint32_t mask)
  3084. {
  3085. struct lpfc_iocbq *irspiocbq;
  3086. struct hbq_dmabuf *dmabuf;
  3087. struct lpfc_cq_event *cq_event;
  3088. unsigned long iflag;
  3089. spin_lock_irqsave(&phba->hbalock, iflag);
  3090. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3091. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3092. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3093. /* Get the response iocb from the head of work queue */
  3094. spin_lock_irqsave(&phba->hbalock, iflag);
  3095. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3096. cq_event, struct lpfc_cq_event, list);
  3097. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3098. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3099. case CQE_CODE_COMPL_WQE:
  3100. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3101. cq_event);
  3102. /* Translate ELS WCQE to response IOCBQ */
  3103. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3104. irspiocbq);
  3105. if (irspiocbq)
  3106. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3107. irspiocbq);
  3108. break;
  3109. case CQE_CODE_RECEIVE:
  3110. case CQE_CODE_RECEIVE_V1:
  3111. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3112. cq_event);
  3113. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3114. break;
  3115. default:
  3116. break;
  3117. }
  3118. }
  3119. }
  3120. /**
  3121. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3122. * @phba: Pointer to HBA context object.
  3123. * @pring: Pointer to driver SLI ring object.
  3124. *
  3125. * This function aborts all iocbs in the given ring and frees all the iocb
  3126. * objects in txq. This function issues an abort iocb for all the iocb commands
  3127. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3128. * the return of this function. The caller is not required to hold any locks.
  3129. **/
  3130. void
  3131. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3132. {
  3133. LIST_HEAD(completions);
  3134. struct lpfc_iocbq *iocb, *next_iocb;
  3135. if (pring->ringno == LPFC_ELS_RING) {
  3136. lpfc_fabric_abort_hba(phba);
  3137. }
  3138. /* Error everything on txq and txcmplq
  3139. * First do the txq.
  3140. */
  3141. spin_lock_irq(&phba->hbalock);
  3142. list_splice_init(&pring->txq, &completions);
  3143. pring->txq_cnt = 0;
  3144. /* Next issue ABTS for everything on the txcmplq */
  3145. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3146. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3147. spin_unlock_irq(&phba->hbalock);
  3148. /* Cancel all the IOCBs from the completions list */
  3149. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3150. IOERR_SLI_ABORTED);
  3151. }
  3152. /**
  3153. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3154. * @phba: Pointer to HBA context object.
  3155. *
  3156. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3157. * objects in txq and txcmplq. This function will not issue abort iocbs
  3158. * for all the iocb commands in txcmplq, they will just be returned with
  3159. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3160. * slot has been permanently disabled.
  3161. **/
  3162. void
  3163. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3164. {
  3165. LIST_HEAD(txq);
  3166. LIST_HEAD(txcmplq);
  3167. struct lpfc_sli *psli = &phba->sli;
  3168. struct lpfc_sli_ring *pring;
  3169. /* Currently, only one fcp ring */
  3170. pring = &psli->ring[psli->fcp_ring];
  3171. spin_lock_irq(&phba->hbalock);
  3172. /* Retrieve everything on txq */
  3173. list_splice_init(&pring->txq, &txq);
  3174. pring->txq_cnt = 0;
  3175. /* Retrieve everything on the txcmplq */
  3176. list_splice_init(&pring->txcmplq, &txcmplq);
  3177. pring->txcmplq_cnt = 0;
  3178. /* Indicate the I/O queues are flushed */
  3179. phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
  3180. spin_unlock_irq(&phba->hbalock);
  3181. /* Flush the txq */
  3182. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3183. IOERR_SLI_DOWN);
  3184. /* Flush the txcmpq */
  3185. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3186. IOERR_SLI_DOWN);
  3187. }
  3188. /**
  3189. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3190. * @phba: Pointer to HBA context object.
  3191. * @mask: Bit mask to be checked.
  3192. *
  3193. * This function reads the host status register and compares
  3194. * with the provided bit mask to check if HBA completed
  3195. * the restart. This function will wait in a loop for the
  3196. * HBA to complete restart. If the HBA does not restart within
  3197. * 15 iterations, the function will reset the HBA again. The
  3198. * function returns 1 when HBA fail to restart otherwise returns
  3199. * zero.
  3200. **/
  3201. static int
  3202. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3203. {
  3204. uint32_t status;
  3205. int i = 0;
  3206. int retval = 0;
  3207. /* Read the HBA Host Status Register */
  3208. if (lpfc_readl(phba->HSregaddr, &status))
  3209. return 1;
  3210. /*
  3211. * Check status register every 100ms for 5 retries, then every
  3212. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3213. * every 2.5 sec for 4.
  3214. * Break our of the loop if errors occurred during init.
  3215. */
  3216. while (((status & mask) != mask) &&
  3217. !(status & HS_FFERM) &&
  3218. i++ < 20) {
  3219. if (i <= 5)
  3220. msleep(10);
  3221. else if (i <= 10)
  3222. msleep(500);
  3223. else
  3224. msleep(2500);
  3225. if (i == 15) {
  3226. /* Do post */
  3227. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3228. lpfc_sli_brdrestart(phba);
  3229. }
  3230. /* Read the HBA Host Status Register */
  3231. if (lpfc_readl(phba->HSregaddr, &status)) {
  3232. retval = 1;
  3233. break;
  3234. }
  3235. }
  3236. /* Check to see if any errors occurred during init */
  3237. if ((status & HS_FFERM) || (i >= 20)) {
  3238. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3239. "2751 Adapter failed to restart, "
  3240. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3241. status,
  3242. readl(phba->MBslimaddr + 0xa8),
  3243. readl(phba->MBslimaddr + 0xac));
  3244. phba->link_state = LPFC_HBA_ERROR;
  3245. retval = 1;
  3246. }
  3247. return retval;
  3248. }
  3249. /**
  3250. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3251. * @phba: Pointer to HBA context object.
  3252. * @mask: Bit mask to be checked.
  3253. *
  3254. * This function checks the host status register to check if HBA is
  3255. * ready. This function will wait in a loop for the HBA to be ready
  3256. * If the HBA is not ready , the function will will reset the HBA PCI
  3257. * function again. The function returns 1 when HBA fail to be ready
  3258. * otherwise returns zero.
  3259. **/
  3260. static int
  3261. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3262. {
  3263. uint32_t status;
  3264. int retval = 0;
  3265. /* Read the HBA Host Status Register */
  3266. status = lpfc_sli4_post_status_check(phba);
  3267. if (status) {
  3268. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3269. lpfc_sli_brdrestart(phba);
  3270. status = lpfc_sli4_post_status_check(phba);
  3271. }
  3272. /* Check to see if any errors occurred during init */
  3273. if (status) {
  3274. phba->link_state = LPFC_HBA_ERROR;
  3275. retval = 1;
  3276. } else
  3277. phba->sli4_hba.intr_enable = 0;
  3278. return retval;
  3279. }
  3280. /**
  3281. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3282. * @phba: Pointer to HBA context object.
  3283. * @mask: Bit mask to be checked.
  3284. *
  3285. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3286. * from the API jump table function pointer from the lpfc_hba struct.
  3287. **/
  3288. int
  3289. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3290. {
  3291. return phba->lpfc_sli_brdready(phba, mask);
  3292. }
  3293. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3294. /**
  3295. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3296. * @phba: Pointer to HBA context object.
  3297. *
  3298. * This function is called before resetting an HBA. This function is called
  3299. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3300. **/
  3301. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3302. {
  3303. uint32_t __iomem *resp_buf;
  3304. uint32_t __iomem *mbox_buf;
  3305. volatile uint32_t mbox;
  3306. uint32_t hc_copy, ha_copy, resp_data;
  3307. int i;
  3308. uint8_t hdrtype;
  3309. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3310. if (hdrtype != 0x80 ||
  3311. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3312. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3313. return;
  3314. /*
  3315. * Tell the other part of the chip to suspend temporarily all
  3316. * its DMA activity.
  3317. */
  3318. resp_buf = phba->MBslimaddr;
  3319. /* Disable the error attention */
  3320. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3321. return;
  3322. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3323. readl(phba->HCregaddr); /* flush */
  3324. phba->link_flag |= LS_IGNORE_ERATT;
  3325. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3326. return;
  3327. if (ha_copy & HA_ERATT) {
  3328. /* Clear Chip error bit */
  3329. writel(HA_ERATT, phba->HAregaddr);
  3330. phba->pport->stopped = 1;
  3331. }
  3332. mbox = 0;
  3333. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3334. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3335. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3336. mbox_buf = phba->MBslimaddr;
  3337. writel(mbox, mbox_buf);
  3338. for (i = 0; i < 50; i++) {
  3339. if (lpfc_readl((resp_buf + 1), &resp_data))
  3340. return;
  3341. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3342. mdelay(1);
  3343. else
  3344. break;
  3345. }
  3346. resp_data = 0;
  3347. if (lpfc_readl((resp_buf + 1), &resp_data))
  3348. return;
  3349. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3350. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3351. phba->pport->stopped)
  3352. goto restore_hc;
  3353. else
  3354. goto clear_errat;
  3355. }
  3356. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3357. resp_data = 0;
  3358. for (i = 0; i < 500; i++) {
  3359. if (lpfc_readl(resp_buf, &resp_data))
  3360. return;
  3361. if (resp_data != mbox)
  3362. mdelay(1);
  3363. else
  3364. break;
  3365. }
  3366. clear_errat:
  3367. while (++i < 500) {
  3368. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3369. return;
  3370. if (!(ha_copy & HA_ERATT))
  3371. mdelay(1);
  3372. else
  3373. break;
  3374. }
  3375. if (readl(phba->HAregaddr) & HA_ERATT) {
  3376. writel(HA_ERATT, phba->HAregaddr);
  3377. phba->pport->stopped = 1;
  3378. }
  3379. restore_hc:
  3380. phba->link_flag &= ~LS_IGNORE_ERATT;
  3381. writel(hc_copy, phba->HCregaddr);
  3382. readl(phba->HCregaddr); /* flush */
  3383. }
  3384. /**
  3385. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3386. * @phba: Pointer to HBA context object.
  3387. *
  3388. * This function issues a kill_board mailbox command and waits for
  3389. * the error attention interrupt. This function is called for stopping
  3390. * the firmware processing. The caller is not required to hold any
  3391. * locks. This function calls lpfc_hba_down_post function to free
  3392. * any pending commands after the kill. The function will return 1 when it
  3393. * fails to kill the board else will return 0.
  3394. **/
  3395. int
  3396. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3397. {
  3398. struct lpfc_sli *psli;
  3399. LPFC_MBOXQ_t *pmb;
  3400. uint32_t status;
  3401. uint32_t ha_copy;
  3402. int retval;
  3403. int i = 0;
  3404. psli = &phba->sli;
  3405. /* Kill HBA */
  3406. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3407. "0329 Kill HBA Data: x%x x%x\n",
  3408. phba->pport->port_state, psli->sli_flag);
  3409. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3410. if (!pmb)
  3411. return 1;
  3412. /* Disable the error attention */
  3413. spin_lock_irq(&phba->hbalock);
  3414. if (lpfc_readl(phba->HCregaddr, &status)) {
  3415. spin_unlock_irq(&phba->hbalock);
  3416. mempool_free(pmb, phba->mbox_mem_pool);
  3417. return 1;
  3418. }
  3419. status &= ~HC_ERINT_ENA;
  3420. writel(status, phba->HCregaddr);
  3421. readl(phba->HCregaddr); /* flush */
  3422. phba->link_flag |= LS_IGNORE_ERATT;
  3423. spin_unlock_irq(&phba->hbalock);
  3424. lpfc_kill_board(phba, pmb);
  3425. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3426. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3427. if (retval != MBX_SUCCESS) {
  3428. if (retval != MBX_BUSY)
  3429. mempool_free(pmb, phba->mbox_mem_pool);
  3430. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3431. "2752 KILL_BOARD command failed retval %d\n",
  3432. retval);
  3433. spin_lock_irq(&phba->hbalock);
  3434. phba->link_flag &= ~LS_IGNORE_ERATT;
  3435. spin_unlock_irq(&phba->hbalock);
  3436. return 1;
  3437. }
  3438. spin_lock_irq(&phba->hbalock);
  3439. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3440. spin_unlock_irq(&phba->hbalock);
  3441. mempool_free(pmb, phba->mbox_mem_pool);
  3442. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3443. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3444. * 3 seconds we still set HBA_ERROR state because the status of the
  3445. * board is now undefined.
  3446. */
  3447. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3448. return 1;
  3449. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3450. mdelay(100);
  3451. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3452. return 1;
  3453. }
  3454. del_timer_sync(&psli->mbox_tmo);
  3455. if (ha_copy & HA_ERATT) {
  3456. writel(HA_ERATT, phba->HAregaddr);
  3457. phba->pport->stopped = 1;
  3458. }
  3459. spin_lock_irq(&phba->hbalock);
  3460. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3461. psli->mbox_active = NULL;
  3462. phba->link_flag &= ~LS_IGNORE_ERATT;
  3463. spin_unlock_irq(&phba->hbalock);
  3464. lpfc_hba_down_post(phba);
  3465. phba->link_state = LPFC_HBA_ERROR;
  3466. return ha_copy & HA_ERATT ? 0 : 1;
  3467. }
  3468. /**
  3469. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3470. * @phba: Pointer to HBA context object.
  3471. *
  3472. * This function resets the HBA by writing HC_INITFF to the control
  3473. * register. After the HBA resets, this function resets all the iocb ring
  3474. * indices. This function disables PCI layer parity checking during
  3475. * the reset.
  3476. * This function returns 0 always.
  3477. * The caller is not required to hold any locks.
  3478. **/
  3479. int
  3480. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3481. {
  3482. struct lpfc_sli *psli;
  3483. struct lpfc_sli_ring *pring;
  3484. uint16_t cfg_value;
  3485. int i;
  3486. psli = &phba->sli;
  3487. /* Reset HBA */
  3488. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3489. "0325 Reset HBA Data: x%x x%x\n",
  3490. phba->pport->port_state, psli->sli_flag);
  3491. /* perform board reset */
  3492. phba->fc_eventTag = 0;
  3493. phba->link_events = 0;
  3494. phba->pport->fc_myDID = 0;
  3495. phba->pport->fc_prevDID = 0;
  3496. /* Turn off parity checking and serr during the physical reset */
  3497. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3498. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3499. (cfg_value &
  3500. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3501. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3502. /* Now toggle INITFF bit in the Host Control Register */
  3503. writel(HC_INITFF, phba->HCregaddr);
  3504. mdelay(1);
  3505. readl(phba->HCregaddr); /* flush */
  3506. writel(0, phba->HCregaddr);
  3507. readl(phba->HCregaddr); /* flush */
  3508. /* Restore PCI cmd register */
  3509. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3510. /* Initialize relevant SLI info */
  3511. for (i = 0; i < psli->num_rings; i++) {
  3512. pring = &psli->ring[i];
  3513. pring->flag = 0;
  3514. pring->rspidx = 0;
  3515. pring->next_cmdidx = 0;
  3516. pring->local_getidx = 0;
  3517. pring->cmdidx = 0;
  3518. pring->missbufcnt = 0;
  3519. }
  3520. phba->link_state = LPFC_WARM_START;
  3521. return 0;
  3522. }
  3523. /**
  3524. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3525. * @phba: Pointer to HBA context object.
  3526. *
  3527. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3528. * checking during resets the device. The caller is not required to hold
  3529. * any locks.
  3530. *
  3531. * This function returns 0 always.
  3532. **/
  3533. int
  3534. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3535. {
  3536. struct lpfc_sli *psli = &phba->sli;
  3537. uint16_t cfg_value;
  3538. /* Reset HBA */
  3539. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3540. "0295 Reset HBA Data: x%x x%x\n",
  3541. phba->pport->port_state, psli->sli_flag);
  3542. /* perform board reset */
  3543. phba->fc_eventTag = 0;
  3544. phba->link_events = 0;
  3545. phba->pport->fc_myDID = 0;
  3546. phba->pport->fc_prevDID = 0;
  3547. spin_lock_irq(&phba->hbalock);
  3548. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3549. phba->fcf.fcf_flag = 0;
  3550. spin_unlock_irq(&phba->hbalock);
  3551. /* Now physically reset the device */
  3552. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3553. "0389 Performing PCI function reset!\n");
  3554. /* Turn off parity checking and serr during the physical reset */
  3555. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3556. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3557. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3558. /* Perform FCoE PCI function reset */
  3559. lpfc_sli4_queue_destroy(phba);
  3560. lpfc_pci_function_reset(phba);
  3561. /* Restore PCI cmd register */
  3562. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3563. return 0;
  3564. }
  3565. /**
  3566. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3567. * @phba: Pointer to HBA context object.
  3568. *
  3569. * This function is called in the SLI initialization code path to
  3570. * restart the HBA. The caller is not required to hold any lock.
  3571. * This function writes MBX_RESTART mailbox command to the SLIM and
  3572. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3573. * function to free any pending commands. The function enables
  3574. * POST only during the first initialization. The function returns zero.
  3575. * The function does not guarantee completion of MBX_RESTART mailbox
  3576. * command before the return of this function.
  3577. **/
  3578. static int
  3579. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3580. {
  3581. MAILBOX_t *mb;
  3582. struct lpfc_sli *psli;
  3583. volatile uint32_t word0;
  3584. void __iomem *to_slim;
  3585. uint32_t hba_aer_enabled;
  3586. spin_lock_irq(&phba->hbalock);
  3587. /* Take PCIe device Advanced Error Reporting (AER) state */
  3588. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3589. psli = &phba->sli;
  3590. /* Restart HBA */
  3591. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3592. "0337 Restart HBA Data: x%x x%x\n",
  3593. phba->pport->port_state, psli->sli_flag);
  3594. word0 = 0;
  3595. mb = (MAILBOX_t *) &word0;
  3596. mb->mbxCommand = MBX_RESTART;
  3597. mb->mbxHc = 1;
  3598. lpfc_reset_barrier(phba);
  3599. to_slim = phba->MBslimaddr;
  3600. writel(*(uint32_t *) mb, to_slim);
  3601. readl(to_slim); /* flush */
  3602. /* Only skip post after fc_ffinit is completed */
  3603. if (phba->pport->port_state)
  3604. word0 = 1; /* This is really setting up word1 */
  3605. else
  3606. word0 = 0; /* This is really setting up word1 */
  3607. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3608. writel(*(uint32_t *) mb, to_slim);
  3609. readl(to_slim); /* flush */
  3610. lpfc_sli_brdreset(phba);
  3611. phba->pport->stopped = 0;
  3612. phba->link_state = LPFC_INIT_START;
  3613. phba->hba_flag = 0;
  3614. spin_unlock_irq(&phba->hbalock);
  3615. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3616. psli->stats_start = get_seconds();
  3617. /* Give the INITFF and Post time to settle. */
  3618. mdelay(100);
  3619. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3620. if (hba_aer_enabled)
  3621. pci_disable_pcie_error_reporting(phba->pcidev);
  3622. lpfc_hba_down_post(phba);
  3623. return 0;
  3624. }
  3625. /**
  3626. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3627. * @phba: Pointer to HBA context object.
  3628. *
  3629. * This function is called in the SLI initialization code path to restart
  3630. * a SLI4 HBA. The caller is not required to hold any lock.
  3631. * At the end of the function, it calls lpfc_hba_down_post function to
  3632. * free any pending commands.
  3633. **/
  3634. static int
  3635. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3636. {
  3637. struct lpfc_sli *psli = &phba->sli;
  3638. uint32_t hba_aer_enabled;
  3639. /* Restart HBA */
  3640. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3641. "0296 Restart HBA Data: x%x x%x\n",
  3642. phba->pport->port_state, psli->sli_flag);
  3643. /* Take PCIe device Advanced Error Reporting (AER) state */
  3644. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3645. lpfc_sli4_brdreset(phba);
  3646. spin_lock_irq(&phba->hbalock);
  3647. phba->pport->stopped = 0;
  3648. phba->link_state = LPFC_INIT_START;
  3649. phba->hba_flag = 0;
  3650. spin_unlock_irq(&phba->hbalock);
  3651. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3652. psli->stats_start = get_seconds();
  3653. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3654. if (hba_aer_enabled)
  3655. pci_disable_pcie_error_reporting(phba->pcidev);
  3656. lpfc_hba_down_post(phba);
  3657. return 0;
  3658. }
  3659. /**
  3660. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3661. * @phba: Pointer to HBA context object.
  3662. *
  3663. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3664. * API jump table function pointer from the lpfc_hba struct.
  3665. **/
  3666. int
  3667. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3668. {
  3669. return phba->lpfc_sli_brdrestart(phba);
  3670. }
  3671. /**
  3672. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3673. * @phba: Pointer to HBA context object.
  3674. *
  3675. * This function is called after a HBA restart to wait for successful
  3676. * restart of the HBA. Successful restart of the HBA is indicated by
  3677. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3678. * iteration, the function will restart the HBA again. The function returns
  3679. * zero if HBA successfully restarted else returns negative error code.
  3680. **/
  3681. static int
  3682. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3683. {
  3684. uint32_t status, i = 0;
  3685. /* Read the HBA Host Status Register */
  3686. if (lpfc_readl(phba->HSregaddr, &status))
  3687. return -EIO;
  3688. /* Check status register to see what current state is */
  3689. i = 0;
  3690. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3691. /* Check every 10ms for 10 retries, then every 100ms for 90
  3692. * retries, then every 1 sec for 50 retires for a total of
  3693. * ~60 seconds before reset the board again and check every
  3694. * 1 sec for 50 retries. The up to 60 seconds before the
  3695. * board ready is required by the Falcon FIPS zeroization
  3696. * complete, and any reset the board in between shall cause
  3697. * restart of zeroization, further delay the board ready.
  3698. */
  3699. if (i++ >= 200) {
  3700. /* Adapter failed to init, timeout, status reg
  3701. <status> */
  3702. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3703. "0436 Adapter failed to init, "
  3704. "timeout, status reg x%x, "
  3705. "FW Data: A8 x%x AC x%x\n", status,
  3706. readl(phba->MBslimaddr + 0xa8),
  3707. readl(phba->MBslimaddr + 0xac));
  3708. phba->link_state = LPFC_HBA_ERROR;
  3709. return -ETIMEDOUT;
  3710. }
  3711. /* Check to see if any errors occurred during init */
  3712. if (status & HS_FFERM) {
  3713. /* ERROR: During chipset initialization */
  3714. /* Adapter failed to init, chipset, status reg
  3715. <status> */
  3716. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3717. "0437 Adapter failed to init, "
  3718. "chipset, status reg x%x, "
  3719. "FW Data: A8 x%x AC x%x\n", status,
  3720. readl(phba->MBslimaddr + 0xa8),
  3721. readl(phba->MBslimaddr + 0xac));
  3722. phba->link_state = LPFC_HBA_ERROR;
  3723. return -EIO;
  3724. }
  3725. if (i <= 10)
  3726. msleep(10);
  3727. else if (i <= 100)
  3728. msleep(100);
  3729. else
  3730. msleep(1000);
  3731. if (i == 150) {
  3732. /* Do post */
  3733. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3734. lpfc_sli_brdrestart(phba);
  3735. }
  3736. /* Read the HBA Host Status Register */
  3737. if (lpfc_readl(phba->HSregaddr, &status))
  3738. return -EIO;
  3739. }
  3740. /* Check to see if any errors occurred during init */
  3741. if (status & HS_FFERM) {
  3742. /* ERROR: During chipset initialization */
  3743. /* Adapter failed to init, chipset, status reg <status> */
  3744. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3745. "0438 Adapter failed to init, chipset, "
  3746. "status reg x%x, "
  3747. "FW Data: A8 x%x AC x%x\n", status,
  3748. readl(phba->MBslimaddr + 0xa8),
  3749. readl(phba->MBslimaddr + 0xac));
  3750. phba->link_state = LPFC_HBA_ERROR;
  3751. return -EIO;
  3752. }
  3753. /* Clear all interrupt enable conditions */
  3754. writel(0, phba->HCregaddr);
  3755. readl(phba->HCregaddr); /* flush */
  3756. /* setup host attn register */
  3757. writel(0xffffffff, phba->HAregaddr);
  3758. readl(phba->HAregaddr); /* flush */
  3759. return 0;
  3760. }
  3761. /**
  3762. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3763. *
  3764. * This function calculates and returns the number of HBQs required to be
  3765. * configured.
  3766. **/
  3767. int
  3768. lpfc_sli_hbq_count(void)
  3769. {
  3770. return ARRAY_SIZE(lpfc_hbq_defs);
  3771. }
  3772. /**
  3773. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3774. *
  3775. * This function adds the number of hbq entries in every HBQ to get
  3776. * the total number of hbq entries required for the HBA and returns
  3777. * the total count.
  3778. **/
  3779. static int
  3780. lpfc_sli_hbq_entry_count(void)
  3781. {
  3782. int hbq_count = lpfc_sli_hbq_count();
  3783. int count = 0;
  3784. int i;
  3785. for (i = 0; i < hbq_count; ++i)
  3786. count += lpfc_hbq_defs[i]->entry_count;
  3787. return count;
  3788. }
  3789. /**
  3790. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3791. *
  3792. * This function calculates amount of memory required for all hbq entries
  3793. * to be configured and returns the total memory required.
  3794. **/
  3795. int
  3796. lpfc_sli_hbq_size(void)
  3797. {
  3798. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3799. }
  3800. /**
  3801. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3802. * @phba: Pointer to HBA context object.
  3803. *
  3804. * This function is called during the SLI initialization to configure
  3805. * all the HBQs and post buffers to the HBQ. The caller is not
  3806. * required to hold any locks. This function will return zero if successful
  3807. * else it will return negative error code.
  3808. **/
  3809. static int
  3810. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3811. {
  3812. int hbq_count = lpfc_sli_hbq_count();
  3813. LPFC_MBOXQ_t *pmb;
  3814. MAILBOX_t *pmbox;
  3815. uint32_t hbqno;
  3816. uint32_t hbq_entry_index;
  3817. /* Get a Mailbox buffer to setup mailbox
  3818. * commands for HBA initialization
  3819. */
  3820. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3821. if (!pmb)
  3822. return -ENOMEM;
  3823. pmbox = &pmb->u.mb;
  3824. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3825. phba->link_state = LPFC_INIT_MBX_CMDS;
  3826. phba->hbq_in_use = 1;
  3827. hbq_entry_index = 0;
  3828. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3829. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3830. phba->hbqs[hbqno].hbqPutIdx = 0;
  3831. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3832. phba->hbqs[hbqno].entry_count =
  3833. lpfc_hbq_defs[hbqno]->entry_count;
  3834. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3835. hbq_entry_index, pmb);
  3836. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3837. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3838. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3839. mbxStatus <status>, ring <num> */
  3840. lpfc_printf_log(phba, KERN_ERR,
  3841. LOG_SLI | LOG_VPORT,
  3842. "1805 Adapter failed to init. "
  3843. "Data: x%x x%x x%x\n",
  3844. pmbox->mbxCommand,
  3845. pmbox->mbxStatus, hbqno);
  3846. phba->link_state = LPFC_HBA_ERROR;
  3847. mempool_free(pmb, phba->mbox_mem_pool);
  3848. return -ENXIO;
  3849. }
  3850. }
  3851. phba->hbq_count = hbq_count;
  3852. mempool_free(pmb, phba->mbox_mem_pool);
  3853. /* Initially populate or replenish the HBQs */
  3854. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3855. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3856. return 0;
  3857. }
  3858. /**
  3859. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3860. * @phba: Pointer to HBA context object.
  3861. *
  3862. * This function is called during the SLI initialization to configure
  3863. * all the HBQs and post buffers to the HBQ. The caller is not
  3864. * required to hold any locks. This function will return zero if successful
  3865. * else it will return negative error code.
  3866. **/
  3867. static int
  3868. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3869. {
  3870. phba->hbq_in_use = 1;
  3871. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3872. phba->hbq_count = 1;
  3873. /* Initially populate or replenish the HBQs */
  3874. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3875. return 0;
  3876. }
  3877. /**
  3878. * lpfc_sli_config_port - Issue config port mailbox command
  3879. * @phba: Pointer to HBA context object.
  3880. * @sli_mode: sli mode - 2/3
  3881. *
  3882. * This function is called by the sli intialization code path
  3883. * to issue config_port mailbox command. This function restarts the
  3884. * HBA firmware and issues a config_port mailbox command to configure
  3885. * the SLI interface in the sli mode specified by sli_mode
  3886. * variable. The caller is not required to hold any locks.
  3887. * The function returns 0 if successful, else returns negative error
  3888. * code.
  3889. **/
  3890. int
  3891. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3892. {
  3893. LPFC_MBOXQ_t *pmb;
  3894. uint32_t resetcount = 0, rc = 0, done = 0;
  3895. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3896. if (!pmb) {
  3897. phba->link_state = LPFC_HBA_ERROR;
  3898. return -ENOMEM;
  3899. }
  3900. phba->sli_rev = sli_mode;
  3901. while (resetcount < 2 && !done) {
  3902. spin_lock_irq(&phba->hbalock);
  3903. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3904. spin_unlock_irq(&phba->hbalock);
  3905. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3906. lpfc_sli_brdrestart(phba);
  3907. rc = lpfc_sli_chipset_init(phba);
  3908. if (rc)
  3909. break;
  3910. spin_lock_irq(&phba->hbalock);
  3911. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3912. spin_unlock_irq(&phba->hbalock);
  3913. resetcount++;
  3914. /* Call pre CONFIG_PORT mailbox command initialization. A
  3915. * value of 0 means the call was successful. Any other
  3916. * nonzero value is a failure, but if ERESTART is returned,
  3917. * the driver may reset the HBA and try again.
  3918. */
  3919. rc = lpfc_config_port_prep(phba);
  3920. if (rc == -ERESTART) {
  3921. phba->link_state = LPFC_LINK_UNKNOWN;
  3922. continue;
  3923. } else if (rc)
  3924. break;
  3925. phba->link_state = LPFC_INIT_MBX_CMDS;
  3926. lpfc_config_port(phba, pmb);
  3927. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3928. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3929. LPFC_SLI3_HBQ_ENABLED |
  3930. LPFC_SLI3_CRP_ENABLED |
  3931. LPFC_SLI3_BG_ENABLED |
  3932. LPFC_SLI3_DSS_ENABLED);
  3933. if (rc != MBX_SUCCESS) {
  3934. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3935. "0442 Adapter failed to init, mbxCmd x%x "
  3936. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3937. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3938. spin_lock_irq(&phba->hbalock);
  3939. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3940. spin_unlock_irq(&phba->hbalock);
  3941. rc = -ENXIO;
  3942. } else {
  3943. /* Allow asynchronous mailbox command to go through */
  3944. spin_lock_irq(&phba->hbalock);
  3945. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3946. spin_unlock_irq(&phba->hbalock);
  3947. done = 1;
  3948. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  3949. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  3950. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3951. "3110 Port did not grant ASABT\n");
  3952. }
  3953. }
  3954. if (!done) {
  3955. rc = -EINVAL;
  3956. goto do_prep_failed;
  3957. }
  3958. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3959. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3960. rc = -ENXIO;
  3961. goto do_prep_failed;
  3962. }
  3963. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3964. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3965. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3966. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3967. phba->max_vpi : phba->max_vports;
  3968. } else
  3969. phba->max_vpi = 0;
  3970. phba->fips_level = 0;
  3971. phba->fips_spec_rev = 0;
  3972. if (pmb->u.mb.un.varCfgPort.gdss) {
  3973. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3974. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3975. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3976. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3977. "2850 Security Crypto Active. FIPS x%d "
  3978. "(Spec Rev: x%d)",
  3979. phba->fips_level, phba->fips_spec_rev);
  3980. }
  3981. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3982. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3983. "2856 Config Port Security Crypto "
  3984. "Error: x%x ",
  3985. pmb->u.mb.un.varCfgPort.sec_err);
  3986. }
  3987. if (pmb->u.mb.un.varCfgPort.gerbm)
  3988. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3989. if (pmb->u.mb.un.varCfgPort.gcrp)
  3990. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3991. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3992. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3993. if (phba->cfg_enable_bg) {
  3994. if (pmb->u.mb.un.varCfgPort.gbg)
  3995. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3996. else
  3997. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3998. "0443 Adapter did not grant "
  3999. "BlockGuard\n");
  4000. }
  4001. } else {
  4002. phba->hbq_get = NULL;
  4003. phba->port_gp = phba->mbox->us.s2.port;
  4004. phba->max_vpi = 0;
  4005. }
  4006. do_prep_failed:
  4007. mempool_free(pmb, phba->mbox_mem_pool);
  4008. return rc;
  4009. }
  4010. /**
  4011. * lpfc_sli_hba_setup - SLI intialization function
  4012. * @phba: Pointer to HBA context object.
  4013. *
  4014. * This function is the main SLI intialization function. This function
  4015. * is called by the HBA intialization code, HBA reset code and HBA
  4016. * error attention handler code. Caller is not required to hold any
  4017. * locks. This function issues config_port mailbox command to configure
  4018. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4019. * calls the config_port_post function to issue init_link mailbox
  4020. * command and to start the discovery. The function will return zero
  4021. * if successful, else it will return negative error code.
  4022. **/
  4023. int
  4024. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4025. {
  4026. uint32_t rc;
  4027. int mode = 3, i;
  4028. int longs;
  4029. switch (lpfc_sli_mode) {
  4030. case 2:
  4031. if (phba->cfg_enable_npiv) {
  4032. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4033. "1824 NPIV enabled: Override lpfc_sli_mode "
  4034. "parameter (%d) to auto (0).\n",
  4035. lpfc_sli_mode);
  4036. break;
  4037. }
  4038. mode = 2;
  4039. break;
  4040. case 0:
  4041. case 3:
  4042. break;
  4043. default:
  4044. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4045. "1819 Unrecognized lpfc_sli_mode "
  4046. "parameter: %d.\n", lpfc_sli_mode);
  4047. break;
  4048. }
  4049. rc = lpfc_sli_config_port(phba, mode);
  4050. if (rc && lpfc_sli_mode == 3)
  4051. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4052. "1820 Unable to select SLI-3. "
  4053. "Not supported by adapter.\n");
  4054. if (rc && mode != 2)
  4055. rc = lpfc_sli_config_port(phba, 2);
  4056. if (rc)
  4057. goto lpfc_sli_hba_setup_error;
  4058. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4059. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4060. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4061. if (!rc) {
  4062. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4063. "2709 This device supports "
  4064. "Advanced Error Reporting (AER)\n");
  4065. spin_lock_irq(&phba->hbalock);
  4066. phba->hba_flag |= HBA_AER_ENABLED;
  4067. spin_unlock_irq(&phba->hbalock);
  4068. } else {
  4069. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4070. "2708 This device does not support "
  4071. "Advanced Error Reporting (AER)\n");
  4072. phba->cfg_aer_support = 0;
  4073. }
  4074. }
  4075. if (phba->sli_rev == 3) {
  4076. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4077. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4078. } else {
  4079. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4080. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4081. phba->sli3_options = 0;
  4082. }
  4083. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4084. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4085. phba->sli_rev, phba->max_vpi);
  4086. rc = lpfc_sli_ring_map(phba);
  4087. if (rc)
  4088. goto lpfc_sli_hba_setup_error;
  4089. /* Initialize VPIs. */
  4090. if (phba->sli_rev == LPFC_SLI_REV3) {
  4091. /*
  4092. * The VPI bitmask and physical ID array are allocated
  4093. * and initialized once only - at driver load. A port
  4094. * reset doesn't need to reinitialize this memory.
  4095. */
  4096. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4097. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4098. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4099. GFP_KERNEL);
  4100. if (!phba->vpi_bmask) {
  4101. rc = -ENOMEM;
  4102. goto lpfc_sli_hba_setup_error;
  4103. }
  4104. phba->vpi_ids = kzalloc(
  4105. (phba->max_vpi+1) * sizeof(uint16_t),
  4106. GFP_KERNEL);
  4107. if (!phba->vpi_ids) {
  4108. kfree(phba->vpi_bmask);
  4109. rc = -ENOMEM;
  4110. goto lpfc_sli_hba_setup_error;
  4111. }
  4112. for (i = 0; i < phba->max_vpi; i++)
  4113. phba->vpi_ids[i] = i;
  4114. }
  4115. }
  4116. /* Init HBQs */
  4117. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4118. rc = lpfc_sli_hbq_setup(phba);
  4119. if (rc)
  4120. goto lpfc_sli_hba_setup_error;
  4121. }
  4122. spin_lock_irq(&phba->hbalock);
  4123. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4124. spin_unlock_irq(&phba->hbalock);
  4125. rc = lpfc_config_port_post(phba);
  4126. if (rc)
  4127. goto lpfc_sli_hba_setup_error;
  4128. return rc;
  4129. lpfc_sli_hba_setup_error:
  4130. phba->link_state = LPFC_HBA_ERROR;
  4131. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4132. "0445 Firmware initialization failed\n");
  4133. return rc;
  4134. }
  4135. /**
  4136. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4137. * @phba: Pointer to HBA context object.
  4138. * @mboxq: mailbox pointer.
  4139. * This function issue a dump mailbox command to read config region
  4140. * 23 and parse the records in the region and populate driver
  4141. * data structure.
  4142. **/
  4143. static int
  4144. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4145. {
  4146. LPFC_MBOXQ_t *mboxq;
  4147. struct lpfc_dmabuf *mp;
  4148. struct lpfc_mqe *mqe;
  4149. uint32_t data_length;
  4150. int rc;
  4151. /* Program the default value of vlan_id and fc_map */
  4152. phba->valid_vlan = 0;
  4153. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4154. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4155. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4156. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4157. if (!mboxq)
  4158. return -ENOMEM;
  4159. mqe = &mboxq->u.mqe;
  4160. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4161. rc = -ENOMEM;
  4162. goto out_free_mboxq;
  4163. }
  4164. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4165. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4166. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4167. "(%d):2571 Mailbox cmd x%x Status x%x "
  4168. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4169. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4170. "CQ: x%x x%x x%x x%x\n",
  4171. mboxq->vport ? mboxq->vport->vpi : 0,
  4172. bf_get(lpfc_mqe_command, mqe),
  4173. bf_get(lpfc_mqe_status, mqe),
  4174. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4175. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4176. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4177. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4178. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4179. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4180. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4181. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4182. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4183. mboxq->mcqe.word0,
  4184. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4185. mboxq->mcqe.trailer);
  4186. if (rc) {
  4187. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4188. kfree(mp);
  4189. rc = -EIO;
  4190. goto out_free_mboxq;
  4191. }
  4192. data_length = mqe->un.mb_words[5];
  4193. if (data_length > DMP_RGN23_SIZE) {
  4194. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4195. kfree(mp);
  4196. rc = -EIO;
  4197. goto out_free_mboxq;
  4198. }
  4199. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4200. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4201. kfree(mp);
  4202. rc = 0;
  4203. out_free_mboxq:
  4204. mempool_free(mboxq, phba->mbox_mem_pool);
  4205. return rc;
  4206. }
  4207. /**
  4208. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4209. * @phba: pointer to lpfc hba data structure.
  4210. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4211. * @vpd: pointer to the memory to hold resulting port vpd data.
  4212. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4213. * On output, the number of data bytes in @vpd.
  4214. *
  4215. * This routine executes a READ_REV SLI4 mailbox command. In
  4216. * addition, this routine gets the port vpd data.
  4217. *
  4218. * Return codes
  4219. * 0 - successful
  4220. * -ENOMEM - could not allocated memory.
  4221. **/
  4222. static int
  4223. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4224. uint8_t *vpd, uint32_t *vpd_size)
  4225. {
  4226. int rc = 0;
  4227. uint32_t dma_size;
  4228. struct lpfc_dmabuf *dmabuf;
  4229. struct lpfc_mqe *mqe;
  4230. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4231. if (!dmabuf)
  4232. return -ENOMEM;
  4233. /*
  4234. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4235. * mailbox command.
  4236. */
  4237. dma_size = *vpd_size;
  4238. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4239. dma_size,
  4240. &dmabuf->phys,
  4241. GFP_KERNEL);
  4242. if (!dmabuf->virt) {
  4243. kfree(dmabuf);
  4244. return -ENOMEM;
  4245. }
  4246. memset(dmabuf->virt, 0, dma_size);
  4247. /*
  4248. * The SLI4 implementation of READ_REV conflicts at word1,
  4249. * bits 31:16 and SLI4 adds vpd functionality not present
  4250. * in SLI3. This code corrects the conflicts.
  4251. */
  4252. lpfc_read_rev(phba, mboxq);
  4253. mqe = &mboxq->u.mqe;
  4254. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4255. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4256. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4257. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4258. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4259. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4260. if (rc) {
  4261. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4262. dmabuf->virt, dmabuf->phys);
  4263. kfree(dmabuf);
  4264. return -EIO;
  4265. }
  4266. /*
  4267. * The available vpd length cannot be bigger than the
  4268. * DMA buffer passed to the port. Catch the less than
  4269. * case and update the caller's size.
  4270. */
  4271. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4272. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4273. memcpy(vpd, dmabuf->virt, *vpd_size);
  4274. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4275. dmabuf->virt, dmabuf->phys);
  4276. kfree(dmabuf);
  4277. return 0;
  4278. }
  4279. /**
  4280. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4281. * @phba: pointer to lpfc hba data structure.
  4282. *
  4283. * This routine retrieves SLI4 device physical port name this PCI function
  4284. * is attached to.
  4285. *
  4286. * Return codes
  4287. * 0 - sucessful
  4288. * otherwise - failed to retrieve physical port name
  4289. **/
  4290. static int
  4291. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4292. {
  4293. LPFC_MBOXQ_t *mboxq;
  4294. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4295. struct lpfc_controller_attribute *cntl_attr;
  4296. struct lpfc_mbx_get_port_name *get_port_name;
  4297. void *virtaddr = NULL;
  4298. uint32_t alloclen, reqlen;
  4299. uint32_t shdr_status, shdr_add_status;
  4300. union lpfc_sli4_cfg_shdr *shdr;
  4301. char cport_name = 0;
  4302. int rc;
  4303. /* We assume nothing at this point */
  4304. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4305. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4306. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4307. if (!mboxq)
  4308. return -ENOMEM;
  4309. /* obtain link type and link number via READ_CONFIG */
  4310. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4311. lpfc_sli4_read_config(phba);
  4312. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4313. goto retrieve_ppname;
  4314. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4315. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4316. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4317. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4318. LPFC_SLI4_MBX_NEMBED);
  4319. if (alloclen < reqlen) {
  4320. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4321. "3084 Allocated DMA memory size (%d) is "
  4322. "less than the requested DMA memory size "
  4323. "(%d)\n", alloclen, reqlen);
  4324. rc = -ENOMEM;
  4325. goto out_free_mboxq;
  4326. }
  4327. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4328. virtaddr = mboxq->sge_array->addr[0];
  4329. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4330. shdr = &mbx_cntl_attr->cfg_shdr;
  4331. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4332. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4333. if (shdr_status || shdr_add_status || rc) {
  4334. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4335. "3085 Mailbox x%x (x%x/x%x) failed, "
  4336. "rc:x%x, status:x%x, add_status:x%x\n",
  4337. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4338. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4339. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4340. rc, shdr_status, shdr_add_status);
  4341. rc = -ENXIO;
  4342. goto out_free_mboxq;
  4343. }
  4344. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4345. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4346. phba->sli4_hba.lnk_info.lnk_tp =
  4347. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4348. phba->sli4_hba.lnk_info.lnk_no =
  4349. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4350. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4351. "3086 lnk_type:%d, lnk_numb:%d\n",
  4352. phba->sli4_hba.lnk_info.lnk_tp,
  4353. phba->sli4_hba.lnk_info.lnk_no);
  4354. retrieve_ppname:
  4355. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4356. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4357. sizeof(struct lpfc_mbx_get_port_name) -
  4358. sizeof(struct lpfc_sli4_cfg_mhdr),
  4359. LPFC_SLI4_MBX_EMBED);
  4360. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4361. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4362. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4363. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4364. phba->sli4_hba.lnk_info.lnk_tp);
  4365. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4366. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4367. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4368. if (shdr_status || shdr_add_status || rc) {
  4369. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4370. "3087 Mailbox x%x (x%x/x%x) failed: "
  4371. "rc:x%x, status:x%x, add_status:x%x\n",
  4372. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4373. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4374. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4375. rc, shdr_status, shdr_add_status);
  4376. rc = -ENXIO;
  4377. goto out_free_mboxq;
  4378. }
  4379. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4380. case LPFC_LINK_NUMBER_0:
  4381. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4382. &get_port_name->u.response);
  4383. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4384. break;
  4385. case LPFC_LINK_NUMBER_1:
  4386. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4387. &get_port_name->u.response);
  4388. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4389. break;
  4390. case LPFC_LINK_NUMBER_2:
  4391. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4392. &get_port_name->u.response);
  4393. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4394. break;
  4395. case LPFC_LINK_NUMBER_3:
  4396. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4397. &get_port_name->u.response);
  4398. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4399. break;
  4400. default:
  4401. break;
  4402. }
  4403. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4404. phba->Port[0] = cport_name;
  4405. phba->Port[1] = '\0';
  4406. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4407. "3091 SLI get port name: %s\n", phba->Port);
  4408. }
  4409. out_free_mboxq:
  4410. if (rc != MBX_TIMEOUT) {
  4411. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4412. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4413. else
  4414. mempool_free(mboxq, phba->mbox_mem_pool);
  4415. }
  4416. return rc;
  4417. }
  4418. /**
  4419. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4420. * @phba: pointer to lpfc hba data structure.
  4421. *
  4422. * This routine is called to explicitly arm the SLI4 device's completion and
  4423. * event queues
  4424. **/
  4425. static void
  4426. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4427. {
  4428. uint8_t fcp_eqidx;
  4429. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4430. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4431. fcp_eqidx = 0;
  4432. if (phba->sli4_hba.fcp_cq) {
  4433. do
  4434. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4435. LPFC_QUEUE_REARM);
  4436. while (++fcp_eqidx < phba->cfg_fcp_eq_count);
  4437. }
  4438. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4439. if (phba->sli4_hba.fp_eq) {
  4440. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count;
  4441. fcp_eqidx++)
  4442. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4443. LPFC_QUEUE_REARM);
  4444. }
  4445. }
  4446. /**
  4447. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4448. * @phba: Pointer to HBA context object.
  4449. * @type: The resource extent type.
  4450. * @extnt_count: buffer to hold port available extent count.
  4451. * @extnt_size: buffer to hold element count per extent.
  4452. *
  4453. * This function calls the port and retrievs the number of available
  4454. * extents and their size for a particular extent type.
  4455. *
  4456. * Returns: 0 if successful. Nonzero otherwise.
  4457. **/
  4458. int
  4459. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4460. uint16_t *extnt_count, uint16_t *extnt_size)
  4461. {
  4462. int rc = 0;
  4463. uint32_t length;
  4464. uint32_t mbox_tmo;
  4465. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4466. LPFC_MBOXQ_t *mbox;
  4467. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4468. if (!mbox)
  4469. return -ENOMEM;
  4470. /* Find out how many extents are available for this resource type */
  4471. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4472. sizeof(struct lpfc_sli4_cfg_mhdr));
  4473. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4474. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4475. length, LPFC_SLI4_MBX_EMBED);
  4476. /* Send an extents count of 0 - the GET doesn't use it. */
  4477. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4478. LPFC_SLI4_MBX_EMBED);
  4479. if (unlikely(rc)) {
  4480. rc = -EIO;
  4481. goto err_exit;
  4482. }
  4483. if (!phba->sli4_hba.intr_enable)
  4484. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4485. else {
  4486. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4487. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4488. }
  4489. if (unlikely(rc)) {
  4490. rc = -EIO;
  4491. goto err_exit;
  4492. }
  4493. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4494. if (bf_get(lpfc_mbox_hdr_status,
  4495. &rsrc_info->header.cfg_shdr.response)) {
  4496. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4497. "2930 Failed to get resource extents "
  4498. "Status 0x%x Add'l Status 0x%x\n",
  4499. bf_get(lpfc_mbox_hdr_status,
  4500. &rsrc_info->header.cfg_shdr.response),
  4501. bf_get(lpfc_mbox_hdr_add_status,
  4502. &rsrc_info->header.cfg_shdr.response));
  4503. rc = -EIO;
  4504. goto err_exit;
  4505. }
  4506. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4507. &rsrc_info->u.rsp);
  4508. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4509. &rsrc_info->u.rsp);
  4510. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4511. "3162 Retrieved extents type-%d from port: count:%d, "
  4512. "size:%d\n", type, *extnt_count, *extnt_size);
  4513. err_exit:
  4514. mempool_free(mbox, phba->mbox_mem_pool);
  4515. return rc;
  4516. }
  4517. /**
  4518. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4519. * @phba: Pointer to HBA context object.
  4520. * @type: The extent type to check.
  4521. *
  4522. * This function reads the current available extents from the port and checks
  4523. * if the extent count or extent size has changed since the last access.
  4524. * Callers use this routine post port reset to understand if there is a
  4525. * extent reprovisioning requirement.
  4526. *
  4527. * Returns:
  4528. * -Error: error indicates problem.
  4529. * 1: Extent count or size has changed.
  4530. * 0: No changes.
  4531. **/
  4532. static int
  4533. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4534. {
  4535. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4536. uint16_t size_diff, rsrc_ext_size;
  4537. int rc = 0;
  4538. struct lpfc_rsrc_blks *rsrc_entry;
  4539. struct list_head *rsrc_blk_list = NULL;
  4540. size_diff = 0;
  4541. curr_ext_cnt = 0;
  4542. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4543. &rsrc_ext_cnt,
  4544. &rsrc_ext_size);
  4545. if (unlikely(rc))
  4546. return -EIO;
  4547. switch (type) {
  4548. case LPFC_RSC_TYPE_FCOE_RPI:
  4549. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4550. break;
  4551. case LPFC_RSC_TYPE_FCOE_VPI:
  4552. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4553. break;
  4554. case LPFC_RSC_TYPE_FCOE_XRI:
  4555. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4556. break;
  4557. case LPFC_RSC_TYPE_FCOE_VFI:
  4558. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4559. break;
  4560. default:
  4561. break;
  4562. }
  4563. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4564. curr_ext_cnt++;
  4565. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4566. size_diff++;
  4567. }
  4568. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4569. rc = 1;
  4570. return rc;
  4571. }
  4572. /**
  4573. * lpfc_sli4_cfg_post_extnts -
  4574. * @phba: Pointer to HBA context object.
  4575. * @extnt_cnt - number of available extents.
  4576. * @type - the extent type (rpi, xri, vfi, vpi).
  4577. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4578. * @mbox - pointer to the caller's allocated mailbox structure.
  4579. *
  4580. * This function executes the extents allocation request. It also
  4581. * takes care of the amount of memory needed to allocate or get the
  4582. * allocated extents. It is the caller's responsibility to evaluate
  4583. * the response.
  4584. *
  4585. * Returns:
  4586. * -Error: Error value describes the condition found.
  4587. * 0: if successful
  4588. **/
  4589. static int
  4590. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4591. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4592. {
  4593. int rc = 0;
  4594. uint32_t req_len;
  4595. uint32_t emb_len;
  4596. uint32_t alloc_len, mbox_tmo;
  4597. /* Calculate the total requested length of the dma memory */
  4598. req_len = extnt_cnt * sizeof(uint16_t);
  4599. /*
  4600. * Calculate the size of an embedded mailbox. The uint32_t
  4601. * accounts for extents-specific word.
  4602. */
  4603. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4604. sizeof(uint32_t);
  4605. /*
  4606. * Presume the allocation and response will fit into an embedded
  4607. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4608. */
  4609. *emb = LPFC_SLI4_MBX_EMBED;
  4610. if (req_len > emb_len) {
  4611. req_len = extnt_cnt * sizeof(uint16_t) +
  4612. sizeof(union lpfc_sli4_cfg_shdr) +
  4613. sizeof(uint32_t);
  4614. *emb = LPFC_SLI4_MBX_NEMBED;
  4615. }
  4616. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4617. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4618. req_len, *emb);
  4619. if (alloc_len < req_len) {
  4620. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4621. "2982 Allocated DMA memory size (x%x) is "
  4622. "less than the requested DMA memory "
  4623. "size (x%x)\n", alloc_len, req_len);
  4624. return -ENOMEM;
  4625. }
  4626. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4627. if (unlikely(rc))
  4628. return -EIO;
  4629. if (!phba->sli4_hba.intr_enable)
  4630. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4631. else {
  4632. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4633. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4634. }
  4635. if (unlikely(rc))
  4636. rc = -EIO;
  4637. return rc;
  4638. }
  4639. /**
  4640. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4641. * @phba: Pointer to HBA context object.
  4642. * @type: The resource extent type to allocate.
  4643. *
  4644. * This function allocates the number of elements for the specified
  4645. * resource type.
  4646. **/
  4647. static int
  4648. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4649. {
  4650. bool emb = false;
  4651. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4652. uint16_t rsrc_id, rsrc_start, j, k;
  4653. uint16_t *ids;
  4654. int i, rc;
  4655. unsigned long longs;
  4656. unsigned long *bmask;
  4657. struct lpfc_rsrc_blks *rsrc_blks;
  4658. LPFC_MBOXQ_t *mbox;
  4659. uint32_t length;
  4660. struct lpfc_id_range *id_array = NULL;
  4661. void *virtaddr = NULL;
  4662. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4663. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4664. struct list_head *ext_blk_list;
  4665. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4666. &rsrc_cnt,
  4667. &rsrc_size);
  4668. if (unlikely(rc))
  4669. return -EIO;
  4670. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4671. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4672. "3009 No available Resource Extents "
  4673. "for resource type 0x%x: Count: 0x%x, "
  4674. "Size 0x%x\n", type, rsrc_cnt,
  4675. rsrc_size);
  4676. return -ENOMEM;
  4677. }
  4678. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4679. "2903 Post resource extents type-0x%x: "
  4680. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4681. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4682. if (!mbox)
  4683. return -ENOMEM;
  4684. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4685. if (unlikely(rc)) {
  4686. rc = -EIO;
  4687. goto err_exit;
  4688. }
  4689. /*
  4690. * Figure out where the response is located. Then get local pointers
  4691. * to the response data. The port does not guarantee to respond to
  4692. * all extents counts request so update the local variable with the
  4693. * allocated count from the port.
  4694. */
  4695. if (emb == LPFC_SLI4_MBX_EMBED) {
  4696. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4697. id_array = &rsrc_ext->u.rsp.id[0];
  4698. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4699. } else {
  4700. virtaddr = mbox->sge_array->addr[0];
  4701. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4702. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4703. id_array = &n_rsrc->id;
  4704. }
  4705. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4706. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4707. /*
  4708. * Based on the resource size and count, correct the base and max
  4709. * resource values.
  4710. */
  4711. length = sizeof(struct lpfc_rsrc_blks);
  4712. switch (type) {
  4713. case LPFC_RSC_TYPE_FCOE_RPI:
  4714. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4715. sizeof(unsigned long),
  4716. GFP_KERNEL);
  4717. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4718. rc = -ENOMEM;
  4719. goto err_exit;
  4720. }
  4721. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4722. sizeof(uint16_t),
  4723. GFP_KERNEL);
  4724. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4725. kfree(phba->sli4_hba.rpi_bmask);
  4726. rc = -ENOMEM;
  4727. goto err_exit;
  4728. }
  4729. /*
  4730. * The next_rpi was initialized with the maximum available
  4731. * count but the port may allocate a smaller number. Catch
  4732. * that case and update the next_rpi.
  4733. */
  4734. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4735. /* Initialize local ptrs for common extent processing later. */
  4736. bmask = phba->sli4_hba.rpi_bmask;
  4737. ids = phba->sli4_hba.rpi_ids;
  4738. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4739. break;
  4740. case LPFC_RSC_TYPE_FCOE_VPI:
  4741. phba->vpi_bmask = kzalloc(longs *
  4742. sizeof(unsigned long),
  4743. GFP_KERNEL);
  4744. if (unlikely(!phba->vpi_bmask)) {
  4745. rc = -ENOMEM;
  4746. goto err_exit;
  4747. }
  4748. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4749. sizeof(uint16_t),
  4750. GFP_KERNEL);
  4751. if (unlikely(!phba->vpi_ids)) {
  4752. kfree(phba->vpi_bmask);
  4753. rc = -ENOMEM;
  4754. goto err_exit;
  4755. }
  4756. /* Initialize local ptrs for common extent processing later. */
  4757. bmask = phba->vpi_bmask;
  4758. ids = phba->vpi_ids;
  4759. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4760. break;
  4761. case LPFC_RSC_TYPE_FCOE_XRI:
  4762. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4763. sizeof(unsigned long),
  4764. GFP_KERNEL);
  4765. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4766. rc = -ENOMEM;
  4767. goto err_exit;
  4768. }
  4769. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4770. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4771. sizeof(uint16_t),
  4772. GFP_KERNEL);
  4773. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4774. kfree(phba->sli4_hba.xri_bmask);
  4775. rc = -ENOMEM;
  4776. goto err_exit;
  4777. }
  4778. /* Initialize local ptrs for common extent processing later. */
  4779. bmask = phba->sli4_hba.xri_bmask;
  4780. ids = phba->sli4_hba.xri_ids;
  4781. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4782. break;
  4783. case LPFC_RSC_TYPE_FCOE_VFI:
  4784. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4785. sizeof(unsigned long),
  4786. GFP_KERNEL);
  4787. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4788. rc = -ENOMEM;
  4789. goto err_exit;
  4790. }
  4791. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4792. sizeof(uint16_t),
  4793. GFP_KERNEL);
  4794. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4795. kfree(phba->sli4_hba.vfi_bmask);
  4796. rc = -ENOMEM;
  4797. goto err_exit;
  4798. }
  4799. /* Initialize local ptrs for common extent processing later. */
  4800. bmask = phba->sli4_hba.vfi_bmask;
  4801. ids = phba->sli4_hba.vfi_ids;
  4802. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4803. break;
  4804. default:
  4805. /* Unsupported Opcode. Fail call. */
  4806. id_array = NULL;
  4807. bmask = NULL;
  4808. ids = NULL;
  4809. ext_blk_list = NULL;
  4810. goto err_exit;
  4811. }
  4812. /*
  4813. * Complete initializing the extent configuration with the
  4814. * allocated ids assigned to this function. The bitmask serves
  4815. * as an index into the array and manages the available ids. The
  4816. * array just stores the ids communicated to the port via the wqes.
  4817. */
  4818. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4819. if ((i % 2) == 0)
  4820. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4821. &id_array[k]);
  4822. else
  4823. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4824. &id_array[k]);
  4825. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4826. if (unlikely(!rsrc_blks)) {
  4827. rc = -ENOMEM;
  4828. kfree(bmask);
  4829. kfree(ids);
  4830. goto err_exit;
  4831. }
  4832. rsrc_blks->rsrc_start = rsrc_id;
  4833. rsrc_blks->rsrc_size = rsrc_size;
  4834. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4835. rsrc_start = rsrc_id;
  4836. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4837. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4838. lpfc_sli4_get_els_iocb_cnt(phba);
  4839. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4840. ids[j] = rsrc_id;
  4841. rsrc_id++;
  4842. j++;
  4843. }
  4844. /* Entire word processed. Get next word.*/
  4845. if ((i % 2) == 1)
  4846. k++;
  4847. }
  4848. err_exit:
  4849. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4850. return rc;
  4851. }
  4852. /**
  4853. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4854. * @phba: Pointer to HBA context object.
  4855. * @type: the extent's type.
  4856. *
  4857. * This function deallocates all extents of a particular resource type.
  4858. * SLI4 does not allow for deallocating a particular extent range. It
  4859. * is the caller's responsibility to release all kernel memory resources.
  4860. **/
  4861. static int
  4862. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4863. {
  4864. int rc;
  4865. uint32_t length, mbox_tmo = 0;
  4866. LPFC_MBOXQ_t *mbox;
  4867. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4868. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4869. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4870. if (!mbox)
  4871. return -ENOMEM;
  4872. /*
  4873. * This function sends an embedded mailbox because it only sends the
  4874. * the resource type. All extents of this type are released by the
  4875. * port.
  4876. */
  4877. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4878. sizeof(struct lpfc_sli4_cfg_mhdr));
  4879. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4880. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4881. length, LPFC_SLI4_MBX_EMBED);
  4882. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4883. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4884. LPFC_SLI4_MBX_EMBED);
  4885. if (unlikely(rc)) {
  4886. rc = -EIO;
  4887. goto out_free_mbox;
  4888. }
  4889. if (!phba->sli4_hba.intr_enable)
  4890. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4891. else {
  4892. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4893. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4894. }
  4895. if (unlikely(rc)) {
  4896. rc = -EIO;
  4897. goto out_free_mbox;
  4898. }
  4899. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4900. if (bf_get(lpfc_mbox_hdr_status,
  4901. &dealloc_rsrc->header.cfg_shdr.response)) {
  4902. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4903. "2919 Failed to release resource extents "
  4904. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4905. "Resource memory not released.\n",
  4906. type,
  4907. bf_get(lpfc_mbox_hdr_status,
  4908. &dealloc_rsrc->header.cfg_shdr.response),
  4909. bf_get(lpfc_mbox_hdr_add_status,
  4910. &dealloc_rsrc->header.cfg_shdr.response));
  4911. rc = -EIO;
  4912. goto out_free_mbox;
  4913. }
  4914. /* Release kernel memory resources for the specific type. */
  4915. switch (type) {
  4916. case LPFC_RSC_TYPE_FCOE_VPI:
  4917. kfree(phba->vpi_bmask);
  4918. kfree(phba->vpi_ids);
  4919. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4920. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4921. &phba->lpfc_vpi_blk_list, list) {
  4922. list_del_init(&rsrc_blk->list);
  4923. kfree(rsrc_blk);
  4924. }
  4925. break;
  4926. case LPFC_RSC_TYPE_FCOE_XRI:
  4927. kfree(phba->sli4_hba.xri_bmask);
  4928. kfree(phba->sli4_hba.xri_ids);
  4929. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4930. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  4931. list_del_init(&rsrc_blk->list);
  4932. kfree(rsrc_blk);
  4933. }
  4934. break;
  4935. case LPFC_RSC_TYPE_FCOE_VFI:
  4936. kfree(phba->sli4_hba.vfi_bmask);
  4937. kfree(phba->sli4_hba.vfi_ids);
  4938. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4939. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4940. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  4941. list_del_init(&rsrc_blk->list);
  4942. kfree(rsrc_blk);
  4943. }
  4944. break;
  4945. case LPFC_RSC_TYPE_FCOE_RPI:
  4946. /* RPI bitmask and physical id array are cleaned up earlier. */
  4947. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4948. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  4949. list_del_init(&rsrc_blk->list);
  4950. kfree(rsrc_blk);
  4951. }
  4952. break;
  4953. default:
  4954. break;
  4955. }
  4956. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4957. out_free_mbox:
  4958. mempool_free(mbox, phba->mbox_mem_pool);
  4959. return rc;
  4960. }
  4961. /**
  4962. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  4963. * @phba: Pointer to HBA context object.
  4964. *
  4965. * This function allocates all SLI4 resource identifiers.
  4966. **/
  4967. int
  4968. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  4969. {
  4970. int i, rc, error = 0;
  4971. uint16_t count, base;
  4972. unsigned long longs;
  4973. if (!phba->sli4_hba.rpi_hdrs_in_use)
  4974. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  4975. if (phba->sli4_hba.extents_in_use) {
  4976. /*
  4977. * The port supports resource extents. The XRI, VPI, VFI, RPI
  4978. * resource extent count must be read and allocated before
  4979. * provisioning the resource id arrays.
  4980. */
  4981. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  4982. LPFC_IDX_RSRC_RDY) {
  4983. /*
  4984. * Extent-based resources are set - the driver could
  4985. * be in a port reset. Figure out if any corrective
  4986. * actions need to be taken.
  4987. */
  4988. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4989. LPFC_RSC_TYPE_FCOE_VFI);
  4990. if (rc != 0)
  4991. error++;
  4992. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4993. LPFC_RSC_TYPE_FCOE_VPI);
  4994. if (rc != 0)
  4995. error++;
  4996. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4997. LPFC_RSC_TYPE_FCOE_XRI);
  4998. if (rc != 0)
  4999. error++;
  5000. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5001. LPFC_RSC_TYPE_FCOE_RPI);
  5002. if (rc != 0)
  5003. error++;
  5004. /*
  5005. * It's possible that the number of resources
  5006. * provided to this port instance changed between
  5007. * resets. Detect this condition and reallocate
  5008. * resources. Otherwise, there is no action.
  5009. */
  5010. if (error) {
  5011. lpfc_printf_log(phba, KERN_INFO,
  5012. LOG_MBOX | LOG_INIT,
  5013. "2931 Detected extent resource "
  5014. "change. Reallocating all "
  5015. "extents.\n");
  5016. rc = lpfc_sli4_dealloc_extent(phba,
  5017. LPFC_RSC_TYPE_FCOE_VFI);
  5018. rc = lpfc_sli4_dealloc_extent(phba,
  5019. LPFC_RSC_TYPE_FCOE_VPI);
  5020. rc = lpfc_sli4_dealloc_extent(phba,
  5021. LPFC_RSC_TYPE_FCOE_XRI);
  5022. rc = lpfc_sli4_dealloc_extent(phba,
  5023. LPFC_RSC_TYPE_FCOE_RPI);
  5024. } else
  5025. return 0;
  5026. }
  5027. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5028. if (unlikely(rc))
  5029. goto err_exit;
  5030. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5031. if (unlikely(rc))
  5032. goto err_exit;
  5033. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5034. if (unlikely(rc))
  5035. goto err_exit;
  5036. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5037. if (unlikely(rc))
  5038. goto err_exit;
  5039. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5040. LPFC_IDX_RSRC_RDY);
  5041. return rc;
  5042. } else {
  5043. /*
  5044. * The port does not support resource extents. The XRI, VPI,
  5045. * VFI, RPI resource ids were determined from READ_CONFIG.
  5046. * Just allocate the bitmasks and provision the resource id
  5047. * arrays. If a port reset is active, the resources don't
  5048. * need any action - just exit.
  5049. */
  5050. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5051. LPFC_IDX_RSRC_RDY) {
  5052. lpfc_sli4_dealloc_resource_identifiers(phba);
  5053. lpfc_sli4_remove_rpis(phba);
  5054. }
  5055. /* RPIs. */
  5056. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5057. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5058. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5059. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5060. sizeof(unsigned long),
  5061. GFP_KERNEL);
  5062. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5063. rc = -ENOMEM;
  5064. goto err_exit;
  5065. }
  5066. phba->sli4_hba.rpi_ids = kzalloc(count *
  5067. sizeof(uint16_t),
  5068. GFP_KERNEL);
  5069. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5070. rc = -ENOMEM;
  5071. goto free_rpi_bmask;
  5072. }
  5073. for (i = 0; i < count; i++)
  5074. phba->sli4_hba.rpi_ids[i] = base + i;
  5075. /* VPIs. */
  5076. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5077. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5078. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5079. phba->vpi_bmask = kzalloc(longs *
  5080. sizeof(unsigned long),
  5081. GFP_KERNEL);
  5082. if (unlikely(!phba->vpi_bmask)) {
  5083. rc = -ENOMEM;
  5084. goto free_rpi_ids;
  5085. }
  5086. phba->vpi_ids = kzalloc(count *
  5087. sizeof(uint16_t),
  5088. GFP_KERNEL);
  5089. if (unlikely(!phba->vpi_ids)) {
  5090. rc = -ENOMEM;
  5091. goto free_vpi_bmask;
  5092. }
  5093. for (i = 0; i < count; i++)
  5094. phba->vpi_ids[i] = base + i;
  5095. /* XRIs. */
  5096. count = phba->sli4_hba.max_cfg_param.max_xri;
  5097. base = phba->sli4_hba.max_cfg_param.xri_base;
  5098. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5099. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5100. sizeof(unsigned long),
  5101. GFP_KERNEL);
  5102. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5103. rc = -ENOMEM;
  5104. goto free_vpi_ids;
  5105. }
  5106. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5107. phba->sli4_hba.xri_ids = kzalloc(count *
  5108. sizeof(uint16_t),
  5109. GFP_KERNEL);
  5110. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5111. rc = -ENOMEM;
  5112. goto free_xri_bmask;
  5113. }
  5114. for (i = 0; i < count; i++)
  5115. phba->sli4_hba.xri_ids[i] = base + i;
  5116. /* VFIs. */
  5117. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5118. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5119. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5120. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5121. sizeof(unsigned long),
  5122. GFP_KERNEL);
  5123. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5124. rc = -ENOMEM;
  5125. goto free_xri_ids;
  5126. }
  5127. phba->sli4_hba.vfi_ids = kzalloc(count *
  5128. sizeof(uint16_t),
  5129. GFP_KERNEL);
  5130. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5131. rc = -ENOMEM;
  5132. goto free_vfi_bmask;
  5133. }
  5134. for (i = 0; i < count; i++)
  5135. phba->sli4_hba.vfi_ids[i] = base + i;
  5136. /*
  5137. * Mark all resources ready. An HBA reset doesn't need
  5138. * to reset the initialization.
  5139. */
  5140. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5141. LPFC_IDX_RSRC_RDY);
  5142. return 0;
  5143. }
  5144. free_vfi_bmask:
  5145. kfree(phba->sli4_hba.vfi_bmask);
  5146. free_xri_ids:
  5147. kfree(phba->sli4_hba.xri_ids);
  5148. free_xri_bmask:
  5149. kfree(phba->sli4_hba.xri_bmask);
  5150. free_vpi_ids:
  5151. kfree(phba->vpi_ids);
  5152. free_vpi_bmask:
  5153. kfree(phba->vpi_bmask);
  5154. free_rpi_ids:
  5155. kfree(phba->sli4_hba.rpi_ids);
  5156. free_rpi_bmask:
  5157. kfree(phba->sli4_hba.rpi_bmask);
  5158. err_exit:
  5159. return rc;
  5160. }
  5161. /**
  5162. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5163. * @phba: Pointer to HBA context object.
  5164. *
  5165. * This function allocates the number of elements for the specified
  5166. * resource type.
  5167. **/
  5168. int
  5169. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5170. {
  5171. if (phba->sli4_hba.extents_in_use) {
  5172. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5173. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5174. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5175. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5176. } else {
  5177. kfree(phba->vpi_bmask);
  5178. kfree(phba->vpi_ids);
  5179. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5180. kfree(phba->sli4_hba.xri_bmask);
  5181. kfree(phba->sli4_hba.xri_ids);
  5182. kfree(phba->sli4_hba.vfi_bmask);
  5183. kfree(phba->sli4_hba.vfi_ids);
  5184. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5185. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5186. }
  5187. return 0;
  5188. }
  5189. /**
  5190. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5191. * @phba: Pointer to HBA context object.
  5192. * @type: The resource extent type.
  5193. * @extnt_count: buffer to hold port extent count response
  5194. * @extnt_size: buffer to hold port extent size response.
  5195. *
  5196. * This function calls the port to read the host allocated extents
  5197. * for a particular type.
  5198. **/
  5199. int
  5200. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5201. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5202. {
  5203. bool emb;
  5204. int rc = 0;
  5205. uint16_t curr_blks = 0;
  5206. uint32_t req_len, emb_len;
  5207. uint32_t alloc_len, mbox_tmo;
  5208. struct list_head *blk_list_head;
  5209. struct lpfc_rsrc_blks *rsrc_blk;
  5210. LPFC_MBOXQ_t *mbox;
  5211. void *virtaddr = NULL;
  5212. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5213. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5214. union lpfc_sli4_cfg_shdr *shdr;
  5215. switch (type) {
  5216. case LPFC_RSC_TYPE_FCOE_VPI:
  5217. blk_list_head = &phba->lpfc_vpi_blk_list;
  5218. break;
  5219. case LPFC_RSC_TYPE_FCOE_XRI:
  5220. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5221. break;
  5222. case LPFC_RSC_TYPE_FCOE_VFI:
  5223. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5224. break;
  5225. case LPFC_RSC_TYPE_FCOE_RPI:
  5226. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5227. break;
  5228. default:
  5229. return -EIO;
  5230. }
  5231. /* Count the number of extents currently allocatd for this type. */
  5232. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5233. if (curr_blks == 0) {
  5234. /*
  5235. * The GET_ALLOCATED mailbox does not return the size,
  5236. * just the count. The size should be just the size
  5237. * stored in the current allocated block and all sizes
  5238. * for an extent type are the same so set the return
  5239. * value now.
  5240. */
  5241. *extnt_size = rsrc_blk->rsrc_size;
  5242. }
  5243. curr_blks++;
  5244. }
  5245. /* Calculate the total requested length of the dma memory. */
  5246. req_len = curr_blks * sizeof(uint16_t);
  5247. /*
  5248. * Calculate the size of an embedded mailbox. The uint32_t
  5249. * accounts for extents-specific word.
  5250. */
  5251. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5252. sizeof(uint32_t);
  5253. /*
  5254. * Presume the allocation and response will fit into an embedded
  5255. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5256. */
  5257. emb = LPFC_SLI4_MBX_EMBED;
  5258. req_len = emb_len;
  5259. if (req_len > emb_len) {
  5260. req_len = curr_blks * sizeof(uint16_t) +
  5261. sizeof(union lpfc_sli4_cfg_shdr) +
  5262. sizeof(uint32_t);
  5263. emb = LPFC_SLI4_MBX_NEMBED;
  5264. }
  5265. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5266. if (!mbox)
  5267. return -ENOMEM;
  5268. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5269. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5270. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5271. req_len, emb);
  5272. if (alloc_len < req_len) {
  5273. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5274. "2983 Allocated DMA memory size (x%x) is "
  5275. "less than the requested DMA memory "
  5276. "size (x%x)\n", alloc_len, req_len);
  5277. rc = -ENOMEM;
  5278. goto err_exit;
  5279. }
  5280. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5281. if (unlikely(rc)) {
  5282. rc = -EIO;
  5283. goto err_exit;
  5284. }
  5285. if (!phba->sli4_hba.intr_enable)
  5286. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5287. else {
  5288. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5289. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5290. }
  5291. if (unlikely(rc)) {
  5292. rc = -EIO;
  5293. goto err_exit;
  5294. }
  5295. /*
  5296. * Figure out where the response is located. Then get local pointers
  5297. * to the response data. The port does not guarantee to respond to
  5298. * all extents counts request so update the local variable with the
  5299. * allocated count from the port.
  5300. */
  5301. if (emb == LPFC_SLI4_MBX_EMBED) {
  5302. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5303. shdr = &rsrc_ext->header.cfg_shdr;
  5304. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5305. } else {
  5306. virtaddr = mbox->sge_array->addr[0];
  5307. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5308. shdr = &n_rsrc->cfg_shdr;
  5309. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5310. }
  5311. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5312. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5313. "2984 Failed to read allocated resources "
  5314. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5315. type,
  5316. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5317. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5318. rc = -EIO;
  5319. goto err_exit;
  5320. }
  5321. err_exit:
  5322. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5323. return rc;
  5324. }
  5325. /**
  5326. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5327. * @phba: pointer to lpfc hba data structure.
  5328. *
  5329. * This routine walks the list of els buffers that have been allocated and
  5330. * repost them to the port by using SGL block post. This is needed after a
  5331. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5332. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5333. * SGL block post mailbox commands to post them to the port. For single els
  5334. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5335. * mailbox command for posting.
  5336. *
  5337. * Returns: 0 = success, non-zero failure.
  5338. **/
  5339. static int
  5340. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5341. {
  5342. struct lpfc_sglq *sglq_entry = NULL;
  5343. struct lpfc_sglq *sglq_entry_next = NULL;
  5344. struct lpfc_sglq *sglq_entry_first = NULL;
  5345. int status, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5346. int last_xritag = NO_XRI;
  5347. LIST_HEAD(prep_sgl_list);
  5348. LIST_HEAD(blck_sgl_list);
  5349. LIST_HEAD(allc_sgl_list);
  5350. LIST_HEAD(post_sgl_list);
  5351. LIST_HEAD(free_sgl_list);
  5352. spin_lock(&phba->hbalock);
  5353. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5354. spin_unlock(&phba->hbalock);
  5355. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5356. &allc_sgl_list, list) {
  5357. list_del_init(&sglq_entry->list);
  5358. block_cnt++;
  5359. if ((last_xritag != NO_XRI) &&
  5360. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5361. /* a hole in xri block, form a sgl posting block */
  5362. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5363. post_cnt = block_cnt - 1;
  5364. /* prepare list for next posting block */
  5365. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5366. block_cnt = 1;
  5367. } else {
  5368. /* prepare list for next posting block */
  5369. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5370. /* enough sgls for non-embed sgl mbox command */
  5371. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5372. list_splice_init(&prep_sgl_list,
  5373. &blck_sgl_list);
  5374. post_cnt = block_cnt;
  5375. block_cnt = 0;
  5376. }
  5377. }
  5378. num_posted++;
  5379. /* keep track of last sgl's xritag */
  5380. last_xritag = sglq_entry->sli4_xritag;
  5381. /* end of repost sgl list condition for els buffers */
  5382. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5383. if (post_cnt == 0) {
  5384. list_splice_init(&prep_sgl_list,
  5385. &blck_sgl_list);
  5386. post_cnt = block_cnt;
  5387. } else if (block_cnt == 1) {
  5388. status = lpfc_sli4_post_sgl(phba,
  5389. sglq_entry->phys, 0,
  5390. sglq_entry->sli4_xritag);
  5391. if (!status) {
  5392. /* successful, put sgl to posted list */
  5393. list_add_tail(&sglq_entry->list,
  5394. &post_sgl_list);
  5395. } else {
  5396. /* Failure, put sgl to free list */
  5397. lpfc_printf_log(phba, KERN_WARNING,
  5398. LOG_SLI,
  5399. "3159 Failed to post els "
  5400. "sgl, xritag:x%x\n",
  5401. sglq_entry->sli4_xritag);
  5402. list_add_tail(&sglq_entry->list,
  5403. &free_sgl_list);
  5404. spin_lock_irq(&phba->hbalock);
  5405. phba->sli4_hba.els_xri_cnt--;
  5406. spin_unlock_irq(&phba->hbalock);
  5407. }
  5408. }
  5409. }
  5410. /* continue until a nembed page worth of sgls */
  5411. if (post_cnt == 0)
  5412. continue;
  5413. /* post the els buffer list sgls as a block */
  5414. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5415. post_cnt);
  5416. if (!status) {
  5417. /* success, put sgl list to posted sgl list */
  5418. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5419. } else {
  5420. /* Failure, put sgl list to free sgl list */
  5421. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5422. struct lpfc_sglq,
  5423. list);
  5424. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5425. "3160 Failed to post els sgl-list, "
  5426. "xritag:x%x-x%x\n",
  5427. sglq_entry_first->sli4_xritag,
  5428. (sglq_entry_first->sli4_xritag +
  5429. post_cnt - 1));
  5430. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5431. spin_lock_irq(&phba->hbalock);
  5432. phba->sli4_hba.els_xri_cnt -= post_cnt;
  5433. spin_unlock_irq(&phba->hbalock);
  5434. }
  5435. /* don't reset xirtag due to hole in xri block */
  5436. if (block_cnt == 0)
  5437. last_xritag = NO_XRI;
  5438. /* reset els sgl post count for next round of posting */
  5439. post_cnt = 0;
  5440. }
  5441. /* free the els sgls failed to post */
  5442. lpfc_free_sgl_list(phba, &free_sgl_list);
  5443. /* push els sgls posted to the availble list */
  5444. if (!list_empty(&post_sgl_list)) {
  5445. spin_lock(&phba->hbalock);
  5446. list_splice_init(&post_sgl_list,
  5447. &phba->sli4_hba.lpfc_sgl_list);
  5448. spin_unlock(&phba->hbalock);
  5449. } else {
  5450. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5451. "3161 Failure to post els sgl to port.\n");
  5452. return -EIO;
  5453. }
  5454. return 0;
  5455. }
  5456. /**
  5457. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5458. * @phba: Pointer to HBA context object.
  5459. *
  5460. * This function is the main SLI4 device intialization PCI function. This
  5461. * function is called by the HBA intialization code, HBA reset code and
  5462. * HBA error attention handler code. Caller is not required to hold any
  5463. * locks.
  5464. **/
  5465. int
  5466. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5467. {
  5468. int rc;
  5469. LPFC_MBOXQ_t *mboxq;
  5470. struct lpfc_mqe *mqe;
  5471. uint8_t *vpd;
  5472. uint32_t vpd_size;
  5473. uint32_t ftr_rsp = 0;
  5474. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5475. struct lpfc_vport *vport = phba->pport;
  5476. struct lpfc_dmabuf *mp;
  5477. /* Perform a PCI function reset to start from clean */
  5478. rc = lpfc_pci_function_reset(phba);
  5479. if (unlikely(rc))
  5480. return -ENODEV;
  5481. /* Check the HBA Host Status Register for readyness */
  5482. rc = lpfc_sli4_post_status_check(phba);
  5483. if (unlikely(rc))
  5484. return -ENODEV;
  5485. else {
  5486. spin_lock_irq(&phba->hbalock);
  5487. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5488. spin_unlock_irq(&phba->hbalock);
  5489. }
  5490. /*
  5491. * Allocate a single mailbox container for initializing the
  5492. * port.
  5493. */
  5494. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5495. if (!mboxq)
  5496. return -ENOMEM;
  5497. /* Issue READ_REV to collect vpd and FW information. */
  5498. vpd_size = SLI4_PAGE_SIZE;
  5499. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5500. if (!vpd) {
  5501. rc = -ENOMEM;
  5502. goto out_free_mbox;
  5503. }
  5504. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5505. if (unlikely(rc)) {
  5506. kfree(vpd);
  5507. goto out_free_mbox;
  5508. }
  5509. mqe = &mboxq->u.mqe;
  5510. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5511. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5512. phba->hba_flag |= HBA_FCOE_MODE;
  5513. else
  5514. phba->hba_flag &= ~HBA_FCOE_MODE;
  5515. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5516. LPFC_DCBX_CEE_MODE)
  5517. phba->hba_flag |= HBA_FIP_SUPPORT;
  5518. else
  5519. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5520. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5521. if (phba->sli_rev != LPFC_SLI_REV4) {
  5522. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5523. "0376 READ_REV Error. SLI Level %d "
  5524. "FCoE enabled %d\n",
  5525. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5526. rc = -EIO;
  5527. kfree(vpd);
  5528. goto out_free_mbox;
  5529. }
  5530. /*
  5531. * Continue initialization with default values even if driver failed
  5532. * to read FCoE param config regions, only read parameters if the
  5533. * board is FCoE
  5534. */
  5535. if (phba->hba_flag & HBA_FCOE_MODE &&
  5536. lpfc_sli4_read_fcoe_params(phba))
  5537. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5538. "2570 Failed to read FCoE parameters\n");
  5539. /*
  5540. * Retrieve sli4 device physical port name, failure of doing it
  5541. * is considered as non-fatal.
  5542. */
  5543. rc = lpfc_sli4_retrieve_pport_name(phba);
  5544. if (!rc)
  5545. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5546. "3080 Successful retrieving SLI4 device "
  5547. "physical port name: %s.\n", phba->Port);
  5548. /*
  5549. * Evaluate the read rev and vpd data. Populate the driver
  5550. * state with the results. If this routine fails, the failure
  5551. * is not fatal as the driver will use generic values.
  5552. */
  5553. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5554. if (unlikely(!rc)) {
  5555. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5556. "0377 Error %d parsing vpd. "
  5557. "Using defaults.\n", rc);
  5558. rc = 0;
  5559. }
  5560. kfree(vpd);
  5561. /* Save information as VPD data */
  5562. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5563. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5564. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5565. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5566. &mqe->un.read_rev);
  5567. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5568. &mqe->un.read_rev);
  5569. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5570. &mqe->un.read_rev);
  5571. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5572. &mqe->un.read_rev);
  5573. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5574. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5575. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5576. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5577. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5578. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5579. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5580. "(%d):0380 READ_REV Status x%x "
  5581. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5582. mboxq->vport ? mboxq->vport->vpi : 0,
  5583. bf_get(lpfc_mqe_status, mqe),
  5584. phba->vpd.rev.opFwName,
  5585. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5586. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5587. /*
  5588. * Discover the port's supported feature set and match it against the
  5589. * hosts requests.
  5590. */
  5591. lpfc_request_features(phba, mboxq);
  5592. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5593. if (unlikely(rc)) {
  5594. rc = -EIO;
  5595. goto out_free_mbox;
  5596. }
  5597. /*
  5598. * The port must support FCP initiator mode as this is the
  5599. * only mode running in the host.
  5600. */
  5601. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5602. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5603. "0378 No support for fcpi mode.\n");
  5604. ftr_rsp++;
  5605. }
  5606. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5607. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5608. else
  5609. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5610. /*
  5611. * If the port cannot support the host's requested features
  5612. * then turn off the global config parameters to disable the
  5613. * feature in the driver. This is not a fatal error.
  5614. */
  5615. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5616. if (phba->cfg_enable_bg) {
  5617. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5618. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5619. else
  5620. ftr_rsp++;
  5621. }
  5622. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5623. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5624. ftr_rsp++;
  5625. if (ftr_rsp) {
  5626. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5627. "0379 Feature Mismatch Data: x%08x %08x "
  5628. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5629. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5630. phba->cfg_enable_npiv, phba->max_vpi);
  5631. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5632. phba->cfg_enable_bg = 0;
  5633. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5634. phba->cfg_enable_npiv = 0;
  5635. }
  5636. /* These SLI3 features are assumed in SLI4 */
  5637. spin_lock_irq(&phba->hbalock);
  5638. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5639. spin_unlock_irq(&phba->hbalock);
  5640. /*
  5641. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5642. * calls depends on these resources to complete port setup.
  5643. */
  5644. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5645. if (rc) {
  5646. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5647. "2920 Failed to alloc Resource IDs "
  5648. "rc = x%x\n", rc);
  5649. goto out_free_mbox;
  5650. }
  5651. /* Read the port's service parameters. */
  5652. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5653. if (rc) {
  5654. phba->link_state = LPFC_HBA_ERROR;
  5655. rc = -ENOMEM;
  5656. goto out_free_mbox;
  5657. }
  5658. mboxq->vport = vport;
  5659. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5660. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5661. if (rc == MBX_SUCCESS) {
  5662. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5663. rc = 0;
  5664. }
  5665. /*
  5666. * This memory was allocated by the lpfc_read_sparam routine. Release
  5667. * it to the mbuf pool.
  5668. */
  5669. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5670. kfree(mp);
  5671. mboxq->context1 = NULL;
  5672. if (unlikely(rc)) {
  5673. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5674. "0382 READ_SPARAM command failed "
  5675. "status %d, mbxStatus x%x\n",
  5676. rc, bf_get(lpfc_mqe_status, mqe));
  5677. phba->link_state = LPFC_HBA_ERROR;
  5678. rc = -EIO;
  5679. goto out_free_mbox;
  5680. }
  5681. lpfc_update_vport_wwn(vport);
  5682. /* Update the fc_host data structures with new wwn. */
  5683. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5684. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5685. /* update host els and scsi xri-sgl sizes and mappings */
  5686. rc = lpfc_sli4_xri_sgl_update(phba);
  5687. if (unlikely(rc)) {
  5688. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5689. "1400 Failed to update xri-sgl size and "
  5690. "mapping: %d\n", rc);
  5691. goto out_free_mbox;
  5692. }
  5693. /* register the els sgl pool to the port */
  5694. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5695. if (unlikely(rc)) {
  5696. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5697. "0582 Error %d during els sgl post "
  5698. "operation\n", rc);
  5699. rc = -ENODEV;
  5700. goto out_free_mbox;
  5701. }
  5702. /* register the allocated scsi sgl pool to the port */
  5703. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5704. if (unlikely(rc)) {
  5705. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5706. "0383 Error %d during scsi sgl post "
  5707. "operation\n", rc);
  5708. /* Some Scsi buffers were moved to the abort scsi list */
  5709. /* A pci function reset will repost them */
  5710. rc = -ENODEV;
  5711. goto out_free_mbox;
  5712. }
  5713. /* Post the rpi header region to the device. */
  5714. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5715. if (unlikely(rc)) {
  5716. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5717. "0393 Error %d during rpi post operation\n",
  5718. rc);
  5719. rc = -ENODEV;
  5720. goto out_free_mbox;
  5721. }
  5722. lpfc_sli4_node_prep(phba);
  5723. /* Create all the SLI4 queues */
  5724. rc = lpfc_sli4_queue_create(phba);
  5725. if (rc) {
  5726. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5727. "3089 Failed to allocate queues\n");
  5728. rc = -ENODEV;
  5729. goto out_stop_timers;
  5730. }
  5731. /* Set up all the queues to the device */
  5732. rc = lpfc_sli4_queue_setup(phba);
  5733. if (unlikely(rc)) {
  5734. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5735. "0381 Error %d during queue setup.\n ", rc);
  5736. goto out_destroy_queue;
  5737. }
  5738. /* Arm the CQs and then EQs on device */
  5739. lpfc_sli4_arm_cqeq_intr(phba);
  5740. /* Indicate device interrupt mode */
  5741. phba->sli4_hba.intr_enable = 1;
  5742. /* Allow asynchronous mailbox command to go through */
  5743. spin_lock_irq(&phba->hbalock);
  5744. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5745. spin_unlock_irq(&phba->hbalock);
  5746. /* Post receive buffers to the device */
  5747. lpfc_sli4_rb_setup(phba);
  5748. /* Reset HBA FCF states after HBA reset */
  5749. phba->fcf.fcf_flag = 0;
  5750. phba->fcf.current_rec.flag = 0;
  5751. /* Start the ELS watchdog timer */
  5752. mod_timer(&vport->els_tmofunc,
  5753. jiffies + HZ * (phba->fc_ratov * 2));
  5754. /* Start heart beat timer */
  5755. mod_timer(&phba->hb_tmofunc,
  5756. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  5757. phba->hb_outstanding = 0;
  5758. phba->last_completion_time = jiffies;
  5759. /* Start error attention (ERATT) polling timer */
  5760. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  5761. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5762. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5763. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5764. if (!rc) {
  5765. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5766. "2829 This device supports "
  5767. "Advanced Error Reporting (AER)\n");
  5768. spin_lock_irq(&phba->hbalock);
  5769. phba->hba_flag |= HBA_AER_ENABLED;
  5770. spin_unlock_irq(&phba->hbalock);
  5771. } else {
  5772. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5773. "2830 This device does not support "
  5774. "Advanced Error Reporting (AER)\n");
  5775. phba->cfg_aer_support = 0;
  5776. }
  5777. rc = 0;
  5778. }
  5779. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5780. /*
  5781. * The FC Port needs to register FCFI (index 0)
  5782. */
  5783. lpfc_reg_fcfi(phba, mboxq);
  5784. mboxq->vport = phba->pport;
  5785. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5786. if (rc != MBX_SUCCESS)
  5787. goto out_unset_queue;
  5788. rc = 0;
  5789. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5790. &mboxq->u.mqe.un.reg_fcfi);
  5791. /* Check if the port is configured to be disabled */
  5792. lpfc_sli_read_link_ste(phba);
  5793. }
  5794. /*
  5795. * The port is ready, set the host's link state to LINK_DOWN
  5796. * in preparation for link interrupts.
  5797. */
  5798. spin_lock_irq(&phba->hbalock);
  5799. phba->link_state = LPFC_LINK_DOWN;
  5800. spin_unlock_irq(&phba->hbalock);
  5801. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5802. (phba->hba_flag & LINK_DISABLED)) {
  5803. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5804. "3103 Adapter Link is disabled.\n");
  5805. lpfc_down_link(phba, mboxq);
  5806. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5807. if (rc != MBX_SUCCESS) {
  5808. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5809. "3104 Adapter failed to issue "
  5810. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5811. goto out_unset_queue;
  5812. }
  5813. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5814. /* don't perform init_link on SLI4 FC port loopback test */
  5815. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  5816. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5817. if (rc)
  5818. goto out_unset_queue;
  5819. }
  5820. }
  5821. mempool_free(mboxq, phba->mbox_mem_pool);
  5822. return rc;
  5823. out_unset_queue:
  5824. /* Unset all the queues set up in this routine when error out */
  5825. lpfc_sli4_queue_unset(phba);
  5826. out_destroy_queue:
  5827. lpfc_sli4_queue_destroy(phba);
  5828. out_stop_timers:
  5829. lpfc_stop_hba_timers(phba);
  5830. out_free_mbox:
  5831. mempool_free(mboxq, phba->mbox_mem_pool);
  5832. return rc;
  5833. }
  5834. /**
  5835. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5836. * @ptr: context object - pointer to hba structure.
  5837. *
  5838. * This is the callback function for mailbox timer. The mailbox
  5839. * timer is armed when a new mailbox command is issued and the timer
  5840. * is deleted when the mailbox complete. The function is called by
  5841. * the kernel timer code when a mailbox does not complete within
  5842. * expected time. This function wakes up the worker thread to
  5843. * process the mailbox timeout and returns. All the processing is
  5844. * done by the worker thread function lpfc_mbox_timeout_handler.
  5845. **/
  5846. void
  5847. lpfc_mbox_timeout(unsigned long ptr)
  5848. {
  5849. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5850. unsigned long iflag;
  5851. uint32_t tmo_posted;
  5852. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5853. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5854. if (!tmo_posted)
  5855. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5856. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5857. if (!tmo_posted)
  5858. lpfc_worker_wake_up(phba);
  5859. return;
  5860. }
  5861. /**
  5862. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5863. * @phba: Pointer to HBA context object.
  5864. *
  5865. * This function is called from worker thread when a mailbox command times out.
  5866. * The caller is not required to hold any locks. This function will reset the
  5867. * HBA and recover all the pending commands.
  5868. **/
  5869. void
  5870. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5871. {
  5872. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5873. MAILBOX_t *mb = &pmbox->u.mb;
  5874. struct lpfc_sli *psli = &phba->sli;
  5875. struct lpfc_sli_ring *pring;
  5876. /* Check the pmbox pointer first. There is a race condition
  5877. * between the mbox timeout handler getting executed in the
  5878. * worklist and the mailbox actually completing. When this
  5879. * race condition occurs, the mbox_active will be NULL.
  5880. */
  5881. spin_lock_irq(&phba->hbalock);
  5882. if (pmbox == NULL) {
  5883. lpfc_printf_log(phba, KERN_WARNING,
  5884. LOG_MBOX | LOG_SLI,
  5885. "0353 Active Mailbox cleared - mailbox timeout "
  5886. "exiting\n");
  5887. spin_unlock_irq(&phba->hbalock);
  5888. return;
  5889. }
  5890. /* Mbox cmd <mbxCommand> timeout */
  5891. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5892. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  5893. mb->mbxCommand,
  5894. phba->pport->port_state,
  5895. phba->sli.sli_flag,
  5896. phba->sli.mbox_active);
  5897. spin_unlock_irq(&phba->hbalock);
  5898. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  5899. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  5900. * it to fail all outstanding SCSI IO.
  5901. */
  5902. spin_lock_irq(&phba->pport->work_port_lock);
  5903. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  5904. spin_unlock_irq(&phba->pport->work_port_lock);
  5905. spin_lock_irq(&phba->hbalock);
  5906. phba->link_state = LPFC_LINK_UNKNOWN;
  5907. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  5908. spin_unlock_irq(&phba->hbalock);
  5909. pring = &psli->ring[psli->fcp_ring];
  5910. lpfc_sli_abort_iocb_ring(phba, pring);
  5911. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5912. "0345 Resetting board due to mailbox timeout\n");
  5913. /* Reset the HBA device */
  5914. lpfc_reset_hba(phba);
  5915. }
  5916. /**
  5917. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  5918. * @phba: Pointer to HBA context object.
  5919. * @pmbox: Pointer to mailbox object.
  5920. * @flag: Flag indicating how the mailbox need to be processed.
  5921. *
  5922. * This function is called by discovery code and HBA management code
  5923. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  5924. * function gets the hbalock to protect the data structures.
  5925. * The mailbox command can be submitted in polling mode, in which case
  5926. * this function will wait in a polling loop for the completion of the
  5927. * mailbox.
  5928. * If the mailbox is submitted in no_wait mode (not polling) the
  5929. * function will submit the command and returns immediately without waiting
  5930. * for the mailbox completion. The no_wait is supported only when HBA
  5931. * is in SLI2/SLI3 mode - interrupts are enabled.
  5932. * The SLI interface allows only one mailbox pending at a time. If the
  5933. * mailbox is issued in polling mode and there is already a mailbox
  5934. * pending, then the function will return an error. If the mailbox is issued
  5935. * in NO_WAIT mode and there is a mailbox pending already, the function
  5936. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  5937. * The sli layer owns the mailbox object until the completion of mailbox
  5938. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  5939. * return codes the caller owns the mailbox command after the return of
  5940. * the function.
  5941. **/
  5942. static int
  5943. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  5944. uint32_t flag)
  5945. {
  5946. MAILBOX_t *mb;
  5947. struct lpfc_sli *psli = &phba->sli;
  5948. uint32_t status, evtctr;
  5949. uint32_t ha_copy, hc_copy;
  5950. int i;
  5951. unsigned long timeout;
  5952. unsigned long drvr_flag = 0;
  5953. uint32_t word0, ldata;
  5954. void __iomem *to_slim;
  5955. int processing_queue = 0;
  5956. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  5957. if (!pmbox) {
  5958. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5959. /* processing mbox queue from intr_handler */
  5960. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5961. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5962. return MBX_SUCCESS;
  5963. }
  5964. processing_queue = 1;
  5965. pmbox = lpfc_mbox_get(phba);
  5966. if (!pmbox) {
  5967. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5968. return MBX_SUCCESS;
  5969. }
  5970. }
  5971. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  5972. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  5973. if(!pmbox->vport) {
  5974. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5975. lpfc_printf_log(phba, KERN_ERR,
  5976. LOG_MBOX | LOG_VPORT,
  5977. "1806 Mbox x%x failed. No vport\n",
  5978. pmbox->u.mb.mbxCommand);
  5979. dump_stack();
  5980. goto out_not_finished;
  5981. }
  5982. }
  5983. /* If the PCI channel is in offline state, do not post mbox. */
  5984. if (unlikely(pci_channel_offline(phba->pcidev))) {
  5985. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5986. goto out_not_finished;
  5987. }
  5988. /* If HBA has a deferred error attention, fail the iocb. */
  5989. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  5990. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5991. goto out_not_finished;
  5992. }
  5993. psli = &phba->sli;
  5994. mb = &pmbox->u.mb;
  5995. status = MBX_SUCCESS;
  5996. if (phba->link_state == LPFC_HBA_ERROR) {
  5997. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5998. /* Mbox command <mbxCommand> cannot issue */
  5999. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6000. "(%d):0311 Mailbox command x%x cannot "
  6001. "issue Data: x%x x%x\n",
  6002. pmbox->vport ? pmbox->vport->vpi : 0,
  6003. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6004. goto out_not_finished;
  6005. }
  6006. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6007. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6008. !(hc_copy & HC_MBINT_ENA)) {
  6009. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6010. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6011. "(%d):2528 Mailbox command x%x cannot "
  6012. "issue Data: x%x x%x\n",
  6013. pmbox->vport ? pmbox->vport->vpi : 0,
  6014. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6015. goto out_not_finished;
  6016. }
  6017. }
  6018. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6019. /* Polling for a mbox command when another one is already active
  6020. * is not allowed in SLI. Also, the driver must have established
  6021. * SLI2 mode to queue and process multiple mbox commands.
  6022. */
  6023. if (flag & MBX_POLL) {
  6024. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6025. /* Mbox command <mbxCommand> cannot issue */
  6026. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6027. "(%d):2529 Mailbox command x%x "
  6028. "cannot issue Data: x%x x%x\n",
  6029. pmbox->vport ? pmbox->vport->vpi : 0,
  6030. pmbox->u.mb.mbxCommand,
  6031. psli->sli_flag, flag);
  6032. goto out_not_finished;
  6033. }
  6034. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6035. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6036. /* Mbox command <mbxCommand> cannot issue */
  6037. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6038. "(%d):2530 Mailbox command x%x "
  6039. "cannot issue Data: x%x x%x\n",
  6040. pmbox->vport ? pmbox->vport->vpi : 0,
  6041. pmbox->u.mb.mbxCommand,
  6042. psli->sli_flag, flag);
  6043. goto out_not_finished;
  6044. }
  6045. /* Another mailbox command is still being processed, queue this
  6046. * command to be processed later.
  6047. */
  6048. lpfc_mbox_put(phba, pmbox);
  6049. /* Mbox cmd issue - BUSY */
  6050. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6051. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6052. "x%x x%x x%x x%x\n",
  6053. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6054. mb->mbxCommand, phba->pport->port_state,
  6055. psli->sli_flag, flag);
  6056. psli->slistat.mbox_busy++;
  6057. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6058. if (pmbox->vport) {
  6059. lpfc_debugfs_disc_trc(pmbox->vport,
  6060. LPFC_DISC_TRC_MBOX_VPORT,
  6061. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6062. (uint32_t)mb->mbxCommand,
  6063. mb->un.varWords[0], mb->un.varWords[1]);
  6064. }
  6065. else {
  6066. lpfc_debugfs_disc_trc(phba->pport,
  6067. LPFC_DISC_TRC_MBOX,
  6068. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6069. (uint32_t)mb->mbxCommand,
  6070. mb->un.varWords[0], mb->un.varWords[1]);
  6071. }
  6072. return MBX_BUSY;
  6073. }
  6074. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6075. /* If we are not polling, we MUST be in SLI2 mode */
  6076. if (flag != MBX_POLL) {
  6077. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6078. (mb->mbxCommand != MBX_KILL_BOARD)) {
  6079. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6080. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6081. /* Mbox command <mbxCommand> cannot issue */
  6082. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6083. "(%d):2531 Mailbox command x%x "
  6084. "cannot issue Data: x%x x%x\n",
  6085. pmbox->vport ? pmbox->vport->vpi : 0,
  6086. pmbox->u.mb.mbxCommand,
  6087. psli->sli_flag, flag);
  6088. goto out_not_finished;
  6089. }
  6090. /* timeout active mbox command */
  6091. mod_timer(&psli->mbox_tmo, (jiffies +
  6092. (HZ * lpfc_mbox_tmo_val(phba, pmbox))));
  6093. }
  6094. /* Mailbox cmd <cmd> issue */
  6095. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6096. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6097. "x%x\n",
  6098. pmbox->vport ? pmbox->vport->vpi : 0,
  6099. mb->mbxCommand, phba->pport->port_state,
  6100. psli->sli_flag, flag);
  6101. if (mb->mbxCommand != MBX_HEARTBEAT) {
  6102. if (pmbox->vport) {
  6103. lpfc_debugfs_disc_trc(pmbox->vport,
  6104. LPFC_DISC_TRC_MBOX_VPORT,
  6105. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6106. (uint32_t)mb->mbxCommand,
  6107. mb->un.varWords[0], mb->un.varWords[1]);
  6108. }
  6109. else {
  6110. lpfc_debugfs_disc_trc(phba->pport,
  6111. LPFC_DISC_TRC_MBOX,
  6112. "MBOX Send: cmd:x%x mb:x%x x%x",
  6113. (uint32_t)mb->mbxCommand,
  6114. mb->un.varWords[0], mb->un.varWords[1]);
  6115. }
  6116. }
  6117. psli->slistat.mbox_cmd++;
  6118. evtctr = psli->slistat.mbox_event;
  6119. /* next set own bit for the adapter and copy over command word */
  6120. mb->mbxOwner = OWN_CHIP;
  6121. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6122. /* Populate mbox extension offset word. */
  6123. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6124. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6125. = (uint8_t *)phba->mbox_ext
  6126. - (uint8_t *)phba->mbox;
  6127. }
  6128. /* Copy the mailbox extension data */
  6129. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6130. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6131. (uint8_t *)phba->mbox_ext,
  6132. pmbox->in_ext_byte_len);
  6133. }
  6134. /* Copy command data to host SLIM area */
  6135. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6136. } else {
  6137. /* Populate mbox extension offset word. */
  6138. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6139. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6140. = MAILBOX_HBA_EXT_OFFSET;
  6141. /* Copy the mailbox extension data */
  6142. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6143. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6144. MAILBOX_HBA_EXT_OFFSET,
  6145. pmbox->context2, pmbox->in_ext_byte_len);
  6146. }
  6147. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6148. /* copy command data into host mbox for cmpl */
  6149. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6150. }
  6151. /* First copy mbox command data to HBA SLIM, skip past first
  6152. word */
  6153. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6154. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  6155. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6156. /* Next copy over first word, with mbxOwner set */
  6157. ldata = *((uint32_t *)mb);
  6158. to_slim = phba->MBslimaddr;
  6159. writel(ldata, to_slim);
  6160. readl(to_slim); /* flush */
  6161. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6162. /* switch over to host mailbox */
  6163. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6164. }
  6165. }
  6166. wmb();
  6167. switch (flag) {
  6168. case MBX_NOWAIT:
  6169. /* Set up reference to mailbox command */
  6170. psli->mbox_active = pmbox;
  6171. /* Interrupt board to do it */
  6172. writel(CA_MBATT, phba->CAregaddr);
  6173. readl(phba->CAregaddr); /* flush */
  6174. /* Don't wait for it to finish, just return */
  6175. break;
  6176. case MBX_POLL:
  6177. /* Set up null reference to mailbox command */
  6178. psli->mbox_active = NULL;
  6179. /* Interrupt board to do it */
  6180. writel(CA_MBATT, phba->CAregaddr);
  6181. readl(phba->CAregaddr); /* flush */
  6182. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6183. /* First read mbox status word */
  6184. word0 = *((uint32_t *)phba->mbox);
  6185. word0 = le32_to_cpu(word0);
  6186. } else {
  6187. /* First read mbox status word */
  6188. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6189. spin_unlock_irqrestore(&phba->hbalock,
  6190. drvr_flag);
  6191. goto out_not_finished;
  6192. }
  6193. }
  6194. /* Read the HBA Host Attention Register */
  6195. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6196. spin_unlock_irqrestore(&phba->hbalock,
  6197. drvr_flag);
  6198. goto out_not_finished;
  6199. }
  6200. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6201. 1000) + jiffies;
  6202. i = 0;
  6203. /* Wait for command to complete */
  6204. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6205. (!(ha_copy & HA_MBATT) &&
  6206. (phba->link_state > LPFC_WARM_START))) {
  6207. if (time_after(jiffies, timeout)) {
  6208. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6209. spin_unlock_irqrestore(&phba->hbalock,
  6210. drvr_flag);
  6211. goto out_not_finished;
  6212. }
  6213. /* Check if we took a mbox interrupt while we were
  6214. polling */
  6215. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6216. && (evtctr != psli->slistat.mbox_event))
  6217. break;
  6218. if (i++ > 10) {
  6219. spin_unlock_irqrestore(&phba->hbalock,
  6220. drvr_flag);
  6221. msleep(1);
  6222. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6223. }
  6224. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6225. /* First copy command data */
  6226. word0 = *((uint32_t *)phba->mbox);
  6227. word0 = le32_to_cpu(word0);
  6228. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6229. MAILBOX_t *slimmb;
  6230. uint32_t slimword0;
  6231. /* Check real SLIM for any errors */
  6232. slimword0 = readl(phba->MBslimaddr);
  6233. slimmb = (MAILBOX_t *) & slimword0;
  6234. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6235. && slimmb->mbxStatus) {
  6236. psli->sli_flag &=
  6237. ~LPFC_SLI_ACTIVE;
  6238. word0 = slimword0;
  6239. }
  6240. }
  6241. } else {
  6242. /* First copy command data */
  6243. word0 = readl(phba->MBslimaddr);
  6244. }
  6245. /* Read the HBA Host Attention Register */
  6246. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6247. spin_unlock_irqrestore(&phba->hbalock,
  6248. drvr_flag);
  6249. goto out_not_finished;
  6250. }
  6251. }
  6252. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6253. /* copy results back to user */
  6254. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  6255. /* Copy the mailbox extension data */
  6256. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6257. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6258. pmbox->context2,
  6259. pmbox->out_ext_byte_len);
  6260. }
  6261. } else {
  6262. /* First copy command data */
  6263. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  6264. MAILBOX_CMD_SIZE);
  6265. /* Copy the mailbox extension data */
  6266. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6267. lpfc_memcpy_from_slim(pmbox->context2,
  6268. phba->MBslimaddr +
  6269. MAILBOX_HBA_EXT_OFFSET,
  6270. pmbox->out_ext_byte_len);
  6271. }
  6272. }
  6273. writel(HA_MBATT, phba->HAregaddr);
  6274. readl(phba->HAregaddr); /* flush */
  6275. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6276. status = mb->mbxStatus;
  6277. }
  6278. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6279. return status;
  6280. out_not_finished:
  6281. if (processing_queue) {
  6282. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6283. lpfc_mbox_cmpl_put(phba, pmbox);
  6284. }
  6285. return MBX_NOT_FINISHED;
  6286. }
  6287. /**
  6288. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6289. * @phba: Pointer to HBA context object.
  6290. *
  6291. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6292. * the driver internal pending mailbox queue. It will then try to wait out the
  6293. * possible outstanding mailbox command before return.
  6294. *
  6295. * Returns:
  6296. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6297. * the outstanding mailbox command timed out.
  6298. **/
  6299. static int
  6300. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6301. {
  6302. struct lpfc_sli *psli = &phba->sli;
  6303. int rc = 0;
  6304. unsigned long timeout = 0;
  6305. /* Mark the asynchronous mailbox command posting as blocked */
  6306. spin_lock_irq(&phba->hbalock);
  6307. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6308. /* Determine how long we might wait for the active mailbox
  6309. * command to be gracefully completed by firmware.
  6310. */
  6311. if (phba->sli.mbox_active)
  6312. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6313. phba->sli.mbox_active) *
  6314. 1000) + jiffies;
  6315. spin_unlock_irq(&phba->hbalock);
  6316. /* Wait for the outstnading mailbox command to complete */
  6317. while (phba->sli.mbox_active) {
  6318. /* Check active mailbox complete status every 2ms */
  6319. msleep(2);
  6320. if (time_after(jiffies, timeout)) {
  6321. /* Timeout, marked the outstanding cmd not complete */
  6322. rc = 1;
  6323. break;
  6324. }
  6325. }
  6326. /* Can not cleanly block async mailbox command, fails it */
  6327. if (rc) {
  6328. spin_lock_irq(&phba->hbalock);
  6329. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6330. spin_unlock_irq(&phba->hbalock);
  6331. }
  6332. return rc;
  6333. }
  6334. /**
  6335. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6336. * @phba: Pointer to HBA context object.
  6337. *
  6338. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6339. * commands from the driver internal pending mailbox queue. It makes sure
  6340. * that there is no outstanding mailbox command before resuming posting
  6341. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6342. * mailbox command, it will try to wait it out before resuming asynchronous
  6343. * mailbox command posting.
  6344. **/
  6345. static void
  6346. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6347. {
  6348. struct lpfc_sli *psli = &phba->sli;
  6349. spin_lock_irq(&phba->hbalock);
  6350. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6351. /* Asynchronous mailbox posting is not blocked, do nothing */
  6352. spin_unlock_irq(&phba->hbalock);
  6353. return;
  6354. }
  6355. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6356. * successful or timeout, after timing-out the outstanding mailbox
  6357. * command shall always be removed, so just unblock posting async
  6358. * mailbox command and resume
  6359. */
  6360. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6361. spin_unlock_irq(&phba->hbalock);
  6362. /* wake up worker thread to post asynchronlous mailbox command */
  6363. lpfc_worker_wake_up(phba);
  6364. }
  6365. /**
  6366. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6367. * @phba: Pointer to HBA context object.
  6368. * @mboxq: Pointer to mailbox object.
  6369. *
  6370. * The function posts a mailbox to the port. The mailbox is expected
  6371. * to be comletely filled in and ready for the port to operate on it.
  6372. * This routine executes a synchronous completion operation on the
  6373. * mailbox by polling for its completion.
  6374. *
  6375. * The caller must not be holding any locks when calling this routine.
  6376. *
  6377. * Returns:
  6378. * MBX_SUCCESS - mailbox posted successfully
  6379. * Any of the MBX error values.
  6380. **/
  6381. static int
  6382. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6383. {
  6384. int rc = MBX_SUCCESS;
  6385. unsigned long iflag;
  6386. uint32_t db_ready;
  6387. uint32_t mcqe_status;
  6388. uint32_t mbx_cmnd;
  6389. unsigned long timeout;
  6390. struct lpfc_sli *psli = &phba->sli;
  6391. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6392. struct lpfc_bmbx_create *mbox_rgn;
  6393. struct dma_address *dma_address;
  6394. struct lpfc_register bmbx_reg;
  6395. /*
  6396. * Only one mailbox can be active to the bootstrap mailbox region
  6397. * at a time and there is no queueing provided.
  6398. */
  6399. spin_lock_irqsave(&phba->hbalock, iflag);
  6400. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6401. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6402. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6403. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6404. "cannot issue Data: x%x x%x\n",
  6405. mboxq->vport ? mboxq->vport->vpi : 0,
  6406. mboxq->u.mb.mbxCommand,
  6407. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6408. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6409. psli->sli_flag, MBX_POLL);
  6410. return MBXERR_ERROR;
  6411. }
  6412. /* The server grabs the token and owns it until release */
  6413. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6414. phba->sli.mbox_active = mboxq;
  6415. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6416. /*
  6417. * Initialize the bootstrap memory region to avoid stale data areas
  6418. * in the mailbox post. Then copy the caller's mailbox contents to
  6419. * the bmbx mailbox region.
  6420. */
  6421. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6422. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6423. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6424. sizeof(struct lpfc_mqe));
  6425. /* Post the high mailbox dma address to the port and wait for ready. */
  6426. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6427. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6428. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6429. * 1000) + jiffies;
  6430. do {
  6431. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6432. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6433. if (!db_ready)
  6434. msleep(2);
  6435. if (time_after(jiffies, timeout)) {
  6436. rc = MBXERR_ERROR;
  6437. goto exit;
  6438. }
  6439. } while (!db_ready);
  6440. /* Post the low mailbox dma address to the port. */
  6441. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6442. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6443. * 1000) + jiffies;
  6444. do {
  6445. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6446. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6447. if (!db_ready)
  6448. msleep(2);
  6449. if (time_after(jiffies, timeout)) {
  6450. rc = MBXERR_ERROR;
  6451. goto exit;
  6452. }
  6453. } while (!db_ready);
  6454. /*
  6455. * Read the CQ to ensure the mailbox has completed.
  6456. * If so, update the mailbox status so that the upper layers
  6457. * can complete the request normally.
  6458. */
  6459. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6460. sizeof(struct lpfc_mqe));
  6461. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6462. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6463. sizeof(struct lpfc_mcqe));
  6464. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6465. /*
  6466. * When the CQE status indicates a failure and the mailbox status
  6467. * indicates success then copy the CQE status into the mailbox status
  6468. * (and prefix it with x4000).
  6469. */
  6470. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6471. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6472. bf_set(lpfc_mqe_status, mb,
  6473. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6474. rc = MBXERR_ERROR;
  6475. } else
  6476. lpfc_sli4_swap_str(phba, mboxq);
  6477. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6478. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6479. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6480. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6481. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6482. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6483. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6484. bf_get(lpfc_mqe_status, mb),
  6485. mb->un.mb_words[0], mb->un.mb_words[1],
  6486. mb->un.mb_words[2], mb->un.mb_words[3],
  6487. mb->un.mb_words[4], mb->un.mb_words[5],
  6488. mb->un.mb_words[6], mb->un.mb_words[7],
  6489. mb->un.mb_words[8], mb->un.mb_words[9],
  6490. mb->un.mb_words[10], mb->un.mb_words[11],
  6491. mb->un.mb_words[12], mboxq->mcqe.word0,
  6492. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6493. mboxq->mcqe.trailer);
  6494. exit:
  6495. /* We are holding the token, no needed for lock when release */
  6496. spin_lock_irqsave(&phba->hbalock, iflag);
  6497. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6498. phba->sli.mbox_active = NULL;
  6499. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6500. return rc;
  6501. }
  6502. /**
  6503. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6504. * @phba: Pointer to HBA context object.
  6505. * @pmbox: Pointer to mailbox object.
  6506. * @flag: Flag indicating how the mailbox need to be processed.
  6507. *
  6508. * This function is called by discovery code and HBA management code to submit
  6509. * a mailbox command to firmware with SLI-4 interface spec.
  6510. *
  6511. * Return codes the caller owns the mailbox command after the return of the
  6512. * function.
  6513. **/
  6514. static int
  6515. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6516. uint32_t flag)
  6517. {
  6518. struct lpfc_sli *psli = &phba->sli;
  6519. unsigned long iflags;
  6520. int rc;
  6521. /* dump from issue mailbox command if setup */
  6522. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6523. rc = lpfc_mbox_dev_check(phba);
  6524. if (unlikely(rc)) {
  6525. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6526. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6527. "cannot issue Data: x%x x%x\n",
  6528. mboxq->vport ? mboxq->vport->vpi : 0,
  6529. mboxq->u.mb.mbxCommand,
  6530. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6531. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6532. psli->sli_flag, flag);
  6533. goto out_not_finished;
  6534. }
  6535. /* Detect polling mode and jump to a handler */
  6536. if (!phba->sli4_hba.intr_enable) {
  6537. if (flag == MBX_POLL)
  6538. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6539. else
  6540. rc = -EIO;
  6541. if (rc != MBX_SUCCESS)
  6542. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6543. "(%d):2541 Mailbox command x%x "
  6544. "(x%x/x%x) failure: "
  6545. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6546. "Data: x%x x%x\n,",
  6547. mboxq->vport ? mboxq->vport->vpi : 0,
  6548. mboxq->u.mb.mbxCommand,
  6549. lpfc_sli_config_mbox_subsys_get(phba,
  6550. mboxq),
  6551. lpfc_sli_config_mbox_opcode_get(phba,
  6552. mboxq),
  6553. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6554. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6555. bf_get(lpfc_mcqe_ext_status,
  6556. &mboxq->mcqe),
  6557. psli->sli_flag, flag);
  6558. return rc;
  6559. } else if (flag == MBX_POLL) {
  6560. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6561. "(%d):2542 Try to issue mailbox command "
  6562. "x%x (x%x/x%x) synchronously ahead of async"
  6563. "mailbox command queue: x%x x%x\n",
  6564. mboxq->vport ? mboxq->vport->vpi : 0,
  6565. mboxq->u.mb.mbxCommand,
  6566. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6567. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6568. psli->sli_flag, flag);
  6569. /* Try to block the asynchronous mailbox posting */
  6570. rc = lpfc_sli4_async_mbox_block(phba);
  6571. if (!rc) {
  6572. /* Successfully blocked, now issue sync mbox cmd */
  6573. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6574. if (rc != MBX_SUCCESS)
  6575. lpfc_printf_log(phba, KERN_WARNING,
  6576. LOG_MBOX | LOG_SLI,
  6577. "(%d):2597 Sync Mailbox command "
  6578. "x%x (x%x/x%x) failure: "
  6579. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6580. "Data: x%x x%x\n,",
  6581. mboxq->vport ? mboxq->vport->vpi : 0,
  6582. mboxq->u.mb.mbxCommand,
  6583. lpfc_sli_config_mbox_subsys_get(phba,
  6584. mboxq),
  6585. lpfc_sli_config_mbox_opcode_get(phba,
  6586. mboxq),
  6587. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6588. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6589. bf_get(lpfc_mcqe_ext_status,
  6590. &mboxq->mcqe),
  6591. psli->sli_flag, flag);
  6592. /* Unblock the async mailbox posting afterward */
  6593. lpfc_sli4_async_mbox_unblock(phba);
  6594. }
  6595. return rc;
  6596. }
  6597. /* Now, interrupt mode asynchrous mailbox command */
  6598. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6599. if (rc) {
  6600. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6601. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6602. "cannot issue Data: x%x x%x\n",
  6603. mboxq->vport ? mboxq->vport->vpi : 0,
  6604. mboxq->u.mb.mbxCommand,
  6605. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6606. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6607. psli->sli_flag, flag);
  6608. goto out_not_finished;
  6609. }
  6610. /* Put the mailbox command to the driver internal FIFO */
  6611. psli->slistat.mbox_busy++;
  6612. spin_lock_irqsave(&phba->hbalock, iflags);
  6613. lpfc_mbox_put(phba, mboxq);
  6614. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6615. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6616. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6617. "x%x (x%x/x%x) x%x x%x x%x\n",
  6618. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6619. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6620. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6621. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6622. phba->pport->port_state,
  6623. psli->sli_flag, MBX_NOWAIT);
  6624. /* Wake up worker thread to transport mailbox command from head */
  6625. lpfc_worker_wake_up(phba);
  6626. return MBX_BUSY;
  6627. out_not_finished:
  6628. return MBX_NOT_FINISHED;
  6629. }
  6630. /**
  6631. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6632. * @phba: Pointer to HBA context object.
  6633. *
  6634. * This function is called by worker thread to send a mailbox command to
  6635. * SLI4 HBA firmware.
  6636. *
  6637. **/
  6638. int
  6639. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6640. {
  6641. struct lpfc_sli *psli = &phba->sli;
  6642. LPFC_MBOXQ_t *mboxq;
  6643. int rc = MBX_SUCCESS;
  6644. unsigned long iflags;
  6645. struct lpfc_mqe *mqe;
  6646. uint32_t mbx_cmnd;
  6647. /* Check interrupt mode before post async mailbox command */
  6648. if (unlikely(!phba->sli4_hba.intr_enable))
  6649. return MBX_NOT_FINISHED;
  6650. /* Check for mailbox command service token */
  6651. spin_lock_irqsave(&phba->hbalock, iflags);
  6652. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6653. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6654. return MBX_NOT_FINISHED;
  6655. }
  6656. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6657. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6658. return MBX_NOT_FINISHED;
  6659. }
  6660. if (unlikely(phba->sli.mbox_active)) {
  6661. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6662. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6663. "0384 There is pending active mailbox cmd\n");
  6664. return MBX_NOT_FINISHED;
  6665. }
  6666. /* Take the mailbox command service token */
  6667. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6668. /* Get the next mailbox command from head of queue */
  6669. mboxq = lpfc_mbox_get(phba);
  6670. /* If no more mailbox command waiting for post, we're done */
  6671. if (!mboxq) {
  6672. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6673. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6674. return MBX_SUCCESS;
  6675. }
  6676. phba->sli.mbox_active = mboxq;
  6677. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6678. /* Check device readiness for posting mailbox command */
  6679. rc = lpfc_mbox_dev_check(phba);
  6680. if (unlikely(rc))
  6681. /* Driver clean routine will clean up pending mailbox */
  6682. goto out_not_finished;
  6683. /* Prepare the mbox command to be posted */
  6684. mqe = &mboxq->u.mqe;
  6685. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6686. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6687. mod_timer(&psli->mbox_tmo, (jiffies +
  6688. (HZ * lpfc_mbox_tmo_val(phba, mboxq))));
  6689. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6690. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6691. "x%x x%x\n",
  6692. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6693. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6694. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6695. phba->pport->port_state, psli->sli_flag);
  6696. if (mbx_cmnd != MBX_HEARTBEAT) {
  6697. if (mboxq->vport) {
  6698. lpfc_debugfs_disc_trc(mboxq->vport,
  6699. LPFC_DISC_TRC_MBOX_VPORT,
  6700. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6701. mbx_cmnd, mqe->un.mb_words[0],
  6702. mqe->un.mb_words[1]);
  6703. } else {
  6704. lpfc_debugfs_disc_trc(phba->pport,
  6705. LPFC_DISC_TRC_MBOX,
  6706. "MBOX Send: cmd:x%x mb:x%x x%x",
  6707. mbx_cmnd, mqe->un.mb_words[0],
  6708. mqe->un.mb_words[1]);
  6709. }
  6710. }
  6711. psli->slistat.mbox_cmd++;
  6712. /* Post the mailbox command to the port */
  6713. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6714. if (rc != MBX_SUCCESS) {
  6715. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6716. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6717. "cannot issue Data: x%x x%x\n",
  6718. mboxq->vport ? mboxq->vport->vpi : 0,
  6719. mboxq->u.mb.mbxCommand,
  6720. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6721. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6722. psli->sli_flag, MBX_NOWAIT);
  6723. goto out_not_finished;
  6724. }
  6725. return rc;
  6726. out_not_finished:
  6727. spin_lock_irqsave(&phba->hbalock, iflags);
  6728. if (phba->sli.mbox_active) {
  6729. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6730. __lpfc_mbox_cmpl_put(phba, mboxq);
  6731. /* Release the token */
  6732. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6733. phba->sli.mbox_active = NULL;
  6734. }
  6735. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6736. return MBX_NOT_FINISHED;
  6737. }
  6738. /**
  6739. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6740. * @phba: Pointer to HBA context object.
  6741. * @pmbox: Pointer to mailbox object.
  6742. * @flag: Flag indicating how the mailbox need to be processed.
  6743. *
  6744. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6745. * the API jump table function pointer from the lpfc_hba struct.
  6746. *
  6747. * Return codes the caller owns the mailbox command after the return of the
  6748. * function.
  6749. **/
  6750. int
  6751. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6752. {
  6753. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6754. }
  6755. /**
  6756. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6757. * @phba: The hba struct for which this call is being executed.
  6758. * @dev_grp: The HBA PCI-Device group number.
  6759. *
  6760. * This routine sets up the mbox interface API function jump table in @phba
  6761. * struct.
  6762. * Returns: 0 - success, -ENODEV - failure.
  6763. **/
  6764. int
  6765. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6766. {
  6767. switch (dev_grp) {
  6768. case LPFC_PCI_DEV_LP:
  6769. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6770. phba->lpfc_sli_handle_slow_ring_event =
  6771. lpfc_sli_handle_slow_ring_event_s3;
  6772. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6773. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6774. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6775. break;
  6776. case LPFC_PCI_DEV_OC:
  6777. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6778. phba->lpfc_sli_handle_slow_ring_event =
  6779. lpfc_sli_handle_slow_ring_event_s4;
  6780. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6781. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6782. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6783. break;
  6784. default:
  6785. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6786. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6787. dev_grp);
  6788. return -ENODEV;
  6789. break;
  6790. }
  6791. return 0;
  6792. }
  6793. /**
  6794. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6795. * @phba: Pointer to HBA context object.
  6796. * @pring: Pointer to driver SLI ring object.
  6797. * @piocb: Pointer to address of newly added command iocb.
  6798. *
  6799. * This function is called with hbalock held to add a command
  6800. * iocb to the txq when SLI layer cannot submit the command iocb
  6801. * to the ring.
  6802. **/
  6803. void
  6804. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6805. struct lpfc_iocbq *piocb)
  6806. {
  6807. /* Insert the caller's iocb in the txq tail for later processing. */
  6808. list_add_tail(&piocb->list, &pring->txq);
  6809. pring->txq_cnt++;
  6810. }
  6811. /**
  6812. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6813. * @phba: Pointer to HBA context object.
  6814. * @pring: Pointer to driver SLI ring object.
  6815. * @piocb: Pointer to address of newly added command iocb.
  6816. *
  6817. * This function is called with hbalock held before a new
  6818. * iocb is submitted to the firmware. This function checks
  6819. * txq to flush the iocbs in txq to Firmware before
  6820. * submitting new iocbs to the Firmware.
  6821. * If there are iocbs in the txq which need to be submitted
  6822. * to firmware, lpfc_sli_next_iocb returns the first element
  6823. * of the txq after dequeuing it from txq.
  6824. * If there is no iocb in the txq then the function will return
  6825. * *piocb and *piocb is set to NULL. Caller needs to check
  6826. * *piocb to find if there are more commands in the txq.
  6827. **/
  6828. static struct lpfc_iocbq *
  6829. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6830. struct lpfc_iocbq **piocb)
  6831. {
  6832. struct lpfc_iocbq * nextiocb;
  6833. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6834. if (!nextiocb) {
  6835. nextiocb = *piocb;
  6836. *piocb = NULL;
  6837. }
  6838. return nextiocb;
  6839. }
  6840. /**
  6841. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6842. * @phba: Pointer to HBA context object.
  6843. * @ring_number: SLI ring number to issue iocb on.
  6844. * @piocb: Pointer to command iocb.
  6845. * @flag: Flag indicating if this command can be put into txq.
  6846. *
  6847. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6848. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6849. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6850. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6851. * this function allows only iocbs for posting buffers. This function finds
  6852. * next available slot in the command ring and posts the command to the
  6853. * available slot and writes the port attention register to request HBA start
  6854. * processing new iocb. If there is no slot available in the ring and
  6855. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6856. * the function returns IOCB_BUSY.
  6857. *
  6858. * This function is called with hbalock held. The function will return success
  6859. * after it successfully submit the iocb to firmware or after adding to the
  6860. * txq.
  6861. **/
  6862. static int
  6863. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6864. struct lpfc_iocbq *piocb, uint32_t flag)
  6865. {
  6866. struct lpfc_iocbq *nextiocb;
  6867. IOCB_t *iocb;
  6868. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6869. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6870. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6871. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6872. lpfc_printf_log(phba, KERN_ERR,
  6873. LOG_SLI | LOG_VPORT,
  6874. "1807 IOCB x%x failed. No vport\n",
  6875. piocb->iocb.ulpCommand);
  6876. dump_stack();
  6877. return IOCB_ERROR;
  6878. }
  6879. /* If the PCI channel is in offline state, do not post iocbs. */
  6880. if (unlikely(pci_channel_offline(phba->pcidev)))
  6881. return IOCB_ERROR;
  6882. /* If HBA has a deferred error attention, fail the iocb. */
  6883. if (unlikely(phba->hba_flag & DEFER_ERATT))
  6884. return IOCB_ERROR;
  6885. /*
  6886. * We should never get an IOCB if we are in a < LINK_DOWN state
  6887. */
  6888. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  6889. return IOCB_ERROR;
  6890. /*
  6891. * Check to see if we are blocking IOCB processing because of a
  6892. * outstanding event.
  6893. */
  6894. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  6895. goto iocb_busy;
  6896. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  6897. /*
  6898. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  6899. * can be issued if the link is not up.
  6900. */
  6901. switch (piocb->iocb.ulpCommand) {
  6902. case CMD_GEN_REQUEST64_CR:
  6903. case CMD_GEN_REQUEST64_CX:
  6904. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  6905. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  6906. FC_RCTL_DD_UNSOL_CMD) ||
  6907. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  6908. MENLO_TRANSPORT_TYPE))
  6909. goto iocb_busy;
  6910. break;
  6911. case CMD_QUE_RING_BUF_CN:
  6912. case CMD_QUE_RING_BUF64_CN:
  6913. /*
  6914. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  6915. * completion, iocb_cmpl MUST be 0.
  6916. */
  6917. if (piocb->iocb_cmpl)
  6918. piocb->iocb_cmpl = NULL;
  6919. /*FALLTHROUGH*/
  6920. case CMD_CREATE_XRI_CR:
  6921. case CMD_CLOSE_XRI_CN:
  6922. case CMD_CLOSE_XRI_CX:
  6923. break;
  6924. default:
  6925. goto iocb_busy;
  6926. }
  6927. /*
  6928. * For FCP commands, we must be in a state where we can process link
  6929. * attention events.
  6930. */
  6931. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  6932. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  6933. goto iocb_busy;
  6934. }
  6935. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  6936. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  6937. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  6938. if (iocb)
  6939. lpfc_sli_update_ring(phba, pring);
  6940. else
  6941. lpfc_sli_update_full_ring(phba, pring);
  6942. if (!piocb)
  6943. return IOCB_SUCCESS;
  6944. goto out_busy;
  6945. iocb_busy:
  6946. pring->stats.iocb_cmd_delay++;
  6947. out_busy:
  6948. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6949. __lpfc_sli_ringtx_put(phba, pring, piocb);
  6950. return IOCB_SUCCESS;
  6951. }
  6952. return IOCB_BUSY;
  6953. }
  6954. /**
  6955. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  6956. * @phba: Pointer to HBA context object.
  6957. * @piocb: Pointer to command iocb.
  6958. * @sglq: Pointer to the scatter gather queue object.
  6959. *
  6960. * This routine converts the bpl or bde that is in the IOCB
  6961. * to a sgl list for the sli4 hardware. The physical address
  6962. * of the bpl/bde is converted back to a virtual address.
  6963. * If the IOCB contains a BPL then the list of BDE's is
  6964. * converted to sli4_sge's. If the IOCB contains a single
  6965. * BDE then it is converted to a single sli_sge.
  6966. * The IOCB is still in cpu endianess so the contents of
  6967. * the bpl can be used without byte swapping.
  6968. *
  6969. * Returns valid XRI = Success, NO_XRI = Failure.
  6970. **/
  6971. static uint16_t
  6972. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  6973. struct lpfc_sglq *sglq)
  6974. {
  6975. uint16_t xritag = NO_XRI;
  6976. struct ulp_bde64 *bpl = NULL;
  6977. struct ulp_bde64 bde;
  6978. struct sli4_sge *sgl = NULL;
  6979. struct lpfc_dmabuf *dmabuf;
  6980. IOCB_t *icmd;
  6981. int numBdes = 0;
  6982. int i = 0;
  6983. uint32_t offset = 0; /* accumulated offset in the sg request list */
  6984. int inbound = 0; /* number of sg reply entries inbound from firmware */
  6985. if (!piocbq || !sglq)
  6986. return xritag;
  6987. sgl = (struct sli4_sge *)sglq->sgl;
  6988. icmd = &piocbq->iocb;
  6989. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  6990. return sglq->sli4_xritag;
  6991. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  6992. numBdes = icmd->un.genreq64.bdl.bdeSize /
  6993. sizeof(struct ulp_bde64);
  6994. /* The addrHigh and addrLow fields within the IOCB
  6995. * have not been byteswapped yet so there is no
  6996. * need to swap them back.
  6997. */
  6998. if (piocbq->context3)
  6999. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7000. else
  7001. return xritag;
  7002. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7003. if (!bpl)
  7004. return xritag;
  7005. for (i = 0; i < numBdes; i++) {
  7006. /* Should already be byte swapped. */
  7007. sgl->addr_hi = bpl->addrHigh;
  7008. sgl->addr_lo = bpl->addrLow;
  7009. sgl->word2 = le32_to_cpu(sgl->word2);
  7010. if ((i+1) == numBdes)
  7011. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7012. else
  7013. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7014. /* swap the size field back to the cpu so we
  7015. * can assign it to the sgl.
  7016. */
  7017. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7018. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7019. /* The offsets in the sgl need to be accumulated
  7020. * separately for the request and reply lists.
  7021. * The request is always first, the reply follows.
  7022. */
  7023. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7024. /* add up the reply sg entries */
  7025. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7026. inbound++;
  7027. /* first inbound? reset the offset */
  7028. if (inbound == 1)
  7029. offset = 0;
  7030. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7031. bf_set(lpfc_sli4_sge_type, sgl,
  7032. LPFC_SGE_TYPE_DATA);
  7033. offset += bde.tus.f.bdeSize;
  7034. }
  7035. sgl->word2 = cpu_to_le32(sgl->word2);
  7036. bpl++;
  7037. sgl++;
  7038. }
  7039. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7040. /* The addrHigh and addrLow fields of the BDE have not
  7041. * been byteswapped yet so they need to be swapped
  7042. * before putting them in the sgl.
  7043. */
  7044. sgl->addr_hi =
  7045. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7046. sgl->addr_lo =
  7047. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7048. sgl->word2 = le32_to_cpu(sgl->word2);
  7049. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7050. sgl->word2 = cpu_to_le32(sgl->word2);
  7051. sgl->sge_len =
  7052. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7053. }
  7054. return sglq->sli4_xritag;
  7055. }
  7056. /**
  7057. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  7058. * @phba: Pointer to HBA context object.
  7059. *
  7060. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  7061. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  7062. * held.
  7063. *
  7064. * Return: index into SLI4 fast-path FCP queue index.
  7065. **/
  7066. static uint32_t
  7067. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  7068. {
  7069. ++phba->fcp_qidx;
  7070. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  7071. phba->fcp_qidx = 0;
  7072. return phba->fcp_qidx;
  7073. }
  7074. /**
  7075. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7076. * @phba: Pointer to HBA context object.
  7077. * @piocb: Pointer to command iocb.
  7078. * @wqe: Pointer to the work queue entry.
  7079. *
  7080. * This routine converts the iocb command to its Work Queue Entry
  7081. * equivalent. The wqe pointer should not have any fields set when
  7082. * this routine is called because it will memcpy over them.
  7083. * This routine does not set the CQ_ID or the WQEC bits in the
  7084. * wqe.
  7085. *
  7086. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7087. **/
  7088. static int
  7089. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7090. union lpfc_wqe *wqe)
  7091. {
  7092. uint32_t xmit_len = 0, total_len = 0;
  7093. uint8_t ct = 0;
  7094. uint32_t fip;
  7095. uint32_t abort_tag;
  7096. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7097. uint8_t cmnd;
  7098. uint16_t xritag;
  7099. uint16_t abrt_iotag;
  7100. struct lpfc_iocbq *abrtiocbq;
  7101. struct ulp_bde64 *bpl = NULL;
  7102. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7103. int numBdes, i;
  7104. struct ulp_bde64 bde;
  7105. struct lpfc_nodelist *ndlp;
  7106. uint32_t *pcmd;
  7107. uint32_t if_type;
  7108. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7109. /* The fcp commands will set command type */
  7110. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7111. command_type = FCP_COMMAND;
  7112. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7113. command_type = ELS_COMMAND_FIP;
  7114. else
  7115. command_type = ELS_COMMAND_NON_FIP;
  7116. /* Some of the fields are in the right position already */
  7117. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7118. abort_tag = (uint32_t) iocbq->iotag;
  7119. xritag = iocbq->sli4_xritag;
  7120. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7121. /* words0-2 bpl convert bde */
  7122. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7123. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7124. sizeof(struct ulp_bde64);
  7125. bpl = (struct ulp_bde64 *)
  7126. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7127. if (!bpl)
  7128. return IOCB_ERROR;
  7129. /* Should already be byte swapped. */
  7130. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7131. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7132. /* swap the size field back to the cpu so we
  7133. * can assign it to the sgl.
  7134. */
  7135. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7136. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7137. total_len = 0;
  7138. for (i = 0; i < numBdes; i++) {
  7139. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7140. total_len += bde.tus.f.bdeSize;
  7141. }
  7142. } else
  7143. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7144. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7145. cmnd = iocbq->iocb.ulpCommand;
  7146. switch (iocbq->iocb.ulpCommand) {
  7147. case CMD_ELS_REQUEST64_CR:
  7148. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7149. ndlp = iocbq->context_un.ndlp;
  7150. else
  7151. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7152. if (!iocbq->iocb.ulpLe) {
  7153. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7154. "2007 Only Limited Edition cmd Format"
  7155. " supported 0x%x\n",
  7156. iocbq->iocb.ulpCommand);
  7157. return IOCB_ERROR;
  7158. }
  7159. wqe->els_req.payload_len = xmit_len;
  7160. /* Els_reguest64 has a TMO */
  7161. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7162. iocbq->iocb.ulpTimeout);
  7163. /* Need a VF for word 4 set the vf bit*/
  7164. bf_set(els_req64_vf, &wqe->els_req, 0);
  7165. /* And a VFID for word 12 */
  7166. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7167. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7168. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7169. iocbq->iocb.ulpContext);
  7170. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7171. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7172. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7173. if (command_type == ELS_COMMAND_FIP)
  7174. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7175. >> LPFC_FIP_ELS_ID_SHIFT);
  7176. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7177. iocbq->context2)->virt);
  7178. if_type = bf_get(lpfc_sli_intf_if_type,
  7179. &phba->sli4_hba.sli_intf);
  7180. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7181. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7182. *pcmd == ELS_CMD_SCR ||
  7183. *pcmd == ELS_CMD_FDISC ||
  7184. *pcmd == ELS_CMD_LOGO ||
  7185. *pcmd == ELS_CMD_PLOGI)) {
  7186. bf_set(els_req64_sp, &wqe->els_req, 1);
  7187. bf_set(els_req64_sid, &wqe->els_req,
  7188. iocbq->vport->fc_myDID);
  7189. if ((*pcmd == ELS_CMD_FLOGI) &&
  7190. !(phba->fc_topology ==
  7191. LPFC_TOPOLOGY_LOOP))
  7192. bf_set(els_req64_sid, &wqe->els_req, 0);
  7193. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7194. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7195. phba->vpi_ids[iocbq->vport->vpi]);
  7196. } else if (pcmd && iocbq->context1) {
  7197. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7198. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7199. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7200. }
  7201. }
  7202. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7203. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7204. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7205. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7206. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7207. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7208. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7209. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7210. break;
  7211. case CMD_XMIT_SEQUENCE64_CX:
  7212. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7213. iocbq->iocb.un.ulpWord[3]);
  7214. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7215. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7216. /* The entire sequence is transmitted for this IOCB */
  7217. xmit_len = total_len;
  7218. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7219. if (phba->link_flag & LS_LOOPBACK_MODE)
  7220. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7221. case CMD_XMIT_SEQUENCE64_CR:
  7222. /* word3 iocb=io_tag32 wqe=reserved */
  7223. wqe->xmit_sequence.rsvd3 = 0;
  7224. /* word4 relative_offset memcpy */
  7225. /* word5 r_ctl/df_ctl memcpy */
  7226. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7227. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7228. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7229. LPFC_WQE_IOD_WRITE);
  7230. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7231. LPFC_WQE_LENLOC_WORD12);
  7232. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7233. wqe->xmit_sequence.xmit_len = xmit_len;
  7234. command_type = OTHER_COMMAND;
  7235. break;
  7236. case CMD_XMIT_BCAST64_CN:
  7237. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7238. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7239. /* word4 iocb=rsvd wqe=rsvd */
  7240. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7241. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7242. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7243. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7244. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7245. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7246. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7247. LPFC_WQE_LENLOC_WORD3);
  7248. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7249. break;
  7250. case CMD_FCP_IWRITE64_CR:
  7251. command_type = FCP_COMMAND_DATA_OUT;
  7252. /* word3 iocb=iotag wqe=payload_offset_len */
  7253. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7254. wqe->fcp_iwrite.payload_offset_len =
  7255. xmit_len + sizeof(struct fcp_rsp);
  7256. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7257. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7258. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7259. iocbq->iocb.ulpFCP2Rcvy);
  7260. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7261. /* Always open the exchange */
  7262. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7263. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7264. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7265. LPFC_WQE_LENLOC_WORD4);
  7266. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7267. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7268. if (iocbq->iocb_flag & LPFC_IO_DIF) {
  7269. iocbq->iocb_flag &= ~LPFC_IO_DIF;
  7270. bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
  7271. }
  7272. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7273. break;
  7274. case CMD_FCP_IREAD64_CR:
  7275. /* word3 iocb=iotag wqe=payload_offset_len */
  7276. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7277. wqe->fcp_iread.payload_offset_len =
  7278. xmit_len + sizeof(struct fcp_rsp);
  7279. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7280. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7281. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7282. iocbq->iocb.ulpFCP2Rcvy);
  7283. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7284. /* Always open the exchange */
  7285. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7286. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7287. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7288. LPFC_WQE_LENLOC_WORD4);
  7289. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7290. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7291. if (iocbq->iocb_flag & LPFC_IO_DIF) {
  7292. iocbq->iocb_flag &= ~LPFC_IO_DIF;
  7293. bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
  7294. }
  7295. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7296. break;
  7297. case CMD_FCP_ICMND64_CR:
  7298. /* word3 iocb=IO_TAG wqe=reserved */
  7299. wqe->fcp_icmd.rsrvd3 = 0;
  7300. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7301. /* Always open the exchange */
  7302. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7303. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7304. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7305. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7306. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7307. LPFC_WQE_LENLOC_NONE);
  7308. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7309. break;
  7310. case CMD_GEN_REQUEST64_CR:
  7311. /* For this command calculate the xmit length of the
  7312. * request bde.
  7313. */
  7314. xmit_len = 0;
  7315. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7316. sizeof(struct ulp_bde64);
  7317. for (i = 0; i < numBdes; i++) {
  7318. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7319. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7320. break;
  7321. xmit_len += bde.tus.f.bdeSize;
  7322. }
  7323. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7324. wqe->gen_req.request_payload_len = xmit_len;
  7325. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7326. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7327. /* word6 context tag copied in memcpy */
  7328. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7329. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7330. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7331. "2015 Invalid CT %x command 0x%x\n",
  7332. ct, iocbq->iocb.ulpCommand);
  7333. return IOCB_ERROR;
  7334. }
  7335. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7336. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7337. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7338. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7339. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7340. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7341. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7342. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7343. command_type = OTHER_COMMAND;
  7344. break;
  7345. case CMD_XMIT_ELS_RSP64_CX:
  7346. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7347. /* words0-2 BDE memcpy */
  7348. /* word3 iocb=iotag32 wqe=response_payload_len */
  7349. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7350. /* word4 */
  7351. wqe->xmit_els_rsp.word4 = 0;
  7352. /* word5 iocb=rsvd wge=did */
  7353. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7354. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7355. if_type = bf_get(lpfc_sli_intf_if_type,
  7356. &phba->sli4_hba.sli_intf);
  7357. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7358. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7359. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7360. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7361. iocbq->vport->fc_myDID);
  7362. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7363. bf_set(wqe_els_did,
  7364. &wqe->xmit_els_rsp.wqe_dest, 0);
  7365. }
  7366. }
  7367. }
  7368. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7369. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7370. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7371. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7372. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7373. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7374. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7375. phba->vpi_ids[iocbq->vport->vpi]);
  7376. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7377. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7378. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7379. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7380. LPFC_WQE_LENLOC_WORD3);
  7381. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7382. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7383. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7384. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7385. iocbq->context2)->virt);
  7386. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7387. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7388. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7389. iocbq->vport->fc_myDID);
  7390. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7391. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7392. phba->vpi_ids[phba->pport->vpi]);
  7393. }
  7394. command_type = OTHER_COMMAND;
  7395. break;
  7396. case CMD_CLOSE_XRI_CN:
  7397. case CMD_ABORT_XRI_CN:
  7398. case CMD_ABORT_XRI_CX:
  7399. /* words 0-2 memcpy should be 0 rserved */
  7400. /* port will send abts */
  7401. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7402. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7403. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7404. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7405. } else
  7406. fip = 0;
  7407. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7408. /*
  7409. * The link is down, or the command was ELS_FIP
  7410. * so the fw does not need to send abts
  7411. * on the wire.
  7412. */
  7413. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7414. else
  7415. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7416. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7417. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7418. wqe->abort_cmd.rsrvd5 = 0;
  7419. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7420. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7421. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7422. /*
  7423. * The abort handler will send us CMD_ABORT_XRI_CN or
  7424. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7425. */
  7426. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7427. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7428. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7429. LPFC_WQE_LENLOC_NONE);
  7430. cmnd = CMD_ABORT_XRI_CX;
  7431. command_type = OTHER_COMMAND;
  7432. xritag = 0;
  7433. break;
  7434. case CMD_XMIT_BLS_RSP64_CX:
  7435. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7436. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7437. * we re-construct this WQE here based on information in
  7438. * iocbq from scratch.
  7439. */
  7440. memset(wqe, 0, sizeof(union lpfc_wqe));
  7441. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7442. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7443. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7444. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7445. LPFC_ABTS_UNSOL_INT) {
  7446. /* ABTS sent by initiator to CT exchange, the
  7447. * RX_ID field will be filled with the newly
  7448. * allocated responder XRI.
  7449. */
  7450. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7451. iocbq->sli4_xritag);
  7452. } else {
  7453. /* ABTS sent by responder to CT exchange, the
  7454. * RX_ID field will be filled with the responder
  7455. * RX_ID from ABTS.
  7456. */
  7457. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7458. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7459. }
  7460. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7461. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7462. /* Use CT=VPI */
  7463. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7464. ndlp->nlp_DID);
  7465. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7466. iocbq->iocb.ulpContext);
  7467. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7468. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7469. phba->vpi_ids[phba->pport->vpi]);
  7470. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7471. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7472. LPFC_WQE_LENLOC_NONE);
  7473. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7474. command_type = OTHER_COMMAND;
  7475. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7476. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7477. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7478. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7479. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7480. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7481. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7482. }
  7483. break;
  7484. case CMD_XRI_ABORTED_CX:
  7485. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7486. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7487. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7488. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7489. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7490. default:
  7491. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7492. "2014 Invalid command 0x%x\n",
  7493. iocbq->iocb.ulpCommand);
  7494. return IOCB_ERROR;
  7495. break;
  7496. }
  7497. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7498. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7499. wqe->generic.wqe_com.abort_tag = abort_tag;
  7500. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7501. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7502. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7503. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7504. return 0;
  7505. }
  7506. /**
  7507. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7508. * @phba: Pointer to HBA context object.
  7509. * @ring_number: SLI ring number to issue iocb on.
  7510. * @piocb: Pointer to command iocb.
  7511. * @flag: Flag indicating if this command can be put into txq.
  7512. *
  7513. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7514. * an iocb command to an HBA with SLI-4 interface spec.
  7515. *
  7516. * This function is called with hbalock held. The function will return success
  7517. * after it successfully submit the iocb to firmware or after adding to the
  7518. * txq.
  7519. **/
  7520. static int
  7521. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7522. struct lpfc_iocbq *piocb, uint32_t flag)
  7523. {
  7524. struct lpfc_sglq *sglq;
  7525. union lpfc_wqe wqe;
  7526. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7527. if (piocb->sli4_xritag == NO_XRI) {
  7528. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7529. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7530. sglq = NULL;
  7531. else {
  7532. if (pring->txq_cnt) {
  7533. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7534. __lpfc_sli_ringtx_put(phba,
  7535. pring, piocb);
  7536. return IOCB_SUCCESS;
  7537. } else {
  7538. return IOCB_BUSY;
  7539. }
  7540. } else {
  7541. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7542. if (!sglq) {
  7543. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7544. __lpfc_sli_ringtx_put(phba,
  7545. pring,
  7546. piocb);
  7547. return IOCB_SUCCESS;
  7548. } else
  7549. return IOCB_BUSY;
  7550. }
  7551. }
  7552. }
  7553. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7554. /* These IO's already have an XRI and a mapped sgl. */
  7555. sglq = NULL;
  7556. } else {
  7557. /*
  7558. * This is a continuation of a commandi,(CX) so this
  7559. * sglq is on the active list
  7560. */
  7561. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  7562. if (!sglq)
  7563. return IOCB_ERROR;
  7564. }
  7565. if (sglq) {
  7566. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7567. piocb->sli4_xritag = sglq->sli4_xritag;
  7568. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7569. return IOCB_ERROR;
  7570. }
  7571. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7572. return IOCB_ERROR;
  7573. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7574. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7575. /*
  7576. * For FCP command IOCB, get a new WQ index to distribute
  7577. * WQE across the WQsr. On the other hand, for abort IOCB,
  7578. * it carries the same WQ index to the original command
  7579. * IOCB.
  7580. */
  7581. if (piocb->iocb_flag & LPFC_IO_FCP)
  7582. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7583. if (unlikely(!phba->sli4_hba.fcp_wq))
  7584. return IOCB_ERROR;
  7585. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7586. &wqe))
  7587. return IOCB_ERROR;
  7588. } else {
  7589. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7590. return IOCB_ERROR;
  7591. }
  7592. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7593. return 0;
  7594. }
  7595. /**
  7596. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7597. *
  7598. * This routine wraps the actual lockless version for issusing IOCB function
  7599. * pointer from the lpfc_hba struct.
  7600. *
  7601. * Return codes:
  7602. * IOCB_ERROR - Error
  7603. * IOCB_SUCCESS - Success
  7604. * IOCB_BUSY - Busy
  7605. **/
  7606. int
  7607. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7608. struct lpfc_iocbq *piocb, uint32_t flag)
  7609. {
  7610. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7611. }
  7612. /**
  7613. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7614. * @phba: The hba struct for which this call is being executed.
  7615. * @dev_grp: The HBA PCI-Device group number.
  7616. *
  7617. * This routine sets up the SLI interface API function jump table in @phba
  7618. * struct.
  7619. * Returns: 0 - success, -ENODEV - failure.
  7620. **/
  7621. int
  7622. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7623. {
  7624. switch (dev_grp) {
  7625. case LPFC_PCI_DEV_LP:
  7626. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7627. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7628. break;
  7629. case LPFC_PCI_DEV_OC:
  7630. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7631. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7632. break;
  7633. default:
  7634. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7635. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7636. dev_grp);
  7637. return -ENODEV;
  7638. break;
  7639. }
  7640. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7641. return 0;
  7642. }
  7643. /**
  7644. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7645. * @phba: Pointer to HBA context object.
  7646. * @pring: Pointer to driver SLI ring object.
  7647. * @piocb: Pointer to command iocb.
  7648. * @flag: Flag indicating if this command can be put into txq.
  7649. *
  7650. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7651. * function. This function gets the hbalock and calls
  7652. * __lpfc_sli_issue_iocb function and will return the error returned
  7653. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7654. * functions which do not hold hbalock.
  7655. **/
  7656. int
  7657. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7658. struct lpfc_iocbq *piocb, uint32_t flag)
  7659. {
  7660. unsigned long iflags;
  7661. int rc;
  7662. spin_lock_irqsave(&phba->hbalock, iflags);
  7663. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7664. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7665. return rc;
  7666. }
  7667. /**
  7668. * lpfc_extra_ring_setup - Extra ring setup function
  7669. * @phba: Pointer to HBA context object.
  7670. *
  7671. * This function is called while driver attaches with the
  7672. * HBA to setup the extra ring. The extra ring is used
  7673. * only when driver needs to support target mode functionality
  7674. * or IP over FC functionalities.
  7675. *
  7676. * This function is called with no lock held.
  7677. **/
  7678. static int
  7679. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7680. {
  7681. struct lpfc_sli *psli;
  7682. struct lpfc_sli_ring *pring;
  7683. psli = &phba->sli;
  7684. /* Adjust cmd/rsp ring iocb entries more evenly */
  7685. /* Take some away from the FCP ring */
  7686. pring = &psli->ring[psli->fcp_ring];
  7687. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7688. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7689. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7690. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7691. /* and give them to the extra ring */
  7692. pring = &psli->ring[psli->extra_ring];
  7693. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7694. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7695. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7696. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7697. /* Setup default profile for this ring */
  7698. pring->iotag_max = 4096;
  7699. pring->num_mask = 1;
  7700. pring->prt[0].profile = 0; /* Mask 0 */
  7701. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7702. pring->prt[0].type = phba->cfg_multi_ring_type;
  7703. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7704. return 0;
  7705. }
  7706. /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
  7707. * @vport: pointer to virtual port object.
  7708. * @ndlp: nodelist pointer for the impacted rport.
  7709. *
  7710. * The driver calls this routine in response to a XRI ABORT CQE
  7711. * event from the port. In this event, the driver is required to
  7712. * recover its login to the rport even though its login may be valid
  7713. * from the driver's perspective. The failed ABTS notice from the
  7714. * port indicates the rport is not responding.
  7715. */
  7716. static void
  7717. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  7718. struct lpfc_nodelist *ndlp)
  7719. {
  7720. struct Scsi_Host *shost;
  7721. struct lpfc_hba *phba;
  7722. unsigned long flags = 0;
  7723. shost = lpfc_shost_from_vport(vport);
  7724. phba = vport->phba;
  7725. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  7726. lpfc_printf_log(phba, KERN_INFO,
  7727. LOG_SLI, "3093 No rport recovery needed. "
  7728. "rport in state 0x%x\n",
  7729. ndlp->nlp_state);
  7730. return;
  7731. }
  7732. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7733. "3094 Start rport recovery on shost id 0x%x "
  7734. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  7735. "flags 0x%x\n",
  7736. shost->host_no, ndlp->nlp_DID,
  7737. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  7738. ndlp->nlp_flag);
  7739. /*
  7740. * The rport is not responding. Don't attempt ADISC recovery.
  7741. * Remove the FCP-2 flag to force a PLOGI.
  7742. */
  7743. spin_lock_irqsave(shost->host_lock, flags);
  7744. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  7745. spin_unlock_irqrestore(shost->host_lock, flags);
  7746. lpfc_disc_state_machine(vport, ndlp, NULL,
  7747. NLP_EVT_DEVICE_RECOVERY);
  7748. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  7749. spin_lock_irqsave(shost->host_lock, flags);
  7750. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  7751. spin_unlock_irqrestore(shost->host_lock, flags);
  7752. lpfc_disc_start(vport);
  7753. }
  7754. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7755. * @phba: Pointer to HBA context object.
  7756. * @iocbq: Pointer to iocb object.
  7757. *
  7758. * The async_event handler calls this routine when it receives
  7759. * an ASYNC_STATUS_CN event from the port. The port generates
  7760. * this event when an Abort Sequence request to an rport fails
  7761. * twice in succession. The abort could be originated by the
  7762. * driver or by the port. The ABTS could have been for an ELS
  7763. * or FCP IO. The port only generates this event when an ABTS
  7764. * fails to complete after one retry.
  7765. */
  7766. static void
  7767. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7768. struct lpfc_iocbq *iocbq)
  7769. {
  7770. struct lpfc_nodelist *ndlp = NULL;
  7771. uint16_t rpi = 0, vpi = 0;
  7772. struct lpfc_vport *vport = NULL;
  7773. /* The rpi in the ulpContext is vport-sensitive. */
  7774. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7775. rpi = iocbq->iocb.ulpContext;
  7776. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7777. "3092 Port generated ABTS async event "
  7778. "on vpi %d rpi %d status 0x%x\n",
  7779. vpi, rpi, iocbq->iocb.ulpStatus);
  7780. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7781. if (!vport)
  7782. goto err_exit;
  7783. ndlp = lpfc_findnode_rpi(vport, rpi);
  7784. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7785. goto err_exit;
  7786. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7787. lpfc_sli_abts_recover_port(vport, ndlp);
  7788. return;
  7789. err_exit:
  7790. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7791. "3095 Event Context not found, no "
  7792. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7793. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7794. vpi, rpi);
  7795. }
  7796. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7797. * @phba: pointer to HBA context object.
  7798. * @ndlp: nodelist pointer for the impacted rport.
  7799. * @axri: pointer to the wcqe containing the failed exchange.
  7800. *
  7801. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7802. * port. The port generates this event when an abort exchange request to an
  7803. * rport fails twice in succession with no reply. The abort could be originated
  7804. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7805. */
  7806. void
  7807. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7808. struct lpfc_nodelist *ndlp,
  7809. struct sli4_wcqe_xri_aborted *axri)
  7810. {
  7811. struct lpfc_vport *vport;
  7812. uint32_t ext_status = 0;
  7813. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  7814. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7815. "3115 Node Context not found, driver "
  7816. "ignoring abts err event\n");
  7817. return;
  7818. }
  7819. vport = ndlp->vport;
  7820. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7821. "3116 Port generated FCP XRI ABORT event on "
  7822. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  7823. ndlp->vport->vpi, ndlp->nlp_rpi,
  7824. bf_get(lpfc_wcqe_xa_xri, axri),
  7825. bf_get(lpfc_wcqe_xa_status, axri),
  7826. axri->parameter);
  7827. /*
  7828. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  7829. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  7830. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  7831. */
  7832. ext_status = axri->parameter & WCQE_PARAM_MASK;
  7833. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  7834. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  7835. lpfc_sli_abts_recover_port(vport, ndlp);
  7836. }
  7837. /**
  7838. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7839. * @phba: Pointer to HBA context object.
  7840. * @pring: Pointer to driver SLI ring object.
  7841. * @iocbq: Pointer to iocb object.
  7842. *
  7843. * This function is called by the slow ring event handler
  7844. * function when there is an ASYNC event iocb in the ring.
  7845. * This function is called with no lock held.
  7846. * Currently this function handles only temperature related
  7847. * ASYNC events. The function decodes the temperature sensor
  7848. * event message and posts events for the management applications.
  7849. **/
  7850. static void
  7851. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7852. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7853. {
  7854. IOCB_t *icmd;
  7855. uint16_t evt_code;
  7856. struct temp_event temp_event_data;
  7857. struct Scsi_Host *shost;
  7858. uint32_t *iocb_w;
  7859. icmd = &iocbq->iocb;
  7860. evt_code = icmd->un.asyncstat.evt_code;
  7861. switch (evt_code) {
  7862. case ASYNC_TEMP_WARN:
  7863. case ASYNC_TEMP_SAFE:
  7864. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7865. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7866. if (evt_code == ASYNC_TEMP_WARN) {
  7867. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7868. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7869. "0347 Adapter is very hot, please take "
  7870. "corrective action. temperature : %d Celsius\n",
  7871. (uint32_t) icmd->ulpContext);
  7872. } else {
  7873. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7874. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7875. "0340 Adapter temperature is OK now. "
  7876. "temperature : %d Celsius\n",
  7877. (uint32_t) icmd->ulpContext);
  7878. }
  7879. /* Send temperature change event to applications */
  7880. shost = lpfc_shost_from_vport(phba->pport);
  7881. fc_host_post_vendor_event(shost, fc_get_event_number(),
  7882. sizeof(temp_event_data), (char *) &temp_event_data,
  7883. LPFC_NL_VENDOR_ID);
  7884. break;
  7885. case ASYNC_STATUS_CN:
  7886. lpfc_sli_abts_err_handler(phba, iocbq);
  7887. break;
  7888. default:
  7889. iocb_w = (uint32_t *) icmd;
  7890. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7891. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  7892. " evt_code 0x%x\n"
  7893. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  7894. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  7895. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  7896. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  7897. pring->ringno, icmd->un.asyncstat.evt_code,
  7898. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  7899. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  7900. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  7901. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  7902. break;
  7903. }
  7904. }
  7905. /**
  7906. * lpfc_sli_setup - SLI ring setup function
  7907. * @phba: Pointer to HBA context object.
  7908. *
  7909. * lpfc_sli_setup sets up rings of the SLI interface with
  7910. * number of iocbs per ring and iotags. This function is
  7911. * called while driver attach to the HBA and before the
  7912. * interrupts are enabled. So there is no need for locking.
  7913. *
  7914. * This function always returns 0.
  7915. **/
  7916. int
  7917. lpfc_sli_setup(struct lpfc_hba *phba)
  7918. {
  7919. int i, totiocbsize = 0;
  7920. struct lpfc_sli *psli = &phba->sli;
  7921. struct lpfc_sli_ring *pring;
  7922. psli->num_rings = MAX_CONFIGURED_RINGS;
  7923. psli->sli_flag = 0;
  7924. psli->fcp_ring = LPFC_FCP_RING;
  7925. psli->next_ring = LPFC_FCP_NEXT_RING;
  7926. psli->extra_ring = LPFC_EXTRA_RING;
  7927. psli->iocbq_lookup = NULL;
  7928. psli->iocbq_lookup_len = 0;
  7929. psli->last_iotag = 0;
  7930. for (i = 0; i < psli->num_rings; i++) {
  7931. pring = &psli->ring[i];
  7932. switch (i) {
  7933. case LPFC_FCP_RING: /* ring 0 - FCP */
  7934. /* numCiocb and numRiocb are used in config_port */
  7935. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  7936. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  7937. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7938. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7939. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7940. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7941. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7942. SLI3_IOCB_CMD_SIZE :
  7943. SLI2_IOCB_CMD_SIZE;
  7944. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7945. SLI3_IOCB_RSP_SIZE :
  7946. SLI2_IOCB_RSP_SIZE;
  7947. pring->iotag_ctr = 0;
  7948. pring->iotag_max =
  7949. (phba->cfg_hba_queue_depth * 2);
  7950. pring->fast_iotag = pring->iotag_max;
  7951. pring->num_mask = 0;
  7952. break;
  7953. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  7954. /* numCiocb and numRiocb are used in config_port */
  7955. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  7956. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  7957. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7958. SLI3_IOCB_CMD_SIZE :
  7959. SLI2_IOCB_CMD_SIZE;
  7960. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7961. SLI3_IOCB_RSP_SIZE :
  7962. SLI2_IOCB_RSP_SIZE;
  7963. pring->iotag_max = phba->cfg_hba_queue_depth;
  7964. pring->num_mask = 0;
  7965. break;
  7966. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  7967. /* numCiocb and numRiocb are used in config_port */
  7968. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  7969. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  7970. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7971. SLI3_IOCB_CMD_SIZE :
  7972. SLI2_IOCB_CMD_SIZE;
  7973. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7974. SLI3_IOCB_RSP_SIZE :
  7975. SLI2_IOCB_RSP_SIZE;
  7976. pring->fast_iotag = 0;
  7977. pring->iotag_ctr = 0;
  7978. pring->iotag_max = 4096;
  7979. pring->lpfc_sli_rcv_async_status =
  7980. lpfc_sli_async_event_handler;
  7981. pring->num_mask = LPFC_MAX_RING_MASK;
  7982. pring->prt[0].profile = 0; /* Mask 0 */
  7983. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  7984. pring->prt[0].type = FC_TYPE_ELS;
  7985. pring->prt[0].lpfc_sli_rcv_unsol_event =
  7986. lpfc_els_unsol_event;
  7987. pring->prt[1].profile = 0; /* Mask 1 */
  7988. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  7989. pring->prt[1].type = FC_TYPE_ELS;
  7990. pring->prt[1].lpfc_sli_rcv_unsol_event =
  7991. lpfc_els_unsol_event;
  7992. pring->prt[2].profile = 0; /* Mask 2 */
  7993. /* NameServer Inquiry */
  7994. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  7995. /* NameServer */
  7996. pring->prt[2].type = FC_TYPE_CT;
  7997. pring->prt[2].lpfc_sli_rcv_unsol_event =
  7998. lpfc_ct_unsol_event;
  7999. pring->prt[3].profile = 0; /* Mask 3 */
  8000. /* NameServer response */
  8001. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8002. /* NameServer */
  8003. pring->prt[3].type = FC_TYPE_CT;
  8004. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8005. lpfc_ct_unsol_event;
  8006. /* abort unsolicited sequence */
  8007. pring->prt[4].profile = 0; /* Mask 4 */
  8008. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  8009. pring->prt[4].type = FC_TYPE_BLS;
  8010. pring->prt[4].lpfc_sli_rcv_unsol_event =
  8011. lpfc_sli4_ct_abort_unsol_event;
  8012. break;
  8013. }
  8014. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  8015. (pring->numRiocb * pring->sizeRiocb);
  8016. }
  8017. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8018. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8019. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8020. "SLI2 SLIM Data: x%x x%lx\n",
  8021. phba->brd_no, totiocbsize,
  8022. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8023. }
  8024. if (phba->cfg_multi_ring_support == 2)
  8025. lpfc_extra_ring_setup(phba);
  8026. return 0;
  8027. }
  8028. /**
  8029. * lpfc_sli_queue_setup - Queue initialization function
  8030. * @phba: Pointer to HBA context object.
  8031. *
  8032. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8033. * ring. This function also initializes ring indices of each ring.
  8034. * This function is called during the initialization of the SLI
  8035. * interface of an HBA.
  8036. * This function is called with no lock held and always returns
  8037. * 1.
  8038. **/
  8039. int
  8040. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8041. {
  8042. struct lpfc_sli *psli;
  8043. struct lpfc_sli_ring *pring;
  8044. int i;
  8045. psli = &phba->sli;
  8046. spin_lock_irq(&phba->hbalock);
  8047. INIT_LIST_HEAD(&psli->mboxq);
  8048. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8049. /* Initialize list headers for txq and txcmplq as double linked lists */
  8050. for (i = 0; i < psli->num_rings; i++) {
  8051. pring = &psli->ring[i];
  8052. pring->ringno = i;
  8053. pring->next_cmdidx = 0;
  8054. pring->local_getidx = 0;
  8055. pring->cmdidx = 0;
  8056. INIT_LIST_HEAD(&pring->txq);
  8057. INIT_LIST_HEAD(&pring->txcmplq);
  8058. INIT_LIST_HEAD(&pring->iocb_continueq);
  8059. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8060. INIT_LIST_HEAD(&pring->postbufq);
  8061. }
  8062. spin_unlock_irq(&phba->hbalock);
  8063. return 1;
  8064. }
  8065. /**
  8066. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8067. * @phba: Pointer to HBA context object.
  8068. *
  8069. * This routine flushes the mailbox command subsystem. It will unconditionally
  8070. * flush all the mailbox commands in the three possible stages in the mailbox
  8071. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8072. * command; and completed mailbox command queue. It is caller's responsibility
  8073. * to make sure that the driver is in the proper state to flush the mailbox
  8074. * command sub-system. Namely, the posting of mailbox commands into the
  8075. * pending mailbox command queue from the various clients must be stopped;
  8076. * either the HBA is in a state that it will never works on the outstanding
  8077. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8078. * mailbox command has been completed.
  8079. **/
  8080. static void
  8081. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8082. {
  8083. LIST_HEAD(completions);
  8084. struct lpfc_sli *psli = &phba->sli;
  8085. LPFC_MBOXQ_t *pmb;
  8086. unsigned long iflag;
  8087. /* Flush all the mailbox commands in the mbox system */
  8088. spin_lock_irqsave(&phba->hbalock, iflag);
  8089. /* The pending mailbox command queue */
  8090. list_splice_init(&phba->sli.mboxq, &completions);
  8091. /* The outstanding active mailbox command */
  8092. if (psli->mbox_active) {
  8093. list_add_tail(&psli->mbox_active->list, &completions);
  8094. psli->mbox_active = NULL;
  8095. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8096. }
  8097. /* The completed mailbox command queue */
  8098. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8099. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8100. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8101. while (!list_empty(&completions)) {
  8102. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8103. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8104. if (pmb->mbox_cmpl)
  8105. pmb->mbox_cmpl(phba, pmb);
  8106. }
  8107. }
  8108. /**
  8109. * lpfc_sli_host_down - Vport cleanup function
  8110. * @vport: Pointer to virtual port object.
  8111. *
  8112. * lpfc_sli_host_down is called to clean up the resources
  8113. * associated with a vport before destroying virtual
  8114. * port data structures.
  8115. * This function does following operations:
  8116. * - Free discovery resources associated with this virtual
  8117. * port.
  8118. * - Free iocbs associated with this virtual port in
  8119. * the txq.
  8120. * - Send abort for all iocb commands associated with this
  8121. * vport in txcmplq.
  8122. *
  8123. * This function is called with no lock held and always returns 1.
  8124. **/
  8125. int
  8126. lpfc_sli_host_down(struct lpfc_vport *vport)
  8127. {
  8128. LIST_HEAD(completions);
  8129. struct lpfc_hba *phba = vport->phba;
  8130. struct lpfc_sli *psli = &phba->sli;
  8131. struct lpfc_sli_ring *pring;
  8132. struct lpfc_iocbq *iocb, *next_iocb;
  8133. int i;
  8134. unsigned long flags = 0;
  8135. uint16_t prev_pring_flag;
  8136. lpfc_cleanup_discovery_resources(vport);
  8137. spin_lock_irqsave(&phba->hbalock, flags);
  8138. for (i = 0; i < psli->num_rings; i++) {
  8139. pring = &psli->ring[i];
  8140. prev_pring_flag = pring->flag;
  8141. /* Only slow rings */
  8142. if (pring->ringno == LPFC_ELS_RING) {
  8143. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8144. /* Set the lpfc data pending flag */
  8145. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8146. }
  8147. /*
  8148. * Error everything on the txq since these iocbs have not been
  8149. * given to the FW yet.
  8150. */
  8151. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8152. if (iocb->vport != vport)
  8153. continue;
  8154. list_move_tail(&iocb->list, &completions);
  8155. pring->txq_cnt--;
  8156. }
  8157. /* Next issue ABTS for everything on the txcmplq */
  8158. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8159. list) {
  8160. if (iocb->vport != vport)
  8161. continue;
  8162. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8163. }
  8164. pring->flag = prev_pring_flag;
  8165. }
  8166. spin_unlock_irqrestore(&phba->hbalock, flags);
  8167. /* Cancel all the IOCBs from the completions list */
  8168. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8169. IOERR_SLI_DOWN);
  8170. return 1;
  8171. }
  8172. /**
  8173. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8174. * @phba: Pointer to HBA context object.
  8175. *
  8176. * This function cleans up all iocb, buffers, mailbox commands
  8177. * while shutting down the HBA. This function is called with no
  8178. * lock held and always returns 1.
  8179. * This function does the following to cleanup driver resources:
  8180. * - Free discovery resources for each virtual port
  8181. * - Cleanup any pending fabric iocbs
  8182. * - Iterate through the iocb txq and free each entry
  8183. * in the list.
  8184. * - Free up any buffer posted to the HBA
  8185. * - Free mailbox commands in the mailbox queue.
  8186. **/
  8187. int
  8188. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8189. {
  8190. LIST_HEAD(completions);
  8191. struct lpfc_sli *psli = &phba->sli;
  8192. struct lpfc_sli_ring *pring;
  8193. struct lpfc_dmabuf *buf_ptr;
  8194. unsigned long flags = 0;
  8195. int i;
  8196. /* Shutdown the mailbox command sub-system */
  8197. lpfc_sli_mbox_sys_shutdown(phba);
  8198. lpfc_hba_down_prep(phba);
  8199. lpfc_fabric_abort_hba(phba);
  8200. spin_lock_irqsave(&phba->hbalock, flags);
  8201. for (i = 0; i < psli->num_rings; i++) {
  8202. pring = &psli->ring[i];
  8203. /* Only slow rings */
  8204. if (pring->ringno == LPFC_ELS_RING) {
  8205. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8206. /* Set the lpfc data pending flag */
  8207. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8208. }
  8209. /*
  8210. * Error everything on the txq since these iocbs have not been
  8211. * given to the FW yet.
  8212. */
  8213. list_splice_init(&pring->txq, &completions);
  8214. pring->txq_cnt = 0;
  8215. }
  8216. spin_unlock_irqrestore(&phba->hbalock, flags);
  8217. /* Cancel all the IOCBs from the completions list */
  8218. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8219. IOERR_SLI_DOWN);
  8220. spin_lock_irqsave(&phba->hbalock, flags);
  8221. list_splice_init(&phba->elsbuf, &completions);
  8222. phba->elsbuf_cnt = 0;
  8223. phba->elsbuf_prev_cnt = 0;
  8224. spin_unlock_irqrestore(&phba->hbalock, flags);
  8225. while (!list_empty(&completions)) {
  8226. list_remove_head(&completions, buf_ptr,
  8227. struct lpfc_dmabuf, list);
  8228. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8229. kfree(buf_ptr);
  8230. }
  8231. /* Return any active mbox cmds */
  8232. del_timer_sync(&psli->mbox_tmo);
  8233. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8234. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8235. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8236. return 1;
  8237. }
  8238. /**
  8239. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8240. * @srcp: Source memory pointer.
  8241. * @destp: Destination memory pointer.
  8242. * @cnt: Number of words required to be copied.
  8243. *
  8244. * This function is used for copying data between driver memory
  8245. * and the SLI memory. This function also changes the endianness
  8246. * of each word if native endianness is different from SLI
  8247. * endianness. This function can be called with or without
  8248. * lock.
  8249. **/
  8250. void
  8251. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8252. {
  8253. uint32_t *src = srcp;
  8254. uint32_t *dest = destp;
  8255. uint32_t ldata;
  8256. int i;
  8257. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8258. ldata = *src;
  8259. ldata = le32_to_cpu(ldata);
  8260. *dest = ldata;
  8261. src++;
  8262. dest++;
  8263. }
  8264. }
  8265. /**
  8266. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8267. * @srcp: Source memory pointer.
  8268. * @destp: Destination memory pointer.
  8269. * @cnt: Number of words required to be copied.
  8270. *
  8271. * This function is used for copying data between a data structure
  8272. * with big endian representation to local endianness.
  8273. * This function can be called with or without lock.
  8274. **/
  8275. void
  8276. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8277. {
  8278. uint32_t *src = srcp;
  8279. uint32_t *dest = destp;
  8280. uint32_t ldata;
  8281. int i;
  8282. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8283. ldata = *src;
  8284. ldata = be32_to_cpu(ldata);
  8285. *dest = ldata;
  8286. src++;
  8287. dest++;
  8288. }
  8289. }
  8290. /**
  8291. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8292. * @phba: Pointer to HBA context object.
  8293. * @pring: Pointer to driver SLI ring object.
  8294. * @mp: Pointer to driver buffer object.
  8295. *
  8296. * This function is called with no lock held.
  8297. * It always return zero after adding the buffer to the postbufq
  8298. * buffer list.
  8299. **/
  8300. int
  8301. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8302. struct lpfc_dmabuf *mp)
  8303. {
  8304. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8305. later */
  8306. spin_lock_irq(&phba->hbalock);
  8307. list_add_tail(&mp->list, &pring->postbufq);
  8308. pring->postbufq_cnt++;
  8309. spin_unlock_irq(&phba->hbalock);
  8310. return 0;
  8311. }
  8312. /**
  8313. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8314. * @phba: Pointer to HBA context object.
  8315. *
  8316. * When HBQ is enabled, buffers are searched based on tags. This function
  8317. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8318. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8319. * does not conflict with tags of buffer posted for unsolicited events.
  8320. * The function returns the allocated tag. The function is called with
  8321. * no locks held.
  8322. **/
  8323. uint32_t
  8324. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8325. {
  8326. spin_lock_irq(&phba->hbalock);
  8327. phba->buffer_tag_count++;
  8328. /*
  8329. * Always set the QUE_BUFTAG_BIT to distiguish between
  8330. * a tag assigned by HBQ.
  8331. */
  8332. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8333. spin_unlock_irq(&phba->hbalock);
  8334. return phba->buffer_tag_count;
  8335. }
  8336. /**
  8337. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8338. * @phba: Pointer to HBA context object.
  8339. * @pring: Pointer to driver SLI ring object.
  8340. * @tag: Buffer tag.
  8341. *
  8342. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8343. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8344. * iocb is posted to the response ring with the tag of the buffer.
  8345. * This function searches the pring->postbufq list using the tag
  8346. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8347. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8348. * buffer is returned to the caller else NULL is returned.
  8349. * This function is called with no lock held.
  8350. **/
  8351. struct lpfc_dmabuf *
  8352. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8353. uint32_t tag)
  8354. {
  8355. struct lpfc_dmabuf *mp, *next_mp;
  8356. struct list_head *slp = &pring->postbufq;
  8357. /* Search postbufq, from the beginning, looking for a match on tag */
  8358. spin_lock_irq(&phba->hbalock);
  8359. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8360. if (mp->buffer_tag == tag) {
  8361. list_del_init(&mp->list);
  8362. pring->postbufq_cnt--;
  8363. spin_unlock_irq(&phba->hbalock);
  8364. return mp;
  8365. }
  8366. }
  8367. spin_unlock_irq(&phba->hbalock);
  8368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8369. "0402 Cannot find virtual addr for buffer tag on "
  8370. "ring %d Data x%lx x%p x%p x%x\n",
  8371. pring->ringno, (unsigned long) tag,
  8372. slp->next, slp->prev, pring->postbufq_cnt);
  8373. return NULL;
  8374. }
  8375. /**
  8376. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8377. * @phba: Pointer to HBA context object.
  8378. * @pring: Pointer to driver SLI ring object.
  8379. * @phys: DMA address of the buffer.
  8380. *
  8381. * This function searches the buffer list using the dma_address
  8382. * of unsolicited event to find the driver's lpfc_dmabuf object
  8383. * corresponding to the dma_address. The function returns the
  8384. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8385. * This function is called by the ct and els unsolicited event
  8386. * handlers to get the buffer associated with the unsolicited
  8387. * event.
  8388. *
  8389. * This function is called with no lock held.
  8390. **/
  8391. struct lpfc_dmabuf *
  8392. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8393. dma_addr_t phys)
  8394. {
  8395. struct lpfc_dmabuf *mp, *next_mp;
  8396. struct list_head *slp = &pring->postbufq;
  8397. /* Search postbufq, from the beginning, looking for a match on phys */
  8398. spin_lock_irq(&phba->hbalock);
  8399. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8400. if (mp->phys == phys) {
  8401. list_del_init(&mp->list);
  8402. pring->postbufq_cnt--;
  8403. spin_unlock_irq(&phba->hbalock);
  8404. return mp;
  8405. }
  8406. }
  8407. spin_unlock_irq(&phba->hbalock);
  8408. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8409. "0410 Cannot find virtual addr for mapped buf on "
  8410. "ring %d Data x%llx x%p x%p x%x\n",
  8411. pring->ringno, (unsigned long long)phys,
  8412. slp->next, slp->prev, pring->postbufq_cnt);
  8413. return NULL;
  8414. }
  8415. /**
  8416. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8417. * @phba: Pointer to HBA context object.
  8418. * @cmdiocb: Pointer to driver command iocb object.
  8419. * @rspiocb: Pointer to driver response iocb object.
  8420. *
  8421. * This function is the completion handler for the abort iocbs for
  8422. * ELS commands. This function is called from the ELS ring event
  8423. * handler with no lock held. This function frees memory resources
  8424. * associated with the abort iocb.
  8425. **/
  8426. static void
  8427. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8428. struct lpfc_iocbq *rspiocb)
  8429. {
  8430. IOCB_t *irsp = &rspiocb->iocb;
  8431. uint16_t abort_iotag, abort_context;
  8432. struct lpfc_iocbq *abort_iocb = NULL;
  8433. if (irsp->ulpStatus) {
  8434. /*
  8435. * Assume that the port already completed and returned, or
  8436. * will return the iocb. Just Log the message.
  8437. */
  8438. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8439. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8440. spin_lock_irq(&phba->hbalock);
  8441. if (phba->sli_rev < LPFC_SLI_REV4) {
  8442. if (abort_iotag != 0 &&
  8443. abort_iotag <= phba->sli.last_iotag)
  8444. abort_iocb =
  8445. phba->sli.iocbq_lookup[abort_iotag];
  8446. } else
  8447. /* For sli4 the abort_tag is the XRI,
  8448. * so the abort routine puts the iotag of the iocb
  8449. * being aborted in the context field of the abort
  8450. * IOCB.
  8451. */
  8452. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8453. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8454. "0327 Cannot abort els iocb %p "
  8455. "with tag %x context %x, abort status %x, "
  8456. "abort code %x\n",
  8457. abort_iocb, abort_iotag, abort_context,
  8458. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8459. spin_unlock_irq(&phba->hbalock);
  8460. }
  8461. lpfc_sli_release_iocbq(phba, cmdiocb);
  8462. return;
  8463. }
  8464. /**
  8465. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8466. * @phba: Pointer to HBA context object.
  8467. * @cmdiocb: Pointer to driver command iocb object.
  8468. * @rspiocb: Pointer to driver response iocb object.
  8469. *
  8470. * The function is called from SLI ring event handler with no
  8471. * lock held. This function is the completion handler for ELS commands
  8472. * which are aborted. The function frees memory resources used for
  8473. * the aborted ELS commands.
  8474. **/
  8475. static void
  8476. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8477. struct lpfc_iocbq *rspiocb)
  8478. {
  8479. IOCB_t *irsp = &rspiocb->iocb;
  8480. /* ELS cmd tag <ulpIoTag> completes */
  8481. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8482. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8483. "x%x x%x x%x\n",
  8484. irsp->ulpIoTag, irsp->ulpStatus,
  8485. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8486. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8487. lpfc_ct_free_iocb(phba, cmdiocb);
  8488. else
  8489. lpfc_els_free_iocb(phba, cmdiocb);
  8490. return;
  8491. }
  8492. /**
  8493. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8494. * @phba: Pointer to HBA context object.
  8495. * @pring: Pointer to driver SLI ring object.
  8496. * @cmdiocb: Pointer to driver command iocb object.
  8497. *
  8498. * This function issues an abort iocb for the provided command iocb down to
  8499. * the port. Other than the case the outstanding command iocb is an abort
  8500. * request, this function issues abort out unconditionally. This function is
  8501. * called with hbalock held. The function returns 0 when it fails due to
  8502. * memory allocation failure or when the command iocb is an abort request.
  8503. **/
  8504. static int
  8505. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8506. struct lpfc_iocbq *cmdiocb)
  8507. {
  8508. struct lpfc_vport *vport = cmdiocb->vport;
  8509. struct lpfc_iocbq *abtsiocbp;
  8510. IOCB_t *icmd = NULL;
  8511. IOCB_t *iabt = NULL;
  8512. int retval;
  8513. /*
  8514. * There are certain command types we don't want to abort. And we
  8515. * don't want to abort commands that are already in the process of
  8516. * being aborted.
  8517. */
  8518. icmd = &cmdiocb->iocb;
  8519. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8520. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8521. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8522. return 0;
  8523. /* issue ABTS for this IOCB based on iotag */
  8524. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8525. if (abtsiocbp == NULL)
  8526. return 0;
  8527. /* This signals the response to set the correct status
  8528. * before calling the completion handler
  8529. */
  8530. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8531. iabt = &abtsiocbp->iocb;
  8532. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8533. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8534. if (phba->sli_rev == LPFC_SLI_REV4) {
  8535. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8536. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8537. }
  8538. else
  8539. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8540. iabt->ulpLe = 1;
  8541. iabt->ulpClass = icmd->ulpClass;
  8542. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8543. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8544. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8545. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8546. if (phba->link_state >= LPFC_LINK_UP)
  8547. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8548. else
  8549. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8550. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8551. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8552. "0339 Abort xri x%x, original iotag x%x, "
  8553. "abort cmd iotag x%x\n",
  8554. iabt->un.acxri.abortIoTag,
  8555. iabt->un.acxri.abortContextTag,
  8556. abtsiocbp->iotag);
  8557. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  8558. if (retval)
  8559. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8560. /*
  8561. * Caller to this routine should check for IOCB_ERROR
  8562. * and handle it properly. This routine no longer removes
  8563. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8564. */
  8565. return retval;
  8566. }
  8567. /**
  8568. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8569. * @phba: Pointer to HBA context object.
  8570. * @pring: Pointer to driver SLI ring object.
  8571. * @cmdiocb: Pointer to driver command iocb object.
  8572. *
  8573. * This function issues an abort iocb for the provided command iocb. In case
  8574. * of unloading, the abort iocb will not be issued to commands on the ELS
  8575. * ring. Instead, the callback function shall be changed to those commands
  8576. * so that nothing happens when them finishes. This function is called with
  8577. * hbalock held. The function returns 0 when the command iocb is an abort
  8578. * request.
  8579. **/
  8580. int
  8581. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8582. struct lpfc_iocbq *cmdiocb)
  8583. {
  8584. struct lpfc_vport *vport = cmdiocb->vport;
  8585. int retval = IOCB_ERROR;
  8586. IOCB_t *icmd = NULL;
  8587. /*
  8588. * There are certain command types we don't want to abort. And we
  8589. * don't want to abort commands that are already in the process of
  8590. * being aborted.
  8591. */
  8592. icmd = &cmdiocb->iocb;
  8593. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8594. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8595. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8596. return 0;
  8597. /*
  8598. * If we're unloading, don't abort iocb on the ELS ring, but change
  8599. * the callback so that nothing happens when it finishes.
  8600. */
  8601. if ((vport->load_flag & FC_UNLOADING) &&
  8602. (pring->ringno == LPFC_ELS_RING)) {
  8603. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8604. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8605. else
  8606. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8607. goto abort_iotag_exit;
  8608. }
  8609. /* Now, we try to issue the abort to the cmdiocb out */
  8610. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8611. abort_iotag_exit:
  8612. /*
  8613. * Caller to this routine should check for IOCB_ERROR
  8614. * and handle it properly. This routine no longer removes
  8615. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8616. */
  8617. return retval;
  8618. }
  8619. /**
  8620. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8621. * @phba: Pointer to HBA context object.
  8622. * @pring: Pointer to driver SLI ring object.
  8623. *
  8624. * This function aborts all iocbs in the given ring and frees all the iocb
  8625. * objects in txq. This function issues abort iocbs unconditionally for all
  8626. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8627. * to complete before the return of this function. The caller is not required
  8628. * to hold any locks.
  8629. **/
  8630. static void
  8631. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8632. {
  8633. LIST_HEAD(completions);
  8634. struct lpfc_iocbq *iocb, *next_iocb;
  8635. if (pring->ringno == LPFC_ELS_RING)
  8636. lpfc_fabric_abort_hba(phba);
  8637. spin_lock_irq(&phba->hbalock);
  8638. /* Take off all the iocbs on txq for cancelling */
  8639. list_splice_init(&pring->txq, &completions);
  8640. pring->txq_cnt = 0;
  8641. /* Next issue ABTS for everything on the txcmplq */
  8642. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8643. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8644. spin_unlock_irq(&phba->hbalock);
  8645. /* Cancel all the IOCBs from the completions list */
  8646. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8647. IOERR_SLI_ABORTED);
  8648. }
  8649. /**
  8650. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8651. * @phba: pointer to lpfc HBA data structure.
  8652. *
  8653. * This routine will abort all pending and outstanding iocbs to an HBA.
  8654. **/
  8655. void
  8656. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8657. {
  8658. struct lpfc_sli *psli = &phba->sli;
  8659. struct lpfc_sli_ring *pring;
  8660. int i;
  8661. for (i = 0; i < psli->num_rings; i++) {
  8662. pring = &psli->ring[i];
  8663. lpfc_sli_iocb_ring_abort(phba, pring);
  8664. }
  8665. }
  8666. /**
  8667. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8668. * @iocbq: Pointer to driver iocb object.
  8669. * @vport: Pointer to driver virtual port object.
  8670. * @tgt_id: SCSI ID of the target.
  8671. * @lun_id: LUN ID of the scsi device.
  8672. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8673. *
  8674. * This function acts as an iocb filter for functions which abort or count
  8675. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8676. * 0 if the filtering criteria is met for the given iocb and will return
  8677. * 1 if the filtering criteria is not met.
  8678. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8679. * given iocb is for the SCSI device specified by vport, tgt_id and
  8680. * lun_id parameter.
  8681. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8682. * given iocb is for the SCSI target specified by vport and tgt_id
  8683. * parameters.
  8684. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8685. * given iocb is for the SCSI host associated with the given vport.
  8686. * This function is called with no locks held.
  8687. **/
  8688. static int
  8689. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8690. uint16_t tgt_id, uint64_t lun_id,
  8691. lpfc_ctx_cmd ctx_cmd)
  8692. {
  8693. struct lpfc_scsi_buf *lpfc_cmd;
  8694. int rc = 1;
  8695. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8696. return rc;
  8697. if (iocbq->vport != vport)
  8698. return rc;
  8699. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8700. if (lpfc_cmd->pCmd == NULL)
  8701. return rc;
  8702. switch (ctx_cmd) {
  8703. case LPFC_CTX_LUN:
  8704. if ((lpfc_cmd->rdata->pnode) &&
  8705. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8706. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8707. rc = 0;
  8708. break;
  8709. case LPFC_CTX_TGT:
  8710. if ((lpfc_cmd->rdata->pnode) &&
  8711. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8712. rc = 0;
  8713. break;
  8714. case LPFC_CTX_HOST:
  8715. rc = 0;
  8716. break;
  8717. default:
  8718. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8719. __func__, ctx_cmd);
  8720. break;
  8721. }
  8722. return rc;
  8723. }
  8724. /**
  8725. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8726. * @vport: Pointer to virtual port.
  8727. * @tgt_id: SCSI ID of the target.
  8728. * @lun_id: LUN ID of the scsi device.
  8729. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8730. *
  8731. * This function returns number of FCP commands pending for the vport.
  8732. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8733. * commands pending on the vport associated with SCSI device specified
  8734. * by tgt_id and lun_id parameters.
  8735. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8736. * commands pending on the vport associated with SCSI target specified
  8737. * by tgt_id parameter.
  8738. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8739. * commands pending on the vport.
  8740. * This function returns the number of iocbs which satisfy the filter.
  8741. * This function is called without any lock held.
  8742. **/
  8743. int
  8744. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8745. lpfc_ctx_cmd ctx_cmd)
  8746. {
  8747. struct lpfc_hba *phba = vport->phba;
  8748. struct lpfc_iocbq *iocbq;
  8749. int sum, i;
  8750. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8751. iocbq = phba->sli.iocbq_lookup[i];
  8752. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8753. ctx_cmd) == 0)
  8754. sum++;
  8755. }
  8756. return sum;
  8757. }
  8758. /**
  8759. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8760. * @phba: Pointer to HBA context object
  8761. * @cmdiocb: Pointer to command iocb object.
  8762. * @rspiocb: Pointer to response iocb object.
  8763. *
  8764. * This function is called when an aborted FCP iocb completes. This
  8765. * function is called by the ring event handler with no lock held.
  8766. * This function frees the iocb.
  8767. **/
  8768. void
  8769. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8770. struct lpfc_iocbq *rspiocb)
  8771. {
  8772. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8773. "3096 ABORT_XRI_CN completing on xri x%x "
  8774. "original iotag x%x, abort cmd iotag x%x "
  8775. "status 0x%x, reason 0x%x\n",
  8776. cmdiocb->iocb.un.acxri.abortContextTag,
  8777. cmdiocb->iocb.un.acxri.abortIoTag,
  8778. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8779. rspiocb->iocb.un.ulpWord[4]);
  8780. lpfc_sli_release_iocbq(phba, cmdiocb);
  8781. return;
  8782. }
  8783. /**
  8784. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8785. * @vport: Pointer to virtual port.
  8786. * @pring: Pointer to driver SLI ring object.
  8787. * @tgt_id: SCSI ID of the target.
  8788. * @lun_id: LUN ID of the scsi device.
  8789. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8790. *
  8791. * This function sends an abort command for every SCSI command
  8792. * associated with the given virtual port pending on the ring
  8793. * filtered by lpfc_sli_validate_fcp_iocb function.
  8794. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8795. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8796. * parameters
  8797. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8798. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8799. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8800. * FCP iocbs associated with virtual port.
  8801. * This function returns number of iocbs it failed to abort.
  8802. * This function is called with no locks held.
  8803. **/
  8804. int
  8805. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8806. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8807. {
  8808. struct lpfc_hba *phba = vport->phba;
  8809. struct lpfc_iocbq *iocbq;
  8810. struct lpfc_iocbq *abtsiocb;
  8811. IOCB_t *cmd = NULL;
  8812. int errcnt = 0, ret_val = 0;
  8813. int i;
  8814. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8815. iocbq = phba->sli.iocbq_lookup[i];
  8816. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8817. abort_cmd) != 0)
  8818. continue;
  8819. /* issue ABTS for this IOCB based on iotag */
  8820. abtsiocb = lpfc_sli_get_iocbq(phba);
  8821. if (abtsiocb == NULL) {
  8822. errcnt++;
  8823. continue;
  8824. }
  8825. cmd = &iocbq->iocb;
  8826. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8827. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8828. if (phba->sli_rev == LPFC_SLI_REV4)
  8829. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8830. else
  8831. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8832. abtsiocb->iocb.ulpLe = 1;
  8833. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8834. abtsiocb->vport = phba->pport;
  8835. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8836. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8837. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8838. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8839. if (lpfc_is_link_up(phba))
  8840. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8841. else
  8842. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8843. /* Setup callback routine and issue the command. */
  8844. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8845. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8846. abtsiocb, 0);
  8847. if (ret_val == IOCB_ERROR) {
  8848. lpfc_sli_release_iocbq(phba, abtsiocb);
  8849. errcnt++;
  8850. continue;
  8851. }
  8852. }
  8853. return errcnt;
  8854. }
  8855. /**
  8856. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8857. * @phba: Pointer to HBA context object.
  8858. * @cmdiocbq: Pointer to command iocb.
  8859. * @rspiocbq: Pointer to response iocb.
  8860. *
  8861. * This function is the completion handler for iocbs issued using
  8862. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8863. * ring event handler function without any lock held. This function
  8864. * can be called from both worker thread context and interrupt
  8865. * context. This function also can be called from other thread which
  8866. * cleans up the SLI layer objects.
  8867. * This function copy the contents of the response iocb to the
  8868. * response iocb memory object provided by the caller of
  8869. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  8870. * sleeps for the iocb completion.
  8871. **/
  8872. static void
  8873. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  8874. struct lpfc_iocbq *cmdiocbq,
  8875. struct lpfc_iocbq *rspiocbq)
  8876. {
  8877. wait_queue_head_t *pdone_q;
  8878. unsigned long iflags;
  8879. struct lpfc_scsi_buf *lpfc_cmd;
  8880. spin_lock_irqsave(&phba->hbalock, iflags);
  8881. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  8882. if (cmdiocbq->context2 && rspiocbq)
  8883. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  8884. &rspiocbq->iocb, sizeof(IOCB_t));
  8885. /* Set the exchange busy flag for task management commands */
  8886. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  8887. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  8888. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  8889. cur_iocbq);
  8890. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  8891. }
  8892. pdone_q = cmdiocbq->context_un.wait_queue;
  8893. if (pdone_q)
  8894. wake_up(pdone_q);
  8895. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8896. return;
  8897. }
  8898. /**
  8899. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  8900. * @phba: Pointer to HBA context object..
  8901. * @piocbq: Pointer to command iocb.
  8902. * @flag: Flag to test.
  8903. *
  8904. * This routine grabs the hbalock and then test the iocb_flag to
  8905. * see if the passed in flag is set.
  8906. * Returns:
  8907. * 1 if flag is set.
  8908. * 0 if flag is not set.
  8909. **/
  8910. static int
  8911. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  8912. struct lpfc_iocbq *piocbq, uint32_t flag)
  8913. {
  8914. unsigned long iflags;
  8915. int ret;
  8916. spin_lock_irqsave(&phba->hbalock, iflags);
  8917. ret = piocbq->iocb_flag & flag;
  8918. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8919. return ret;
  8920. }
  8921. /**
  8922. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  8923. * @phba: Pointer to HBA context object..
  8924. * @pring: Pointer to sli ring.
  8925. * @piocb: Pointer to command iocb.
  8926. * @prspiocbq: Pointer to response iocb.
  8927. * @timeout: Timeout in number of seconds.
  8928. *
  8929. * This function issues the iocb to firmware and waits for the
  8930. * iocb to complete. If the iocb command is not
  8931. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  8932. * Caller should not free the iocb resources if this function
  8933. * returns IOCB_TIMEDOUT.
  8934. * The function waits for the iocb completion using an
  8935. * non-interruptible wait.
  8936. * This function will sleep while waiting for iocb completion.
  8937. * So, this function should not be called from any context which
  8938. * does not allow sleeping. Due to the same reason, this function
  8939. * cannot be called with interrupt disabled.
  8940. * This function assumes that the iocb completions occur while
  8941. * this function sleep. So, this function cannot be called from
  8942. * the thread which process iocb completion for this ring.
  8943. * This function clears the iocb_flag of the iocb object before
  8944. * issuing the iocb and the iocb completion handler sets this
  8945. * flag and wakes this thread when the iocb completes.
  8946. * The contents of the response iocb will be copied to prspiocbq
  8947. * by the completion handler when the command completes.
  8948. * This function returns IOCB_SUCCESS when success.
  8949. * This function is called with no lock held.
  8950. **/
  8951. int
  8952. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  8953. uint32_t ring_number,
  8954. struct lpfc_iocbq *piocb,
  8955. struct lpfc_iocbq *prspiocbq,
  8956. uint32_t timeout)
  8957. {
  8958. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  8959. long timeleft, timeout_req = 0;
  8960. int retval = IOCB_SUCCESS;
  8961. uint32_t creg_val;
  8962. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8963. /*
  8964. * If the caller has provided a response iocbq buffer, then context2
  8965. * is NULL or its an error.
  8966. */
  8967. if (prspiocbq) {
  8968. if (piocb->context2)
  8969. return IOCB_ERROR;
  8970. piocb->context2 = prspiocbq;
  8971. }
  8972. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  8973. piocb->context_un.wait_queue = &done_q;
  8974. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  8975. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  8976. if (lpfc_readl(phba->HCregaddr, &creg_val))
  8977. return IOCB_ERROR;
  8978. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  8979. writel(creg_val, phba->HCregaddr);
  8980. readl(phba->HCregaddr); /* flush */
  8981. }
  8982. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  8983. SLI_IOCB_RET_IOCB);
  8984. if (retval == IOCB_SUCCESS) {
  8985. timeout_req = timeout * HZ;
  8986. timeleft = wait_event_timeout(done_q,
  8987. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  8988. timeout_req);
  8989. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  8990. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8991. "0331 IOCB wake signaled\n");
  8992. } else if (timeleft == 0) {
  8993. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8994. "0338 IOCB wait timeout error - no "
  8995. "wake response Data x%x\n", timeout);
  8996. retval = IOCB_TIMEDOUT;
  8997. } else {
  8998. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8999. "0330 IOCB wake NOT set, "
  9000. "Data x%x x%lx\n",
  9001. timeout, (timeleft / jiffies));
  9002. retval = IOCB_TIMEDOUT;
  9003. }
  9004. } else if (retval == IOCB_BUSY) {
  9005. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9006. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9007. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  9008. return retval;
  9009. } else {
  9010. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9011. "0332 IOCB wait issue failed, Data x%x\n",
  9012. retval);
  9013. retval = IOCB_ERROR;
  9014. }
  9015. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9016. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9017. return IOCB_ERROR;
  9018. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9019. writel(creg_val, phba->HCregaddr);
  9020. readl(phba->HCregaddr); /* flush */
  9021. }
  9022. if (prspiocbq)
  9023. piocb->context2 = NULL;
  9024. piocb->context_un.wait_queue = NULL;
  9025. piocb->iocb_cmpl = NULL;
  9026. return retval;
  9027. }
  9028. /**
  9029. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9030. * @phba: Pointer to HBA context object.
  9031. * @pmboxq: Pointer to driver mailbox object.
  9032. * @timeout: Timeout in number of seconds.
  9033. *
  9034. * This function issues the mailbox to firmware and waits for the
  9035. * mailbox command to complete. If the mailbox command is not
  9036. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9037. * The function waits for the mailbox completion using an
  9038. * interruptible wait. If the thread is woken up due to a
  9039. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9040. * should not free the mailbox resources, if this function returns
  9041. * MBX_TIMEOUT.
  9042. * This function will sleep while waiting for mailbox completion.
  9043. * So, this function should not be called from any context which
  9044. * does not allow sleeping. Due to the same reason, this function
  9045. * cannot be called with interrupt disabled.
  9046. * This function assumes that the mailbox completion occurs while
  9047. * this function sleep. So, this function cannot be called from
  9048. * the worker thread which processes mailbox completion.
  9049. * This function is called in the context of HBA management
  9050. * applications.
  9051. * This function returns MBX_SUCCESS when successful.
  9052. * This function is called with no lock held.
  9053. **/
  9054. int
  9055. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9056. uint32_t timeout)
  9057. {
  9058. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9059. int retval;
  9060. unsigned long flag;
  9061. /* The caller must leave context1 empty. */
  9062. if (pmboxq->context1)
  9063. return MBX_NOT_FINISHED;
  9064. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9065. /* setup wake call as IOCB callback */
  9066. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9067. /* setup context field to pass wait_queue pointer to wake function */
  9068. pmboxq->context1 = &done_q;
  9069. /* now issue the command */
  9070. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9071. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9072. wait_event_interruptible_timeout(done_q,
  9073. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9074. timeout * HZ);
  9075. spin_lock_irqsave(&phba->hbalock, flag);
  9076. pmboxq->context1 = NULL;
  9077. /*
  9078. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9079. * else do not free the resources.
  9080. */
  9081. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9082. retval = MBX_SUCCESS;
  9083. lpfc_sli4_swap_str(phba, pmboxq);
  9084. } else {
  9085. retval = MBX_TIMEOUT;
  9086. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9087. }
  9088. spin_unlock_irqrestore(&phba->hbalock, flag);
  9089. }
  9090. return retval;
  9091. }
  9092. /**
  9093. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9094. * @phba: Pointer to HBA context.
  9095. *
  9096. * This function is called to shutdown the driver's mailbox sub-system.
  9097. * It first marks the mailbox sub-system is in a block state to prevent
  9098. * the asynchronous mailbox command from issued off the pending mailbox
  9099. * command queue. If the mailbox command sub-system shutdown is due to
  9100. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9101. * the mailbox sub-system flush routine to forcefully bring down the
  9102. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9103. * as with offline or HBA function reset), this routine will wait for the
  9104. * outstanding mailbox command to complete before invoking the mailbox
  9105. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9106. **/
  9107. void
  9108. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  9109. {
  9110. struct lpfc_sli *psli = &phba->sli;
  9111. unsigned long timeout;
  9112. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9113. spin_lock_irq(&phba->hbalock);
  9114. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9115. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9116. /* Determine how long we might wait for the active mailbox
  9117. * command to be gracefully completed by firmware.
  9118. */
  9119. if (phba->sli.mbox_active)
  9120. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9121. phba->sli.mbox_active) *
  9122. 1000) + jiffies;
  9123. spin_unlock_irq(&phba->hbalock);
  9124. while (phba->sli.mbox_active) {
  9125. /* Check active mailbox complete status every 2ms */
  9126. msleep(2);
  9127. if (time_after(jiffies, timeout))
  9128. /* Timeout, let the mailbox flush routine to
  9129. * forcefully release active mailbox command
  9130. */
  9131. break;
  9132. }
  9133. } else
  9134. spin_unlock_irq(&phba->hbalock);
  9135. lpfc_sli_mbox_sys_flush(phba);
  9136. }
  9137. /**
  9138. * lpfc_sli_eratt_read - read sli-3 error attention events
  9139. * @phba: Pointer to HBA context.
  9140. *
  9141. * This function is called to read the SLI3 device error attention registers
  9142. * for possible error attention events. The caller must hold the hostlock
  9143. * with spin_lock_irq().
  9144. *
  9145. * This function returns 1 when there is Error Attention in the Host Attention
  9146. * Register and returns 0 otherwise.
  9147. **/
  9148. static int
  9149. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9150. {
  9151. uint32_t ha_copy;
  9152. /* Read chip Host Attention (HA) register */
  9153. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9154. goto unplug_err;
  9155. if (ha_copy & HA_ERATT) {
  9156. /* Read host status register to retrieve error event */
  9157. if (lpfc_sli_read_hs(phba))
  9158. goto unplug_err;
  9159. /* Check if there is a deferred error condition is active */
  9160. if ((HS_FFER1 & phba->work_hs) &&
  9161. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9162. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9163. phba->hba_flag |= DEFER_ERATT;
  9164. /* Clear all interrupt enable conditions */
  9165. writel(0, phba->HCregaddr);
  9166. readl(phba->HCregaddr);
  9167. }
  9168. /* Set the driver HA work bitmap */
  9169. phba->work_ha |= HA_ERATT;
  9170. /* Indicate polling handles this ERATT */
  9171. phba->hba_flag |= HBA_ERATT_HANDLED;
  9172. return 1;
  9173. }
  9174. return 0;
  9175. unplug_err:
  9176. /* Set the driver HS work bitmap */
  9177. phba->work_hs |= UNPLUG_ERR;
  9178. /* Set the driver HA work bitmap */
  9179. phba->work_ha |= HA_ERATT;
  9180. /* Indicate polling handles this ERATT */
  9181. phba->hba_flag |= HBA_ERATT_HANDLED;
  9182. return 1;
  9183. }
  9184. /**
  9185. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9186. * @phba: Pointer to HBA context.
  9187. *
  9188. * This function is called to read the SLI4 device error attention registers
  9189. * for possible error attention events. The caller must hold the hostlock
  9190. * with spin_lock_irq().
  9191. *
  9192. * This function returns 1 when there is Error Attention in the Host Attention
  9193. * Register and returns 0 otherwise.
  9194. **/
  9195. static int
  9196. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9197. {
  9198. uint32_t uerr_sta_hi, uerr_sta_lo;
  9199. uint32_t if_type, portsmphr;
  9200. struct lpfc_register portstat_reg;
  9201. /*
  9202. * For now, use the SLI4 device internal unrecoverable error
  9203. * registers for error attention. This can be changed later.
  9204. */
  9205. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9206. switch (if_type) {
  9207. case LPFC_SLI_INTF_IF_TYPE_0:
  9208. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9209. &uerr_sta_lo) ||
  9210. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9211. &uerr_sta_hi)) {
  9212. phba->work_hs |= UNPLUG_ERR;
  9213. phba->work_ha |= HA_ERATT;
  9214. phba->hba_flag |= HBA_ERATT_HANDLED;
  9215. return 1;
  9216. }
  9217. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9218. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9219. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9220. "1423 HBA Unrecoverable error: "
  9221. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9222. "ue_mask_lo_reg=0x%x, "
  9223. "ue_mask_hi_reg=0x%x\n",
  9224. uerr_sta_lo, uerr_sta_hi,
  9225. phba->sli4_hba.ue_mask_lo,
  9226. phba->sli4_hba.ue_mask_hi);
  9227. phba->work_status[0] = uerr_sta_lo;
  9228. phba->work_status[1] = uerr_sta_hi;
  9229. phba->work_ha |= HA_ERATT;
  9230. phba->hba_flag |= HBA_ERATT_HANDLED;
  9231. return 1;
  9232. }
  9233. break;
  9234. case LPFC_SLI_INTF_IF_TYPE_2:
  9235. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9236. &portstat_reg.word0) ||
  9237. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9238. &portsmphr)){
  9239. phba->work_hs |= UNPLUG_ERR;
  9240. phba->work_ha |= HA_ERATT;
  9241. phba->hba_flag |= HBA_ERATT_HANDLED;
  9242. return 1;
  9243. }
  9244. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9245. phba->work_status[0] =
  9246. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9247. phba->work_status[1] =
  9248. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9249. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9250. "2885 Port Status Event: "
  9251. "port status reg 0x%x, "
  9252. "port smphr reg 0x%x, "
  9253. "error 1=0x%x, error 2=0x%x\n",
  9254. portstat_reg.word0,
  9255. portsmphr,
  9256. phba->work_status[0],
  9257. phba->work_status[1]);
  9258. phba->work_ha |= HA_ERATT;
  9259. phba->hba_flag |= HBA_ERATT_HANDLED;
  9260. return 1;
  9261. }
  9262. break;
  9263. case LPFC_SLI_INTF_IF_TYPE_1:
  9264. default:
  9265. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9266. "2886 HBA Error Attention on unsupported "
  9267. "if type %d.", if_type);
  9268. return 1;
  9269. }
  9270. return 0;
  9271. }
  9272. /**
  9273. * lpfc_sli_check_eratt - check error attention events
  9274. * @phba: Pointer to HBA context.
  9275. *
  9276. * This function is called from timer soft interrupt context to check HBA's
  9277. * error attention register bit for error attention events.
  9278. *
  9279. * This function returns 1 when there is Error Attention in the Host Attention
  9280. * Register and returns 0 otherwise.
  9281. **/
  9282. int
  9283. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9284. {
  9285. uint32_t ha_copy;
  9286. /* If somebody is waiting to handle an eratt, don't process it
  9287. * here. The brdkill function will do this.
  9288. */
  9289. if (phba->link_flag & LS_IGNORE_ERATT)
  9290. return 0;
  9291. /* Check if interrupt handler handles this ERATT */
  9292. spin_lock_irq(&phba->hbalock);
  9293. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9294. /* Interrupt handler has handled ERATT */
  9295. spin_unlock_irq(&phba->hbalock);
  9296. return 0;
  9297. }
  9298. /*
  9299. * If there is deferred error attention, do not check for error
  9300. * attention
  9301. */
  9302. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9303. spin_unlock_irq(&phba->hbalock);
  9304. return 0;
  9305. }
  9306. /* If PCI channel is offline, don't process it */
  9307. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9308. spin_unlock_irq(&phba->hbalock);
  9309. return 0;
  9310. }
  9311. switch (phba->sli_rev) {
  9312. case LPFC_SLI_REV2:
  9313. case LPFC_SLI_REV3:
  9314. /* Read chip Host Attention (HA) register */
  9315. ha_copy = lpfc_sli_eratt_read(phba);
  9316. break;
  9317. case LPFC_SLI_REV4:
  9318. /* Read device Uncoverable Error (UERR) registers */
  9319. ha_copy = lpfc_sli4_eratt_read(phba);
  9320. break;
  9321. default:
  9322. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9323. "0299 Invalid SLI revision (%d)\n",
  9324. phba->sli_rev);
  9325. ha_copy = 0;
  9326. break;
  9327. }
  9328. spin_unlock_irq(&phba->hbalock);
  9329. return ha_copy;
  9330. }
  9331. /**
  9332. * lpfc_intr_state_check - Check device state for interrupt handling
  9333. * @phba: Pointer to HBA context.
  9334. *
  9335. * This inline routine checks whether a device or its PCI slot is in a state
  9336. * that the interrupt should be handled.
  9337. *
  9338. * This function returns 0 if the device or the PCI slot is in a state that
  9339. * interrupt should be handled, otherwise -EIO.
  9340. */
  9341. static inline int
  9342. lpfc_intr_state_check(struct lpfc_hba *phba)
  9343. {
  9344. /* If the pci channel is offline, ignore all the interrupts */
  9345. if (unlikely(pci_channel_offline(phba->pcidev)))
  9346. return -EIO;
  9347. /* Update device level interrupt statistics */
  9348. phba->sli.slistat.sli_intr++;
  9349. /* Ignore all interrupts during initialization. */
  9350. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9351. return -EIO;
  9352. return 0;
  9353. }
  9354. /**
  9355. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9356. * @irq: Interrupt number.
  9357. * @dev_id: The device context pointer.
  9358. *
  9359. * This function is directly called from the PCI layer as an interrupt
  9360. * service routine when device with SLI-3 interface spec is enabled with
  9361. * MSI-X multi-message interrupt mode and there are slow-path events in
  9362. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9363. * interrupt mode, this function is called as part of the device-level
  9364. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9365. * is undergoing initialization, the interrupt handler will not process
  9366. * the interrupt. The link attention and ELS ring attention events are
  9367. * handled by the worker thread. The interrupt handler signals the worker
  9368. * thread and returns for these events. This function is called without
  9369. * any lock held. It gets the hbalock to access and update SLI data
  9370. * structures.
  9371. *
  9372. * This function returns IRQ_HANDLED when interrupt is handled else it
  9373. * returns IRQ_NONE.
  9374. **/
  9375. irqreturn_t
  9376. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9377. {
  9378. struct lpfc_hba *phba;
  9379. uint32_t ha_copy, hc_copy;
  9380. uint32_t work_ha_copy;
  9381. unsigned long status;
  9382. unsigned long iflag;
  9383. uint32_t control;
  9384. MAILBOX_t *mbox, *pmbox;
  9385. struct lpfc_vport *vport;
  9386. struct lpfc_nodelist *ndlp;
  9387. struct lpfc_dmabuf *mp;
  9388. LPFC_MBOXQ_t *pmb;
  9389. int rc;
  9390. /*
  9391. * Get the driver's phba structure from the dev_id and
  9392. * assume the HBA is not interrupting.
  9393. */
  9394. phba = (struct lpfc_hba *)dev_id;
  9395. if (unlikely(!phba))
  9396. return IRQ_NONE;
  9397. /*
  9398. * Stuff needs to be attented to when this function is invoked as an
  9399. * individual interrupt handler in MSI-X multi-message interrupt mode
  9400. */
  9401. if (phba->intr_type == MSIX) {
  9402. /* Check device state for handling interrupt */
  9403. if (lpfc_intr_state_check(phba))
  9404. return IRQ_NONE;
  9405. /* Need to read HA REG for slow-path events */
  9406. spin_lock_irqsave(&phba->hbalock, iflag);
  9407. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9408. goto unplug_error;
  9409. /* If somebody is waiting to handle an eratt don't process it
  9410. * here. The brdkill function will do this.
  9411. */
  9412. if (phba->link_flag & LS_IGNORE_ERATT)
  9413. ha_copy &= ~HA_ERATT;
  9414. /* Check the need for handling ERATT in interrupt handler */
  9415. if (ha_copy & HA_ERATT) {
  9416. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9417. /* ERATT polling has handled ERATT */
  9418. ha_copy &= ~HA_ERATT;
  9419. else
  9420. /* Indicate interrupt handler handles ERATT */
  9421. phba->hba_flag |= HBA_ERATT_HANDLED;
  9422. }
  9423. /*
  9424. * If there is deferred error attention, do not check for any
  9425. * interrupt.
  9426. */
  9427. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9428. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9429. return IRQ_NONE;
  9430. }
  9431. /* Clear up only attention source related to slow-path */
  9432. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9433. goto unplug_error;
  9434. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9435. HC_LAINT_ENA | HC_ERINT_ENA),
  9436. phba->HCregaddr);
  9437. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9438. phba->HAregaddr);
  9439. writel(hc_copy, phba->HCregaddr);
  9440. readl(phba->HAregaddr); /* flush */
  9441. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9442. } else
  9443. ha_copy = phba->ha_copy;
  9444. work_ha_copy = ha_copy & phba->work_ha_mask;
  9445. if (work_ha_copy) {
  9446. if (work_ha_copy & HA_LATT) {
  9447. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9448. /*
  9449. * Turn off Link Attention interrupts
  9450. * until CLEAR_LA done
  9451. */
  9452. spin_lock_irqsave(&phba->hbalock, iflag);
  9453. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9454. if (lpfc_readl(phba->HCregaddr, &control))
  9455. goto unplug_error;
  9456. control &= ~HC_LAINT_ENA;
  9457. writel(control, phba->HCregaddr);
  9458. readl(phba->HCregaddr); /* flush */
  9459. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9460. }
  9461. else
  9462. work_ha_copy &= ~HA_LATT;
  9463. }
  9464. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9465. /*
  9466. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9467. * the only slow ring.
  9468. */
  9469. status = (work_ha_copy &
  9470. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9471. status >>= (4*LPFC_ELS_RING);
  9472. if (status & HA_RXMASK) {
  9473. spin_lock_irqsave(&phba->hbalock, iflag);
  9474. if (lpfc_readl(phba->HCregaddr, &control))
  9475. goto unplug_error;
  9476. lpfc_debugfs_slow_ring_trc(phba,
  9477. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9478. control, status,
  9479. (uint32_t)phba->sli.slistat.sli_intr);
  9480. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9481. lpfc_debugfs_slow_ring_trc(phba,
  9482. "ISR Disable ring:"
  9483. "pwork:x%x hawork:x%x wait:x%x",
  9484. phba->work_ha, work_ha_copy,
  9485. (uint32_t)((unsigned long)
  9486. &phba->work_waitq));
  9487. control &=
  9488. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9489. writel(control, phba->HCregaddr);
  9490. readl(phba->HCregaddr); /* flush */
  9491. }
  9492. else {
  9493. lpfc_debugfs_slow_ring_trc(phba,
  9494. "ISR slow ring: pwork:"
  9495. "x%x hawork:x%x wait:x%x",
  9496. phba->work_ha, work_ha_copy,
  9497. (uint32_t)((unsigned long)
  9498. &phba->work_waitq));
  9499. }
  9500. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9501. }
  9502. }
  9503. spin_lock_irqsave(&phba->hbalock, iflag);
  9504. if (work_ha_copy & HA_ERATT) {
  9505. if (lpfc_sli_read_hs(phba))
  9506. goto unplug_error;
  9507. /*
  9508. * Check if there is a deferred error condition
  9509. * is active
  9510. */
  9511. if ((HS_FFER1 & phba->work_hs) &&
  9512. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9513. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9514. phba->work_hs)) {
  9515. phba->hba_flag |= DEFER_ERATT;
  9516. /* Clear all interrupt enable conditions */
  9517. writel(0, phba->HCregaddr);
  9518. readl(phba->HCregaddr);
  9519. }
  9520. }
  9521. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9522. pmb = phba->sli.mbox_active;
  9523. pmbox = &pmb->u.mb;
  9524. mbox = phba->mbox;
  9525. vport = pmb->vport;
  9526. /* First check out the status word */
  9527. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9528. if (pmbox->mbxOwner != OWN_HOST) {
  9529. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9530. /*
  9531. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9532. * mbxStatus <status>
  9533. */
  9534. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9535. LOG_SLI,
  9536. "(%d):0304 Stray Mailbox "
  9537. "Interrupt mbxCommand x%x "
  9538. "mbxStatus x%x\n",
  9539. (vport ? vport->vpi : 0),
  9540. pmbox->mbxCommand,
  9541. pmbox->mbxStatus);
  9542. /* clear mailbox attention bit */
  9543. work_ha_copy &= ~HA_MBATT;
  9544. } else {
  9545. phba->sli.mbox_active = NULL;
  9546. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9547. phba->last_completion_time = jiffies;
  9548. del_timer(&phba->sli.mbox_tmo);
  9549. if (pmb->mbox_cmpl) {
  9550. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9551. MAILBOX_CMD_SIZE);
  9552. if (pmb->out_ext_byte_len &&
  9553. pmb->context2)
  9554. lpfc_sli_pcimem_bcopy(
  9555. phba->mbox_ext,
  9556. pmb->context2,
  9557. pmb->out_ext_byte_len);
  9558. }
  9559. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9560. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9561. lpfc_debugfs_disc_trc(vport,
  9562. LPFC_DISC_TRC_MBOX_VPORT,
  9563. "MBOX dflt rpi: : "
  9564. "status:x%x rpi:x%x",
  9565. (uint32_t)pmbox->mbxStatus,
  9566. pmbox->un.varWords[0], 0);
  9567. if (!pmbox->mbxStatus) {
  9568. mp = (struct lpfc_dmabuf *)
  9569. (pmb->context1);
  9570. ndlp = (struct lpfc_nodelist *)
  9571. pmb->context2;
  9572. /* Reg_LOGIN of dflt RPI was
  9573. * successful. new lets get
  9574. * rid of the RPI using the
  9575. * same mbox buffer.
  9576. */
  9577. lpfc_unreg_login(phba,
  9578. vport->vpi,
  9579. pmbox->un.varWords[0],
  9580. pmb);
  9581. pmb->mbox_cmpl =
  9582. lpfc_mbx_cmpl_dflt_rpi;
  9583. pmb->context1 = mp;
  9584. pmb->context2 = ndlp;
  9585. pmb->vport = vport;
  9586. rc = lpfc_sli_issue_mbox(phba,
  9587. pmb,
  9588. MBX_NOWAIT);
  9589. if (rc != MBX_BUSY)
  9590. lpfc_printf_log(phba,
  9591. KERN_ERR,
  9592. LOG_MBOX | LOG_SLI,
  9593. "0350 rc should have"
  9594. "been MBX_BUSY\n");
  9595. if (rc != MBX_NOT_FINISHED)
  9596. goto send_current_mbox;
  9597. }
  9598. }
  9599. spin_lock_irqsave(
  9600. &phba->pport->work_port_lock,
  9601. iflag);
  9602. phba->pport->work_port_events &=
  9603. ~WORKER_MBOX_TMO;
  9604. spin_unlock_irqrestore(
  9605. &phba->pport->work_port_lock,
  9606. iflag);
  9607. lpfc_mbox_cmpl_put(phba, pmb);
  9608. }
  9609. } else
  9610. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9611. if ((work_ha_copy & HA_MBATT) &&
  9612. (phba->sli.mbox_active == NULL)) {
  9613. send_current_mbox:
  9614. /* Process next mailbox command if there is one */
  9615. do {
  9616. rc = lpfc_sli_issue_mbox(phba, NULL,
  9617. MBX_NOWAIT);
  9618. } while (rc == MBX_NOT_FINISHED);
  9619. if (rc != MBX_SUCCESS)
  9620. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9621. LOG_SLI, "0349 rc should be "
  9622. "MBX_SUCCESS\n");
  9623. }
  9624. spin_lock_irqsave(&phba->hbalock, iflag);
  9625. phba->work_ha |= work_ha_copy;
  9626. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9627. lpfc_worker_wake_up(phba);
  9628. }
  9629. return IRQ_HANDLED;
  9630. unplug_error:
  9631. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9632. return IRQ_HANDLED;
  9633. } /* lpfc_sli_sp_intr_handler */
  9634. /**
  9635. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9636. * @irq: Interrupt number.
  9637. * @dev_id: The device context pointer.
  9638. *
  9639. * This function is directly called from the PCI layer as an interrupt
  9640. * service routine when device with SLI-3 interface spec is enabled with
  9641. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9642. * ring event in the HBA. However, when the device is enabled with either
  9643. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9644. * device-level interrupt handler. When the PCI slot is in error recovery
  9645. * or the HBA is undergoing initialization, the interrupt handler will not
  9646. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9647. * the intrrupt context. This function is called without any lock held.
  9648. * It gets the hbalock to access and update SLI data structures.
  9649. *
  9650. * This function returns IRQ_HANDLED when interrupt is handled else it
  9651. * returns IRQ_NONE.
  9652. **/
  9653. irqreturn_t
  9654. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9655. {
  9656. struct lpfc_hba *phba;
  9657. uint32_t ha_copy;
  9658. unsigned long status;
  9659. unsigned long iflag;
  9660. /* Get the driver's phba structure from the dev_id and
  9661. * assume the HBA is not interrupting.
  9662. */
  9663. phba = (struct lpfc_hba *) dev_id;
  9664. if (unlikely(!phba))
  9665. return IRQ_NONE;
  9666. /*
  9667. * Stuff needs to be attented to when this function is invoked as an
  9668. * individual interrupt handler in MSI-X multi-message interrupt mode
  9669. */
  9670. if (phba->intr_type == MSIX) {
  9671. /* Check device state for handling interrupt */
  9672. if (lpfc_intr_state_check(phba))
  9673. return IRQ_NONE;
  9674. /* Need to read HA REG for FCP ring and other ring events */
  9675. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9676. return IRQ_HANDLED;
  9677. /* Clear up only attention source related to fast-path */
  9678. spin_lock_irqsave(&phba->hbalock, iflag);
  9679. /*
  9680. * If there is deferred error attention, do not check for
  9681. * any interrupt.
  9682. */
  9683. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9684. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9685. return IRQ_NONE;
  9686. }
  9687. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9688. phba->HAregaddr);
  9689. readl(phba->HAregaddr); /* flush */
  9690. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9691. } else
  9692. ha_copy = phba->ha_copy;
  9693. /*
  9694. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9695. */
  9696. ha_copy &= ~(phba->work_ha_mask);
  9697. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9698. status >>= (4*LPFC_FCP_RING);
  9699. if (status & HA_RXMASK)
  9700. lpfc_sli_handle_fast_ring_event(phba,
  9701. &phba->sli.ring[LPFC_FCP_RING],
  9702. status);
  9703. if (phba->cfg_multi_ring_support == 2) {
  9704. /*
  9705. * Process all events on extra ring. Take the optimized path
  9706. * for extra ring IO.
  9707. */
  9708. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9709. status >>= (4*LPFC_EXTRA_RING);
  9710. if (status & HA_RXMASK) {
  9711. lpfc_sli_handle_fast_ring_event(phba,
  9712. &phba->sli.ring[LPFC_EXTRA_RING],
  9713. status);
  9714. }
  9715. }
  9716. return IRQ_HANDLED;
  9717. } /* lpfc_sli_fp_intr_handler */
  9718. /**
  9719. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9720. * @irq: Interrupt number.
  9721. * @dev_id: The device context pointer.
  9722. *
  9723. * This function is the HBA device-level interrupt handler to device with
  9724. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9725. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9726. * requires driver attention. This function invokes the slow-path interrupt
  9727. * attention handling function and fast-path interrupt attention handling
  9728. * function in turn to process the relevant HBA attention events. This
  9729. * function is called without any lock held. It gets the hbalock to access
  9730. * and update SLI data structures.
  9731. *
  9732. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9733. * returns IRQ_NONE.
  9734. **/
  9735. irqreturn_t
  9736. lpfc_sli_intr_handler(int irq, void *dev_id)
  9737. {
  9738. struct lpfc_hba *phba;
  9739. irqreturn_t sp_irq_rc, fp_irq_rc;
  9740. unsigned long status1, status2;
  9741. uint32_t hc_copy;
  9742. /*
  9743. * Get the driver's phba structure from the dev_id and
  9744. * assume the HBA is not interrupting.
  9745. */
  9746. phba = (struct lpfc_hba *) dev_id;
  9747. if (unlikely(!phba))
  9748. return IRQ_NONE;
  9749. /* Check device state for handling interrupt */
  9750. if (lpfc_intr_state_check(phba))
  9751. return IRQ_NONE;
  9752. spin_lock(&phba->hbalock);
  9753. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9754. spin_unlock(&phba->hbalock);
  9755. return IRQ_HANDLED;
  9756. }
  9757. if (unlikely(!phba->ha_copy)) {
  9758. spin_unlock(&phba->hbalock);
  9759. return IRQ_NONE;
  9760. } else if (phba->ha_copy & HA_ERATT) {
  9761. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9762. /* ERATT polling has handled ERATT */
  9763. phba->ha_copy &= ~HA_ERATT;
  9764. else
  9765. /* Indicate interrupt handler handles ERATT */
  9766. phba->hba_flag |= HBA_ERATT_HANDLED;
  9767. }
  9768. /*
  9769. * If there is deferred error attention, do not check for any interrupt.
  9770. */
  9771. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9772. spin_unlock(&phba->hbalock);
  9773. return IRQ_NONE;
  9774. }
  9775. /* Clear attention sources except link and error attentions */
  9776. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9777. spin_unlock(&phba->hbalock);
  9778. return IRQ_HANDLED;
  9779. }
  9780. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9781. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9782. phba->HCregaddr);
  9783. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9784. writel(hc_copy, phba->HCregaddr);
  9785. readl(phba->HAregaddr); /* flush */
  9786. spin_unlock(&phba->hbalock);
  9787. /*
  9788. * Invokes slow-path host attention interrupt handling as appropriate.
  9789. */
  9790. /* status of events with mailbox and link attention */
  9791. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9792. /* status of events with ELS ring */
  9793. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9794. status2 >>= (4*LPFC_ELS_RING);
  9795. if (status1 || (status2 & HA_RXMASK))
  9796. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9797. else
  9798. sp_irq_rc = IRQ_NONE;
  9799. /*
  9800. * Invoke fast-path host attention interrupt handling as appropriate.
  9801. */
  9802. /* status of events with FCP ring */
  9803. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9804. status1 >>= (4*LPFC_FCP_RING);
  9805. /* status of events with extra ring */
  9806. if (phba->cfg_multi_ring_support == 2) {
  9807. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9808. status2 >>= (4*LPFC_EXTRA_RING);
  9809. } else
  9810. status2 = 0;
  9811. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9812. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9813. else
  9814. fp_irq_rc = IRQ_NONE;
  9815. /* Return device-level interrupt handling status */
  9816. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9817. } /* lpfc_sli_intr_handler */
  9818. /**
  9819. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9820. * @phba: pointer to lpfc hba data structure.
  9821. *
  9822. * This routine is invoked by the worker thread to process all the pending
  9823. * SLI4 FCP abort XRI events.
  9824. **/
  9825. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9826. {
  9827. struct lpfc_cq_event *cq_event;
  9828. /* First, declare the fcp xri abort event has been handled */
  9829. spin_lock_irq(&phba->hbalock);
  9830. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9831. spin_unlock_irq(&phba->hbalock);
  9832. /* Now, handle all the fcp xri abort events */
  9833. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9834. /* Get the first event from the head of the event queue */
  9835. spin_lock_irq(&phba->hbalock);
  9836. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9837. cq_event, struct lpfc_cq_event, list);
  9838. spin_unlock_irq(&phba->hbalock);
  9839. /* Notify aborted XRI for FCP work queue */
  9840. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9841. /* Free the event processed back to the free pool */
  9842. lpfc_sli4_cq_event_release(phba, cq_event);
  9843. }
  9844. }
  9845. /**
  9846. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9847. * @phba: pointer to lpfc hba data structure.
  9848. *
  9849. * This routine is invoked by the worker thread to process all the pending
  9850. * SLI4 els abort xri events.
  9851. **/
  9852. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  9853. {
  9854. struct lpfc_cq_event *cq_event;
  9855. /* First, declare the els xri abort event has been handled */
  9856. spin_lock_irq(&phba->hbalock);
  9857. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  9858. spin_unlock_irq(&phba->hbalock);
  9859. /* Now, handle all the els xri abort events */
  9860. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  9861. /* Get the first event from the head of the event queue */
  9862. spin_lock_irq(&phba->hbalock);
  9863. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  9864. cq_event, struct lpfc_cq_event, list);
  9865. spin_unlock_irq(&phba->hbalock);
  9866. /* Notify aborted XRI for ELS work queue */
  9867. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9868. /* Free the event processed back to the free pool */
  9869. lpfc_sli4_cq_event_release(phba, cq_event);
  9870. }
  9871. }
  9872. /**
  9873. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  9874. * @phba: pointer to lpfc hba data structure
  9875. * @pIocbIn: pointer to the rspiocbq
  9876. * @pIocbOut: pointer to the cmdiocbq
  9877. * @wcqe: pointer to the complete wcqe
  9878. *
  9879. * This routine transfers the fields of a command iocbq to a response iocbq
  9880. * by copying all the IOCB fields from command iocbq and transferring the
  9881. * completion status information from the complete wcqe.
  9882. **/
  9883. static void
  9884. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  9885. struct lpfc_iocbq *pIocbIn,
  9886. struct lpfc_iocbq *pIocbOut,
  9887. struct lpfc_wcqe_complete *wcqe)
  9888. {
  9889. unsigned long iflags;
  9890. uint32_t status;
  9891. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  9892. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  9893. sizeof(struct lpfc_iocbq) - offset);
  9894. /* Map WCQE parameters into irspiocb parameters */
  9895. status = bf_get(lpfc_wcqe_c_status, wcqe);
  9896. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  9897. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  9898. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  9899. pIocbIn->iocb.un.fcpi.fcpi_parm =
  9900. pIocbOut->iocb.un.fcpi.fcpi_parm -
  9901. wcqe->total_data_placed;
  9902. else
  9903. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9904. else {
  9905. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9906. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  9907. }
  9908. /* Convert BG errors for completion status */
  9909. if (status == CQE_STATUS_DI_ERROR) {
  9910. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  9911. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  9912. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  9913. else
  9914. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  9915. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  9916. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  9917. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9918. BGS_GUARD_ERR_MASK;
  9919. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  9920. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9921. BGS_APPTAG_ERR_MASK;
  9922. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  9923. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9924. BGS_REFTAG_ERR_MASK;
  9925. /* Check to see if there was any good data before the error */
  9926. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  9927. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9928. BGS_HI_WATER_MARK_PRESENT_MASK;
  9929. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  9930. wcqe->total_data_placed;
  9931. }
  9932. /*
  9933. * Set ALL the error bits to indicate we don't know what
  9934. * type of error it is.
  9935. */
  9936. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  9937. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9938. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  9939. BGS_GUARD_ERR_MASK);
  9940. }
  9941. /* Pick up HBA exchange busy condition */
  9942. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  9943. spin_lock_irqsave(&phba->hbalock, iflags);
  9944. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  9945. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9946. }
  9947. }
  9948. /**
  9949. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  9950. * @phba: Pointer to HBA context object.
  9951. * @wcqe: Pointer to work-queue completion queue entry.
  9952. *
  9953. * This routine handles an ELS work-queue completion event and construct
  9954. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  9955. * discovery engine to handle.
  9956. *
  9957. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  9958. **/
  9959. static struct lpfc_iocbq *
  9960. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  9961. struct lpfc_iocbq *irspiocbq)
  9962. {
  9963. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9964. struct lpfc_iocbq *cmdiocbq;
  9965. struct lpfc_wcqe_complete *wcqe;
  9966. unsigned long iflags;
  9967. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  9968. spin_lock_irqsave(&phba->hbalock, iflags);
  9969. pring->stats.iocb_event++;
  9970. /* Look up the ELS command IOCB and create pseudo response IOCB */
  9971. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  9972. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9973. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9974. if (unlikely(!cmdiocbq)) {
  9975. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9976. "0386 ELS complete with no corresponding "
  9977. "cmdiocb: iotag (%d)\n",
  9978. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9979. lpfc_sli_release_iocbq(phba, irspiocbq);
  9980. return NULL;
  9981. }
  9982. /* Fake the irspiocbq and copy necessary response information */
  9983. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  9984. return irspiocbq;
  9985. }
  9986. /**
  9987. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  9988. * @phba: Pointer to HBA context object.
  9989. * @cqe: Pointer to mailbox completion queue entry.
  9990. *
  9991. * This routine process a mailbox completion queue entry with asynchrous
  9992. * event.
  9993. *
  9994. * Return: true if work posted to worker thread, otherwise false.
  9995. **/
  9996. static bool
  9997. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  9998. {
  9999. struct lpfc_cq_event *cq_event;
  10000. unsigned long iflags;
  10001. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10002. "0392 Async Event: word0:x%x, word1:x%x, "
  10003. "word2:x%x, word3:x%x\n", mcqe->word0,
  10004. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10005. /* Allocate a new internal CQ_EVENT entry */
  10006. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10007. if (!cq_event) {
  10008. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10009. "0394 Failed to allocate CQ_EVENT entry\n");
  10010. return false;
  10011. }
  10012. /* Move the CQE into an asynchronous event entry */
  10013. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10014. spin_lock_irqsave(&phba->hbalock, iflags);
  10015. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10016. /* Set the async event flag */
  10017. phba->hba_flag |= ASYNC_EVENT;
  10018. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10019. return true;
  10020. }
  10021. /**
  10022. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10023. * @phba: Pointer to HBA context object.
  10024. * @cqe: Pointer to mailbox completion queue entry.
  10025. *
  10026. * This routine process a mailbox completion queue entry with mailbox
  10027. * completion event.
  10028. *
  10029. * Return: true if work posted to worker thread, otherwise false.
  10030. **/
  10031. static bool
  10032. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10033. {
  10034. uint32_t mcqe_status;
  10035. MAILBOX_t *mbox, *pmbox;
  10036. struct lpfc_mqe *mqe;
  10037. struct lpfc_vport *vport;
  10038. struct lpfc_nodelist *ndlp;
  10039. struct lpfc_dmabuf *mp;
  10040. unsigned long iflags;
  10041. LPFC_MBOXQ_t *pmb;
  10042. bool workposted = false;
  10043. int rc;
  10044. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10045. if (!bf_get(lpfc_trailer_completed, mcqe))
  10046. goto out_no_mqe_complete;
  10047. /* Get the reference to the active mbox command */
  10048. spin_lock_irqsave(&phba->hbalock, iflags);
  10049. pmb = phba->sli.mbox_active;
  10050. if (unlikely(!pmb)) {
  10051. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10052. "1832 No pending MBOX command to handle\n");
  10053. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10054. goto out_no_mqe_complete;
  10055. }
  10056. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10057. mqe = &pmb->u.mqe;
  10058. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10059. mbox = phba->mbox;
  10060. vport = pmb->vport;
  10061. /* Reset heartbeat timer */
  10062. phba->last_completion_time = jiffies;
  10063. del_timer(&phba->sli.mbox_tmo);
  10064. /* Move mbox data to caller's mailbox region, do endian swapping */
  10065. if (pmb->mbox_cmpl && mbox)
  10066. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10067. /*
  10068. * For mcqe errors, conditionally move a modified error code to
  10069. * the mbox so that the error will not be missed.
  10070. */
  10071. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10072. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10073. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10074. bf_set(lpfc_mqe_status, mqe,
  10075. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10076. }
  10077. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10078. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10079. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10080. "MBOX dflt rpi: status:x%x rpi:x%x",
  10081. mcqe_status,
  10082. pmbox->un.varWords[0], 0);
  10083. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10084. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10085. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10086. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10087. * RID of the PPI using the same mbox buffer.
  10088. */
  10089. lpfc_unreg_login(phba, vport->vpi,
  10090. pmbox->un.varWords[0], pmb);
  10091. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10092. pmb->context1 = mp;
  10093. pmb->context2 = ndlp;
  10094. pmb->vport = vport;
  10095. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10096. if (rc != MBX_BUSY)
  10097. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10098. LOG_SLI, "0385 rc should "
  10099. "have been MBX_BUSY\n");
  10100. if (rc != MBX_NOT_FINISHED)
  10101. goto send_current_mbox;
  10102. }
  10103. }
  10104. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10105. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10106. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10107. /* There is mailbox completion work to do */
  10108. spin_lock_irqsave(&phba->hbalock, iflags);
  10109. __lpfc_mbox_cmpl_put(phba, pmb);
  10110. phba->work_ha |= HA_MBATT;
  10111. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10112. workposted = true;
  10113. send_current_mbox:
  10114. spin_lock_irqsave(&phba->hbalock, iflags);
  10115. /* Release the mailbox command posting token */
  10116. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10117. /* Setting active mailbox pointer need to be in sync to flag clear */
  10118. phba->sli.mbox_active = NULL;
  10119. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10120. /* Wake up worker thread to post the next pending mailbox command */
  10121. lpfc_worker_wake_up(phba);
  10122. out_no_mqe_complete:
  10123. if (bf_get(lpfc_trailer_consumed, mcqe))
  10124. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10125. return workposted;
  10126. }
  10127. /**
  10128. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10129. * @phba: Pointer to HBA context object.
  10130. * @cqe: Pointer to mailbox completion queue entry.
  10131. *
  10132. * This routine process a mailbox completion queue entry, it invokes the
  10133. * proper mailbox complete handling or asynchrous event handling routine
  10134. * according to the MCQE's async bit.
  10135. *
  10136. * Return: true if work posted to worker thread, otherwise false.
  10137. **/
  10138. static bool
  10139. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10140. {
  10141. struct lpfc_mcqe mcqe;
  10142. bool workposted;
  10143. /* Copy the mailbox MCQE and convert endian order as needed */
  10144. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10145. /* Invoke the proper event handling routine */
  10146. if (!bf_get(lpfc_trailer_async, &mcqe))
  10147. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10148. else
  10149. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10150. return workposted;
  10151. }
  10152. /**
  10153. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10154. * @phba: Pointer to HBA context object.
  10155. * @wcqe: Pointer to work-queue completion queue entry.
  10156. *
  10157. * This routine handles an ELS work-queue completion event.
  10158. *
  10159. * Return: true if work posted to worker thread, otherwise false.
  10160. **/
  10161. static bool
  10162. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  10163. struct lpfc_wcqe_complete *wcqe)
  10164. {
  10165. struct lpfc_iocbq *irspiocbq;
  10166. unsigned long iflags;
  10167. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  10168. /* Get an irspiocbq for later ELS response processing use */
  10169. irspiocbq = lpfc_sli_get_iocbq(phba);
  10170. if (!irspiocbq) {
  10171. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10172. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10173. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10174. pring->txq_cnt, phba->iocb_cnt,
  10175. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  10176. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  10177. return false;
  10178. }
  10179. /* Save off the slow-path queue event for work thread to process */
  10180. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10181. spin_lock_irqsave(&phba->hbalock, iflags);
  10182. list_add_tail(&irspiocbq->cq_event.list,
  10183. &phba->sli4_hba.sp_queue_event);
  10184. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10185. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10186. return true;
  10187. }
  10188. /**
  10189. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10190. * @phba: Pointer to HBA context object.
  10191. * @wcqe: Pointer to work-queue completion queue entry.
  10192. *
  10193. * This routine handles slow-path WQ entry comsumed event by invoking the
  10194. * proper WQ release routine to the slow-path WQ.
  10195. **/
  10196. static void
  10197. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10198. struct lpfc_wcqe_release *wcqe)
  10199. {
  10200. /* sanity check on queue memory */
  10201. if (unlikely(!phba->sli4_hba.els_wq))
  10202. return;
  10203. /* Check for the slow-path ELS work queue */
  10204. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10205. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10206. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10207. else
  10208. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10209. "2579 Slow-path wqe consume event carries "
  10210. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10211. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10212. phba->sli4_hba.els_wq->queue_id);
  10213. }
  10214. /**
  10215. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10216. * @phba: Pointer to HBA context object.
  10217. * @cq: Pointer to a WQ completion queue.
  10218. * @wcqe: Pointer to work-queue completion queue entry.
  10219. *
  10220. * This routine handles an XRI abort event.
  10221. *
  10222. * Return: true if work posted to worker thread, otherwise false.
  10223. **/
  10224. static bool
  10225. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10226. struct lpfc_queue *cq,
  10227. struct sli4_wcqe_xri_aborted *wcqe)
  10228. {
  10229. bool workposted = false;
  10230. struct lpfc_cq_event *cq_event;
  10231. unsigned long iflags;
  10232. /* Allocate a new internal CQ_EVENT entry */
  10233. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10234. if (!cq_event) {
  10235. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10236. "0602 Failed to allocate CQ_EVENT entry\n");
  10237. return false;
  10238. }
  10239. /* Move the CQE into the proper xri abort event list */
  10240. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10241. switch (cq->subtype) {
  10242. case LPFC_FCP:
  10243. spin_lock_irqsave(&phba->hbalock, iflags);
  10244. list_add_tail(&cq_event->list,
  10245. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10246. /* Set the fcp xri abort event flag */
  10247. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10248. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10249. workposted = true;
  10250. break;
  10251. case LPFC_ELS:
  10252. spin_lock_irqsave(&phba->hbalock, iflags);
  10253. list_add_tail(&cq_event->list,
  10254. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10255. /* Set the els xri abort event flag */
  10256. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10257. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10258. workposted = true;
  10259. break;
  10260. default:
  10261. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10262. "0603 Invalid work queue CQE subtype (x%x)\n",
  10263. cq->subtype);
  10264. workposted = false;
  10265. break;
  10266. }
  10267. return workposted;
  10268. }
  10269. /**
  10270. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10271. * @phba: Pointer to HBA context object.
  10272. * @rcqe: Pointer to receive-queue completion queue entry.
  10273. *
  10274. * This routine process a receive-queue completion queue entry.
  10275. *
  10276. * Return: true if work posted to worker thread, otherwise false.
  10277. **/
  10278. static bool
  10279. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10280. {
  10281. bool workposted = false;
  10282. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10283. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10284. struct hbq_dmabuf *dma_buf;
  10285. uint32_t status, rq_id;
  10286. unsigned long iflags;
  10287. /* sanity check on queue memory */
  10288. if (unlikely(!hrq) || unlikely(!drq))
  10289. return workposted;
  10290. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10291. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10292. else
  10293. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10294. if (rq_id != hrq->queue_id)
  10295. goto out;
  10296. status = bf_get(lpfc_rcqe_status, rcqe);
  10297. switch (status) {
  10298. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10299. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10300. "2537 Receive Frame Truncated!!\n");
  10301. case FC_STATUS_RQ_SUCCESS:
  10302. lpfc_sli4_rq_release(hrq, drq);
  10303. spin_lock_irqsave(&phba->hbalock, iflags);
  10304. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10305. if (!dma_buf) {
  10306. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10307. goto out;
  10308. }
  10309. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10310. /* save off the frame for the word thread to process */
  10311. list_add_tail(&dma_buf->cq_event.list,
  10312. &phba->sli4_hba.sp_queue_event);
  10313. /* Frame received */
  10314. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10315. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10316. workposted = true;
  10317. break;
  10318. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10319. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10320. /* Post more buffers if possible */
  10321. spin_lock_irqsave(&phba->hbalock, iflags);
  10322. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10323. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10324. workposted = true;
  10325. break;
  10326. }
  10327. out:
  10328. return workposted;
  10329. }
  10330. /**
  10331. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10332. * @phba: Pointer to HBA context object.
  10333. * @cq: Pointer to the completion queue.
  10334. * @wcqe: Pointer to a completion queue entry.
  10335. *
  10336. * This routine process a slow-path work-queue or receive queue completion queue
  10337. * entry.
  10338. *
  10339. * Return: true if work posted to worker thread, otherwise false.
  10340. **/
  10341. static bool
  10342. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10343. struct lpfc_cqe *cqe)
  10344. {
  10345. struct lpfc_cqe cqevt;
  10346. bool workposted = false;
  10347. /* Copy the work queue CQE and convert endian order if needed */
  10348. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10349. /* Check and process for different type of WCQE and dispatch */
  10350. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10351. case CQE_CODE_COMPL_WQE:
  10352. /* Process the WQ/RQ complete event */
  10353. phba->last_completion_time = jiffies;
  10354. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  10355. (struct lpfc_wcqe_complete *)&cqevt);
  10356. break;
  10357. case CQE_CODE_RELEASE_WQE:
  10358. /* Process the WQ release event */
  10359. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10360. (struct lpfc_wcqe_release *)&cqevt);
  10361. break;
  10362. case CQE_CODE_XRI_ABORTED:
  10363. /* Process the WQ XRI abort event */
  10364. phba->last_completion_time = jiffies;
  10365. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10366. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10367. break;
  10368. case CQE_CODE_RECEIVE:
  10369. case CQE_CODE_RECEIVE_V1:
  10370. /* Process the RQ event */
  10371. phba->last_completion_time = jiffies;
  10372. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10373. (struct lpfc_rcqe *)&cqevt);
  10374. break;
  10375. default:
  10376. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10377. "0388 Not a valid WCQE code: x%x\n",
  10378. bf_get(lpfc_cqe_code, &cqevt));
  10379. break;
  10380. }
  10381. return workposted;
  10382. }
  10383. /**
  10384. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10385. * @phba: Pointer to HBA context object.
  10386. * @eqe: Pointer to fast-path event queue entry.
  10387. *
  10388. * This routine process a event queue entry from the slow-path event queue.
  10389. * It will check the MajorCode and MinorCode to determine this is for a
  10390. * completion event on a completion queue, if not, an error shall be logged
  10391. * and just return. Otherwise, it will get to the corresponding completion
  10392. * queue and process all the entries on that completion queue, rearm the
  10393. * completion queue, and then return.
  10394. *
  10395. **/
  10396. static void
  10397. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  10398. {
  10399. struct lpfc_queue *cq = NULL, *childq, *speq;
  10400. struct lpfc_cqe *cqe;
  10401. bool workposted = false;
  10402. int ecount = 0;
  10403. uint16_t cqid;
  10404. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  10405. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10406. "0359 Not a valid slow-path completion "
  10407. "event: majorcode=x%x, minorcode=x%x\n",
  10408. bf_get_le32(lpfc_eqe_major_code, eqe),
  10409. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10410. return;
  10411. }
  10412. /* Get the reference to the corresponding CQ */
  10413. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10414. /* Search for completion queue pointer matching this cqid */
  10415. speq = phba->sli4_hba.sp_eq;
  10416. /* sanity check on queue memory */
  10417. if (unlikely(!speq))
  10418. return;
  10419. list_for_each_entry(childq, &speq->child_list, list) {
  10420. if (childq->queue_id == cqid) {
  10421. cq = childq;
  10422. break;
  10423. }
  10424. }
  10425. if (unlikely(!cq)) {
  10426. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10427. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10428. "0365 Slow-path CQ identifier "
  10429. "(%d) does not exist\n", cqid);
  10430. return;
  10431. }
  10432. /* Process all the entries to the CQ */
  10433. switch (cq->type) {
  10434. case LPFC_MCQ:
  10435. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10436. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10437. if (!(++ecount % cq->entry_repost))
  10438. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10439. }
  10440. break;
  10441. case LPFC_WCQ:
  10442. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10443. if (cq->subtype == LPFC_FCP)
  10444. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10445. cqe);
  10446. else
  10447. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10448. cqe);
  10449. if (!(++ecount % cq->entry_repost))
  10450. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10451. }
  10452. break;
  10453. default:
  10454. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10455. "0370 Invalid completion queue type (%d)\n",
  10456. cq->type);
  10457. return;
  10458. }
  10459. /* Catch the no cq entry condition, log an error */
  10460. if (unlikely(ecount == 0))
  10461. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10462. "0371 No entry from the CQ: identifier "
  10463. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10464. /* In any case, flash and re-arm the RCQ */
  10465. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10466. /* wake up worker thread if there are works to be done */
  10467. if (workposted)
  10468. lpfc_worker_wake_up(phba);
  10469. }
  10470. /**
  10471. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10472. * @eqe: Pointer to fast-path completion queue entry.
  10473. *
  10474. * This routine process a fast-path work queue completion entry from fast-path
  10475. * event queue for FCP command response completion.
  10476. **/
  10477. static void
  10478. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  10479. struct lpfc_wcqe_complete *wcqe)
  10480. {
  10481. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  10482. struct lpfc_iocbq *cmdiocbq;
  10483. struct lpfc_iocbq irspiocbq;
  10484. unsigned long iflags;
  10485. spin_lock_irqsave(&phba->hbalock, iflags);
  10486. pring->stats.iocb_event++;
  10487. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10488. /* Check for response status */
  10489. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10490. /* If resource errors reported from HBA, reduce queue
  10491. * depth of the SCSI device.
  10492. */
  10493. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10494. IOSTAT_LOCAL_REJECT) &&
  10495. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  10496. phba->lpfc_rampdown_queue_depth(phba);
  10497. }
  10498. /* Log the error status */
  10499. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10500. "0373 FCP complete error: status=x%x, "
  10501. "hw_status=x%x, total_data_specified=%d, "
  10502. "parameter=x%x, word3=x%x\n",
  10503. bf_get(lpfc_wcqe_c_status, wcqe),
  10504. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10505. wcqe->total_data_placed, wcqe->parameter,
  10506. wcqe->word3);
  10507. }
  10508. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10509. spin_lock_irqsave(&phba->hbalock, iflags);
  10510. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10511. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10512. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10513. if (unlikely(!cmdiocbq)) {
  10514. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10515. "0374 FCP complete with no corresponding "
  10516. "cmdiocb: iotag (%d)\n",
  10517. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10518. return;
  10519. }
  10520. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10521. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10522. "0375 FCP cmdiocb not callback function "
  10523. "iotag: (%d)\n",
  10524. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10525. return;
  10526. }
  10527. /* Fake the irspiocb and copy necessary response information */
  10528. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10529. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10530. spin_lock_irqsave(&phba->hbalock, iflags);
  10531. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10532. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10533. }
  10534. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10535. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10536. }
  10537. /**
  10538. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10539. * @phba: Pointer to HBA context object.
  10540. * @cq: Pointer to completion queue.
  10541. * @wcqe: Pointer to work-queue completion queue entry.
  10542. *
  10543. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10544. * proper WQ release routine to the slow-path WQ.
  10545. **/
  10546. static void
  10547. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10548. struct lpfc_wcqe_release *wcqe)
  10549. {
  10550. struct lpfc_queue *childwq;
  10551. bool wqid_matched = false;
  10552. uint16_t fcp_wqid;
  10553. /* Check for fast-path FCP work queue release */
  10554. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10555. list_for_each_entry(childwq, &cq->child_list, list) {
  10556. if (childwq->queue_id == fcp_wqid) {
  10557. lpfc_sli4_wq_release(childwq,
  10558. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10559. wqid_matched = true;
  10560. break;
  10561. }
  10562. }
  10563. /* Report warning log message if no match found */
  10564. if (wqid_matched != true)
  10565. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10566. "2580 Fast-path wqe consume event carries "
  10567. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10568. }
  10569. /**
  10570. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10571. * @cq: Pointer to the completion queue.
  10572. * @eqe: Pointer to fast-path completion queue entry.
  10573. *
  10574. * This routine process a fast-path work queue completion entry from fast-path
  10575. * event queue for FCP command response completion.
  10576. **/
  10577. static int
  10578. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10579. struct lpfc_cqe *cqe)
  10580. {
  10581. struct lpfc_wcqe_release wcqe;
  10582. bool workposted = false;
  10583. /* Copy the work queue CQE and convert endian order if needed */
  10584. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10585. /* Check and process for different type of WCQE and dispatch */
  10586. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10587. case CQE_CODE_COMPL_WQE:
  10588. /* Process the WQ complete event */
  10589. phba->last_completion_time = jiffies;
  10590. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  10591. (struct lpfc_wcqe_complete *)&wcqe);
  10592. break;
  10593. case CQE_CODE_RELEASE_WQE:
  10594. /* Process the WQ release event */
  10595. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10596. (struct lpfc_wcqe_release *)&wcqe);
  10597. break;
  10598. case CQE_CODE_XRI_ABORTED:
  10599. /* Process the WQ XRI abort event */
  10600. phba->last_completion_time = jiffies;
  10601. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10602. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10603. break;
  10604. default:
  10605. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10606. "0144 Not a valid WCQE code: x%x\n",
  10607. bf_get(lpfc_wcqe_c_code, &wcqe));
  10608. break;
  10609. }
  10610. return workposted;
  10611. }
  10612. /**
  10613. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  10614. * @phba: Pointer to HBA context object.
  10615. * @eqe: Pointer to fast-path event queue entry.
  10616. *
  10617. * This routine process a event queue entry from the fast-path event queue.
  10618. * It will check the MajorCode and MinorCode to determine this is for a
  10619. * completion event on a completion queue, if not, an error shall be logged
  10620. * and just return. Otherwise, it will get to the corresponding completion
  10621. * queue and process all the entries on the completion queue, rearm the
  10622. * completion queue, and then return.
  10623. **/
  10624. static void
  10625. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10626. uint32_t fcp_cqidx)
  10627. {
  10628. struct lpfc_queue *cq;
  10629. struct lpfc_cqe *cqe;
  10630. bool workposted = false;
  10631. uint16_t cqid;
  10632. int ecount = 0;
  10633. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10634. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10635. "0366 Not a valid fast-path completion "
  10636. "event: majorcode=x%x, minorcode=x%x\n",
  10637. bf_get_le32(lpfc_eqe_major_code, eqe),
  10638. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10639. return;
  10640. }
  10641. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  10642. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10643. "3146 Fast-path completion queues "
  10644. "does not exist\n");
  10645. return;
  10646. }
  10647. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  10648. if (unlikely(!cq)) {
  10649. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10650. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10651. "0367 Fast-path completion queue "
  10652. "(%d) does not exist\n", fcp_cqidx);
  10653. return;
  10654. }
  10655. /* Get the reference to the corresponding CQ */
  10656. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10657. if (unlikely(cqid != cq->queue_id)) {
  10658. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10659. "0368 Miss-matched fast-path completion "
  10660. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10661. cqid, cq->queue_id);
  10662. return;
  10663. }
  10664. /* Process all the entries to the CQ */
  10665. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10666. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10667. if (!(++ecount % cq->entry_repost))
  10668. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10669. }
  10670. /* Catch the no cq entry condition */
  10671. if (unlikely(ecount == 0))
  10672. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10673. "0369 No entry from fast-path completion "
  10674. "queue fcpcqid=%d\n", cq->queue_id);
  10675. /* In any case, flash and re-arm the CQ */
  10676. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10677. /* wake up worker thread if there are works to be done */
  10678. if (workposted)
  10679. lpfc_worker_wake_up(phba);
  10680. }
  10681. static void
  10682. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10683. {
  10684. struct lpfc_eqe *eqe;
  10685. /* walk all the EQ entries and drop on the floor */
  10686. while ((eqe = lpfc_sli4_eq_get(eq)))
  10687. ;
  10688. /* Clear and re-arm the EQ */
  10689. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10690. }
  10691. /**
  10692. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  10693. * @irq: Interrupt number.
  10694. * @dev_id: The device context pointer.
  10695. *
  10696. * This function is directly called from the PCI layer as an interrupt
  10697. * service routine when device with SLI-4 interface spec is enabled with
  10698. * MSI-X multi-message interrupt mode and there are slow-path events in
  10699. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  10700. * interrupt mode, this function is called as part of the device-level
  10701. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  10702. * undergoing initialization, the interrupt handler will not process the
  10703. * interrupt. The link attention and ELS ring attention events are handled
  10704. * by the worker thread. The interrupt handler signals the worker thread
  10705. * and returns for these events. This function is called without any lock
  10706. * held. It gets the hbalock to access and update SLI data structures.
  10707. *
  10708. * This function returns IRQ_HANDLED when interrupt is handled else it
  10709. * returns IRQ_NONE.
  10710. **/
  10711. irqreturn_t
  10712. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  10713. {
  10714. struct lpfc_hba *phba;
  10715. struct lpfc_queue *speq;
  10716. struct lpfc_eqe *eqe;
  10717. unsigned long iflag;
  10718. int ecount = 0;
  10719. /*
  10720. * Get the driver's phba structure from the dev_id
  10721. */
  10722. phba = (struct lpfc_hba *)dev_id;
  10723. if (unlikely(!phba))
  10724. return IRQ_NONE;
  10725. /* Get to the EQ struct associated with this vector */
  10726. speq = phba->sli4_hba.sp_eq;
  10727. if (unlikely(!speq))
  10728. return IRQ_NONE;
  10729. /* Check device state for handling interrupt */
  10730. if (unlikely(lpfc_intr_state_check(phba))) {
  10731. /* Check again for link_state with lock held */
  10732. spin_lock_irqsave(&phba->hbalock, iflag);
  10733. if (phba->link_state < LPFC_LINK_DOWN)
  10734. /* Flush, clear interrupt, and rearm the EQ */
  10735. lpfc_sli4_eq_flush(phba, speq);
  10736. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10737. return IRQ_NONE;
  10738. }
  10739. /*
  10740. * Process all the event on FCP slow-path EQ
  10741. */
  10742. while ((eqe = lpfc_sli4_eq_get(speq))) {
  10743. lpfc_sli4_sp_handle_eqe(phba, eqe);
  10744. if (!(++ecount % speq->entry_repost))
  10745. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  10746. }
  10747. /* Always clear and re-arm the slow-path EQ */
  10748. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  10749. /* Catch the no cq entry condition */
  10750. if (unlikely(ecount == 0)) {
  10751. if (phba->intr_type == MSIX)
  10752. /* MSI-X treated interrupt served as no EQ share INT */
  10753. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10754. "0357 MSI-X interrupt with no EQE\n");
  10755. else
  10756. /* Non MSI-X treated on interrupt as EQ share INT */
  10757. return IRQ_NONE;
  10758. }
  10759. return IRQ_HANDLED;
  10760. } /* lpfc_sli4_sp_intr_handler */
  10761. /**
  10762. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  10763. * @irq: Interrupt number.
  10764. * @dev_id: The device context pointer.
  10765. *
  10766. * This function is directly called from the PCI layer as an interrupt
  10767. * service routine when device with SLI-4 interface spec is enabled with
  10768. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10769. * ring event in the HBA. However, when the device is enabled with either
  10770. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10771. * device-level interrupt handler. When the PCI slot is in error recovery
  10772. * or the HBA is undergoing initialization, the interrupt handler will not
  10773. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10774. * the intrrupt context. This function is called without any lock held.
  10775. * It gets the hbalock to access and update SLI data structures. Note that,
  10776. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10777. * equal to that of FCP CQ index.
  10778. *
  10779. * This function returns IRQ_HANDLED when interrupt is handled else it
  10780. * returns IRQ_NONE.
  10781. **/
  10782. irqreturn_t
  10783. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  10784. {
  10785. struct lpfc_hba *phba;
  10786. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10787. struct lpfc_queue *fpeq;
  10788. struct lpfc_eqe *eqe;
  10789. unsigned long iflag;
  10790. int ecount = 0;
  10791. uint32_t fcp_eqidx;
  10792. /* Get the driver's phba structure from the dev_id */
  10793. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10794. phba = fcp_eq_hdl->phba;
  10795. fcp_eqidx = fcp_eq_hdl->idx;
  10796. if (unlikely(!phba))
  10797. return IRQ_NONE;
  10798. if (unlikely(!phba->sli4_hba.fp_eq))
  10799. return IRQ_NONE;
  10800. /* Get to the EQ struct associated with this vector */
  10801. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  10802. if (unlikely(!fpeq))
  10803. return IRQ_NONE;
  10804. /* Check device state for handling interrupt */
  10805. if (unlikely(lpfc_intr_state_check(phba))) {
  10806. /* Check again for link_state with lock held */
  10807. spin_lock_irqsave(&phba->hbalock, iflag);
  10808. if (phba->link_state < LPFC_LINK_DOWN)
  10809. /* Flush, clear interrupt, and rearm the EQ */
  10810. lpfc_sli4_eq_flush(phba, fpeq);
  10811. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10812. return IRQ_NONE;
  10813. }
  10814. /*
  10815. * Process all the event on FCP fast-path EQ
  10816. */
  10817. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10818. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  10819. if (!(++ecount % fpeq->entry_repost))
  10820. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10821. }
  10822. /* Always clear and re-arm the fast-path EQ */
  10823. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  10824. if (unlikely(ecount == 0)) {
  10825. if (phba->intr_type == MSIX)
  10826. /* MSI-X treated interrupt served as no EQ share INT */
  10827. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10828. "0358 MSI-X interrupt with no EQE\n");
  10829. else
  10830. /* Non MSI-X treated on interrupt as EQ share INT */
  10831. return IRQ_NONE;
  10832. }
  10833. return IRQ_HANDLED;
  10834. } /* lpfc_sli4_fp_intr_handler */
  10835. /**
  10836. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10837. * @irq: Interrupt number.
  10838. * @dev_id: The device context pointer.
  10839. *
  10840. * This function is the device-level interrupt handler to device with SLI-4
  10841. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10842. * interrupt mode is enabled and there is an event in the HBA which requires
  10843. * driver attention. This function invokes the slow-path interrupt attention
  10844. * handling function and fast-path interrupt attention handling function in
  10845. * turn to process the relevant HBA attention events. This function is called
  10846. * without any lock held. It gets the hbalock to access and update SLI data
  10847. * structures.
  10848. *
  10849. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10850. * returns IRQ_NONE.
  10851. **/
  10852. irqreturn_t
  10853. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10854. {
  10855. struct lpfc_hba *phba;
  10856. irqreturn_t sp_irq_rc, fp_irq_rc;
  10857. bool fp_handled = false;
  10858. uint32_t fcp_eqidx;
  10859. /* Get the driver's phba structure from the dev_id */
  10860. phba = (struct lpfc_hba *)dev_id;
  10861. if (unlikely(!phba))
  10862. return IRQ_NONE;
  10863. /*
  10864. * Invokes slow-path host attention interrupt handling as appropriate.
  10865. */
  10866. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  10867. /*
  10868. * Invoke fast-path host attention interrupt handling as appropriate.
  10869. */
  10870. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  10871. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  10872. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10873. if (fp_irq_rc == IRQ_HANDLED)
  10874. fp_handled |= true;
  10875. }
  10876. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  10877. } /* lpfc_sli4_intr_handler */
  10878. /**
  10879. * lpfc_sli4_queue_free - free a queue structure and associated memory
  10880. * @queue: The queue structure to free.
  10881. *
  10882. * This function frees a queue structure and the DMAable memory used for
  10883. * the host resident queue. This function must be called after destroying the
  10884. * queue on the HBA.
  10885. **/
  10886. void
  10887. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  10888. {
  10889. struct lpfc_dmabuf *dmabuf;
  10890. if (!queue)
  10891. return;
  10892. while (!list_empty(&queue->page_list)) {
  10893. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  10894. list);
  10895. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  10896. dmabuf->virt, dmabuf->phys);
  10897. kfree(dmabuf);
  10898. }
  10899. kfree(queue);
  10900. return;
  10901. }
  10902. /**
  10903. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  10904. * @phba: The HBA that this queue is being created on.
  10905. * @entry_size: The size of each queue entry for this queue.
  10906. * @entry count: The number of entries that this queue will handle.
  10907. *
  10908. * This function allocates a queue structure and the DMAable memory used for
  10909. * the host resident queue. This function must be called before creating the
  10910. * queue on the HBA.
  10911. **/
  10912. struct lpfc_queue *
  10913. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  10914. uint32_t entry_count)
  10915. {
  10916. struct lpfc_queue *queue;
  10917. struct lpfc_dmabuf *dmabuf;
  10918. int x, total_qe_count;
  10919. void *dma_pointer;
  10920. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10921. if (!phba->sli4_hba.pc_sli4_params.supported)
  10922. hw_page_size = SLI4_PAGE_SIZE;
  10923. queue = kzalloc(sizeof(struct lpfc_queue) +
  10924. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  10925. if (!queue)
  10926. return NULL;
  10927. queue->page_count = (ALIGN(entry_size * entry_count,
  10928. hw_page_size))/hw_page_size;
  10929. INIT_LIST_HEAD(&queue->list);
  10930. INIT_LIST_HEAD(&queue->page_list);
  10931. INIT_LIST_HEAD(&queue->child_list);
  10932. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  10933. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  10934. if (!dmabuf)
  10935. goto out_fail;
  10936. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  10937. hw_page_size, &dmabuf->phys,
  10938. GFP_KERNEL);
  10939. if (!dmabuf->virt) {
  10940. kfree(dmabuf);
  10941. goto out_fail;
  10942. }
  10943. memset(dmabuf->virt, 0, hw_page_size);
  10944. dmabuf->buffer_tag = x;
  10945. list_add_tail(&dmabuf->list, &queue->page_list);
  10946. /* initialize queue's entry array */
  10947. dma_pointer = dmabuf->virt;
  10948. for (; total_qe_count < entry_count &&
  10949. dma_pointer < (hw_page_size + dmabuf->virt);
  10950. total_qe_count++, dma_pointer += entry_size) {
  10951. queue->qe[total_qe_count].address = dma_pointer;
  10952. }
  10953. }
  10954. queue->entry_size = entry_size;
  10955. queue->entry_count = entry_count;
  10956. /*
  10957. * entry_repost is calculated based on the number of entries in the
  10958. * queue. This works out except for RQs. If buffers are NOT initially
  10959. * posted for every RQE, entry_repost should be adjusted accordingly.
  10960. */
  10961. queue->entry_repost = (entry_count >> 3);
  10962. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  10963. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  10964. queue->phba = phba;
  10965. return queue;
  10966. out_fail:
  10967. lpfc_sli4_queue_free(queue);
  10968. return NULL;
  10969. }
  10970. /**
  10971. * lpfc_eq_create - Create an Event Queue on the HBA
  10972. * @phba: HBA structure that indicates port to create a queue on.
  10973. * @eq: The queue structure to use to create the event queue.
  10974. * @imax: The maximum interrupt per second limit.
  10975. *
  10976. * This function creates an event queue, as detailed in @eq, on a port,
  10977. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  10978. *
  10979. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  10980. * is used to get the entry count and entry size that are necessary to
  10981. * determine the number of pages to allocate and use for this queue. This
  10982. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  10983. * event queue. This function is asynchronous and will wait for the mailbox
  10984. * command to finish before continuing.
  10985. *
  10986. * On success this function will return a zero. If unable to allocate enough
  10987. * memory this function will return -ENOMEM. If the queue create mailbox command
  10988. * fails this function will return -ENXIO.
  10989. **/
  10990. uint32_t
  10991. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  10992. {
  10993. struct lpfc_mbx_eq_create *eq_create;
  10994. LPFC_MBOXQ_t *mbox;
  10995. int rc, length, status = 0;
  10996. struct lpfc_dmabuf *dmabuf;
  10997. uint32_t shdr_status, shdr_add_status;
  10998. union lpfc_sli4_cfg_shdr *shdr;
  10999. uint16_t dmult;
  11000. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11001. /* sanity check on queue memory */
  11002. if (!eq)
  11003. return -ENODEV;
  11004. if (!phba->sli4_hba.pc_sli4_params.supported)
  11005. hw_page_size = SLI4_PAGE_SIZE;
  11006. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11007. if (!mbox)
  11008. return -ENOMEM;
  11009. length = (sizeof(struct lpfc_mbx_eq_create) -
  11010. sizeof(struct lpfc_sli4_cfg_mhdr));
  11011. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11012. LPFC_MBOX_OPCODE_EQ_CREATE,
  11013. length, LPFC_SLI4_MBX_EMBED);
  11014. eq_create = &mbox->u.mqe.un.eq_create;
  11015. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11016. eq->page_count);
  11017. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11018. LPFC_EQE_SIZE);
  11019. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11020. /* Calculate delay multiper from maximum interrupt per second */
  11021. dmult = LPFC_DMULT_CONST/imax - 1;
  11022. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11023. dmult);
  11024. switch (eq->entry_count) {
  11025. default:
  11026. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11027. "0360 Unsupported EQ count. (%d)\n",
  11028. eq->entry_count);
  11029. if (eq->entry_count < 256)
  11030. return -EINVAL;
  11031. /* otherwise default to smallest count (drop through) */
  11032. case 256:
  11033. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11034. LPFC_EQ_CNT_256);
  11035. break;
  11036. case 512:
  11037. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11038. LPFC_EQ_CNT_512);
  11039. break;
  11040. case 1024:
  11041. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11042. LPFC_EQ_CNT_1024);
  11043. break;
  11044. case 2048:
  11045. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11046. LPFC_EQ_CNT_2048);
  11047. break;
  11048. case 4096:
  11049. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11050. LPFC_EQ_CNT_4096);
  11051. break;
  11052. }
  11053. list_for_each_entry(dmabuf, &eq->page_list, list) {
  11054. memset(dmabuf->virt, 0, hw_page_size);
  11055. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11056. putPaddrLow(dmabuf->phys);
  11057. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11058. putPaddrHigh(dmabuf->phys);
  11059. }
  11060. mbox->vport = phba->pport;
  11061. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11062. mbox->context1 = NULL;
  11063. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11064. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  11065. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11066. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11067. if (shdr_status || shdr_add_status || rc) {
  11068. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11069. "2500 EQ_CREATE mailbox failed with "
  11070. "status x%x add_status x%x, mbx status x%x\n",
  11071. shdr_status, shdr_add_status, rc);
  11072. status = -ENXIO;
  11073. }
  11074. eq->type = LPFC_EQ;
  11075. eq->subtype = LPFC_NONE;
  11076. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  11077. if (eq->queue_id == 0xFFFF)
  11078. status = -ENXIO;
  11079. eq->host_index = 0;
  11080. eq->hba_index = 0;
  11081. mempool_free(mbox, phba->mbox_mem_pool);
  11082. return status;
  11083. }
  11084. /**
  11085. * lpfc_cq_create - Create a Completion Queue on the HBA
  11086. * @phba: HBA structure that indicates port to create a queue on.
  11087. * @cq: The queue structure to use to create the completion queue.
  11088. * @eq: The event queue to bind this completion queue to.
  11089. *
  11090. * This function creates a completion queue, as detailed in @wq, on a port,
  11091. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  11092. *
  11093. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11094. * is used to get the entry count and entry size that are necessary to
  11095. * determine the number of pages to allocate and use for this queue. The @eq
  11096. * is used to indicate which event queue to bind this completion queue to. This
  11097. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  11098. * completion queue. This function is asynchronous and will wait for the mailbox
  11099. * command to finish before continuing.
  11100. *
  11101. * On success this function will return a zero. If unable to allocate enough
  11102. * memory this function will return -ENOMEM. If the queue create mailbox command
  11103. * fails this function will return -ENXIO.
  11104. **/
  11105. uint32_t
  11106. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11107. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  11108. {
  11109. struct lpfc_mbx_cq_create *cq_create;
  11110. struct lpfc_dmabuf *dmabuf;
  11111. LPFC_MBOXQ_t *mbox;
  11112. int rc, length, status = 0;
  11113. uint32_t shdr_status, shdr_add_status;
  11114. union lpfc_sli4_cfg_shdr *shdr;
  11115. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11116. /* sanity check on queue memory */
  11117. if (!cq || !eq)
  11118. return -ENODEV;
  11119. if (!phba->sli4_hba.pc_sli4_params.supported)
  11120. hw_page_size = SLI4_PAGE_SIZE;
  11121. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11122. if (!mbox)
  11123. return -ENOMEM;
  11124. length = (sizeof(struct lpfc_mbx_cq_create) -
  11125. sizeof(struct lpfc_sli4_cfg_mhdr));
  11126. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11127. LPFC_MBOX_OPCODE_CQ_CREATE,
  11128. length, LPFC_SLI4_MBX_EMBED);
  11129. cq_create = &mbox->u.mqe.un.cq_create;
  11130. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  11131. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  11132. cq->page_count);
  11133. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  11134. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  11135. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11136. phba->sli4_hba.pc_sli4_params.cqv);
  11137. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  11138. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  11139. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  11140. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  11141. eq->queue_id);
  11142. } else {
  11143. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  11144. eq->queue_id);
  11145. }
  11146. switch (cq->entry_count) {
  11147. default:
  11148. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11149. "0361 Unsupported CQ count. (%d)\n",
  11150. cq->entry_count);
  11151. if (cq->entry_count < 256)
  11152. return -EINVAL;
  11153. /* otherwise default to smallest count (drop through) */
  11154. case 256:
  11155. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11156. LPFC_CQ_CNT_256);
  11157. break;
  11158. case 512:
  11159. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11160. LPFC_CQ_CNT_512);
  11161. break;
  11162. case 1024:
  11163. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11164. LPFC_CQ_CNT_1024);
  11165. break;
  11166. }
  11167. list_for_each_entry(dmabuf, &cq->page_list, list) {
  11168. memset(dmabuf->virt, 0, hw_page_size);
  11169. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11170. putPaddrLow(dmabuf->phys);
  11171. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11172. putPaddrHigh(dmabuf->phys);
  11173. }
  11174. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11175. /* The IOCTL status is embedded in the mailbox subheader. */
  11176. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11177. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11178. if (shdr_status || shdr_add_status || rc) {
  11179. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11180. "2501 CQ_CREATE mailbox failed with "
  11181. "status x%x add_status x%x, mbx status x%x\n",
  11182. shdr_status, shdr_add_status, rc);
  11183. status = -ENXIO;
  11184. goto out;
  11185. }
  11186. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11187. if (cq->queue_id == 0xFFFF) {
  11188. status = -ENXIO;
  11189. goto out;
  11190. }
  11191. /* link the cq onto the parent eq child list */
  11192. list_add_tail(&cq->list, &eq->child_list);
  11193. /* Set up completion queue's type and subtype */
  11194. cq->type = type;
  11195. cq->subtype = subtype;
  11196. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11197. cq->assoc_qid = eq->queue_id;
  11198. cq->host_index = 0;
  11199. cq->hba_index = 0;
  11200. out:
  11201. mempool_free(mbox, phba->mbox_mem_pool);
  11202. return status;
  11203. }
  11204. /**
  11205. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  11206. * @phba: HBA structure that indicates port to create a queue on.
  11207. * @mq: The queue structure to use to create the mailbox queue.
  11208. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  11209. * @cq: The completion queue to associate with this cq.
  11210. *
  11211. * This function provides failback (fb) functionality when the
  11212. * mq_create_ext fails on older FW generations. It's purpose is identical
  11213. * to mq_create_ext otherwise.
  11214. *
  11215. * This routine cannot fail as all attributes were previously accessed and
  11216. * initialized in mq_create_ext.
  11217. **/
  11218. static void
  11219. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11220. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  11221. {
  11222. struct lpfc_mbx_mq_create *mq_create;
  11223. struct lpfc_dmabuf *dmabuf;
  11224. int length;
  11225. length = (sizeof(struct lpfc_mbx_mq_create) -
  11226. sizeof(struct lpfc_sli4_cfg_mhdr));
  11227. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11228. LPFC_MBOX_OPCODE_MQ_CREATE,
  11229. length, LPFC_SLI4_MBX_EMBED);
  11230. mq_create = &mbox->u.mqe.un.mq_create;
  11231. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  11232. mq->page_count);
  11233. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  11234. cq->queue_id);
  11235. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  11236. switch (mq->entry_count) {
  11237. case 16:
  11238. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11239. LPFC_MQ_RING_SIZE_16);
  11240. break;
  11241. case 32:
  11242. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11243. LPFC_MQ_RING_SIZE_32);
  11244. break;
  11245. case 64:
  11246. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11247. LPFC_MQ_RING_SIZE_64);
  11248. break;
  11249. case 128:
  11250. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11251. LPFC_MQ_RING_SIZE_128);
  11252. break;
  11253. }
  11254. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11255. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11256. putPaddrLow(dmabuf->phys);
  11257. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11258. putPaddrHigh(dmabuf->phys);
  11259. }
  11260. }
  11261. /**
  11262. * lpfc_mq_create - Create a mailbox Queue on the HBA
  11263. * @phba: HBA structure that indicates port to create a queue on.
  11264. * @mq: The queue structure to use to create the mailbox queue.
  11265. * @cq: The completion queue to associate with this cq.
  11266. * @subtype: The queue's subtype.
  11267. *
  11268. * This function creates a mailbox queue, as detailed in @mq, on a port,
  11269. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  11270. *
  11271. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11272. * is used to get the entry count and entry size that are necessary to
  11273. * determine the number of pages to allocate and use for this queue. This
  11274. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  11275. * mailbox queue. This function is asynchronous and will wait for the mailbox
  11276. * command to finish before continuing.
  11277. *
  11278. * On success this function will return a zero. If unable to allocate enough
  11279. * memory this function will return -ENOMEM. If the queue create mailbox command
  11280. * fails this function will return -ENXIO.
  11281. **/
  11282. int32_t
  11283. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11284. struct lpfc_queue *cq, uint32_t subtype)
  11285. {
  11286. struct lpfc_mbx_mq_create *mq_create;
  11287. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11288. struct lpfc_dmabuf *dmabuf;
  11289. LPFC_MBOXQ_t *mbox;
  11290. int rc, length, status = 0;
  11291. uint32_t shdr_status, shdr_add_status;
  11292. union lpfc_sli4_cfg_shdr *shdr;
  11293. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11294. /* sanity check on queue memory */
  11295. if (!mq || !cq)
  11296. return -ENODEV;
  11297. if (!phba->sli4_hba.pc_sli4_params.supported)
  11298. hw_page_size = SLI4_PAGE_SIZE;
  11299. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11300. if (!mbox)
  11301. return -ENOMEM;
  11302. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11303. sizeof(struct lpfc_sli4_cfg_mhdr));
  11304. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11305. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11306. length, LPFC_SLI4_MBX_EMBED);
  11307. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11308. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11309. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11310. &mq_create_ext->u.request, mq->page_count);
  11311. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11312. &mq_create_ext->u.request, 1);
  11313. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11314. &mq_create_ext->u.request, 1);
  11315. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11316. &mq_create_ext->u.request, 1);
  11317. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11318. &mq_create_ext->u.request, 1);
  11319. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11320. &mq_create_ext->u.request, 1);
  11321. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11322. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11323. phba->sli4_hba.pc_sli4_params.mqv);
  11324. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11325. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11326. cq->queue_id);
  11327. else
  11328. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11329. cq->queue_id);
  11330. switch (mq->entry_count) {
  11331. default:
  11332. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11333. "0362 Unsupported MQ count. (%d)\n",
  11334. mq->entry_count);
  11335. if (mq->entry_count < 16)
  11336. return -EINVAL;
  11337. /* otherwise default to smallest count (drop through) */
  11338. case 16:
  11339. bf_set(lpfc_mq_context_ring_size,
  11340. &mq_create_ext->u.request.context,
  11341. LPFC_MQ_RING_SIZE_16);
  11342. break;
  11343. case 32:
  11344. bf_set(lpfc_mq_context_ring_size,
  11345. &mq_create_ext->u.request.context,
  11346. LPFC_MQ_RING_SIZE_32);
  11347. break;
  11348. case 64:
  11349. bf_set(lpfc_mq_context_ring_size,
  11350. &mq_create_ext->u.request.context,
  11351. LPFC_MQ_RING_SIZE_64);
  11352. break;
  11353. case 128:
  11354. bf_set(lpfc_mq_context_ring_size,
  11355. &mq_create_ext->u.request.context,
  11356. LPFC_MQ_RING_SIZE_128);
  11357. break;
  11358. }
  11359. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11360. memset(dmabuf->virt, 0, hw_page_size);
  11361. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11362. putPaddrLow(dmabuf->phys);
  11363. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11364. putPaddrHigh(dmabuf->phys);
  11365. }
  11366. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11367. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11368. &mq_create_ext->u.response);
  11369. if (rc != MBX_SUCCESS) {
  11370. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11371. "2795 MQ_CREATE_EXT failed with "
  11372. "status x%x. Failback to MQ_CREATE.\n",
  11373. rc);
  11374. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11375. mq_create = &mbox->u.mqe.un.mq_create;
  11376. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11377. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11378. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11379. &mq_create->u.response);
  11380. }
  11381. /* The IOCTL status is embedded in the mailbox subheader. */
  11382. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11383. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11384. if (shdr_status || shdr_add_status || rc) {
  11385. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11386. "2502 MQ_CREATE mailbox failed with "
  11387. "status x%x add_status x%x, mbx status x%x\n",
  11388. shdr_status, shdr_add_status, rc);
  11389. status = -ENXIO;
  11390. goto out;
  11391. }
  11392. if (mq->queue_id == 0xFFFF) {
  11393. status = -ENXIO;
  11394. goto out;
  11395. }
  11396. mq->type = LPFC_MQ;
  11397. mq->assoc_qid = cq->queue_id;
  11398. mq->subtype = subtype;
  11399. mq->host_index = 0;
  11400. mq->hba_index = 0;
  11401. /* link the mq onto the parent cq child list */
  11402. list_add_tail(&mq->list, &cq->child_list);
  11403. out:
  11404. mempool_free(mbox, phba->mbox_mem_pool);
  11405. return status;
  11406. }
  11407. /**
  11408. * lpfc_wq_create - Create a Work Queue on the HBA
  11409. * @phba: HBA structure that indicates port to create a queue on.
  11410. * @wq: The queue structure to use to create the work queue.
  11411. * @cq: The completion queue to bind this work queue to.
  11412. * @subtype: The subtype of the work queue indicating its functionality.
  11413. *
  11414. * This function creates a work queue, as detailed in @wq, on a port, described
  11415. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11416. *
  11417. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11418. * is used to get the entry count and entry size that are necessary to
  11419. * determine the number of pages to allocate and use for this queue. The @cq
  11420. * is used to indicate which completion queue to bind this work queue to. This
  11421. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11422. * work queue. This function is asynchronous and will wait for the mailbox
  11423. * command to finish before continuing.
  11424. *
  11425. * On success this function will return a zero. If unable to allocate enough
  11426. * memory this function will return -ENOMEM. If the queue create mailbox command
  11427. * fails this function will return -ENXIO.
  11428. **/
  11429. uint32_t
  11430. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11431. struct lpfc_queue *cq, uint32_t subtype)
  11432. {
  11433. struct lpfc_mbx_wq_create *wq_create;
  11434. struct lpfc_dmabuf *dmabuf;
  11435. LPFC_MBOXQ_t *mbox;
  11436. int rc, length, status = 0;
  11437. uint32_t shdr_status, shdr_add_status;
  11438. union lpfc_sli4_cfg_shdr *shdr;
  11439. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11440. struct dma_address *page;
  11441. /* sanity check on queue memory */
  11442. if (!wq || !cq)
  11443. return -ENODEV;
  11444. if (!phba->sli4_hba.pc_sli4_params.supported)
  11445. hw_page_size = SLI4_PAGE_SIZE;
  11446. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11447. if (!mbox)
  11448. return -ENOMEM;
  11449. length = (sizeof(struct lpfc_mbx_wq_create) -
  11450. sizeof(struct lpfc_sli4_cfg_mhdr));
  11451. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11452. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11453. length, LPFC_SLI4_MBX_EMBED);
  11454. wq_create = &mbox->u.mqe.un.wq_create;
  11455. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11456. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11457. wq->page_count);
  11458. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11459. cq->queue_id);
  11460. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11461. phba->sli4_hba.pc_sli4_params.wqv);
  11462. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11463. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11464. wq->entry_count);
  11465. switch (wq->entry_size) {
  11466. default:
  11467. case 64:
  11468. bf_set(lpfc_mbx_wq_create_wqe_size,
  11469. &wq_create->u.request_1,
  11470. LPFC_WQ_WQE_SIZE_64);
  11471. break;
  11472. case 128:
  11473. bf_set(lpfc_mbx_wq_create_wqe_size,
  11474. &wq_create->u.request_1,
  11475. LPFC_WQ_WQE_SIZE_128);
  11476. break;
  11477. }
  11478. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11479. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11480. page = wq_create->u.request_1.page;
  11481. } else {
  11482. page = wq_create->u.request.page;
  11483. }
  11484. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11485. memset(dmabuf->virt, 0, hw_page_size);
  11486. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11487. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11488. }
  11489. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11490. /* The IOCTL status is embedded in the mailbox subheader. */
  11491. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11492. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11493. if (shdr_status || shdr_add_status || rc) {
  11494. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11495. "2503 WQ_CREATE mailbox failed with "
  11496. "status x%x add_status x%x, mbx status x%x\n",
  11497. shdr_status, shdr_add_status, rc);
  11498. status = -ENXIO;
  11499. goto out;
  11500. }
  11501. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11502. if (wq->queue_id == 0xFFFF) {
  11503. status = -ENXIO;
  11504. goto out;
  11505. }
  11506. wq->type = LPFC_WQ;
  11507. wq->assoc_qid = cq->queue_id;
  11508. wq->subtype = subtype;
  11509. wq->host_index = 0;
  11510. wq->hba_index = 0;
  11511. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11512. /* link the wq onto the parent cq child list */
  11513. list_add_tail(&wq->list, &cq->child_list);
  11514. out:
  11515. mempool_free(mbox, phba->mbox_mem_pool);
  11516. return status;
  11517. }
  11518. /**
  11519. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11520. * @phba: HBA structure that indicates port to create a queue on.
  11521. * @rq: The queue structure to use for the receive queue.
  11522. * @qno: The associated HBQ number
  11523. *
  11524. *
  11525. * For SLI4 we need to adjust the RQ repost value based on
  11526. * the number of buffers that are initially posted to the RQ.
  11527. */
  11528. void
  11529. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11530. {
  11531. uint32_t cnt;
  11532. /* sanity check on queue memory */
  11533. if (!rq)
  11534. return;
  11535. cnt = lpfc_hbq_defs[qno]->entry_count;
  11536. /* Recalc repost for RQs based on buffers initially posted */
  11537. cnt = (cnt >> 3);
  11538. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11539. cnt = LPFC_QUEUE_MIN_REPOST;
  11540. rq->entry_repost = cnt;
  11541. }
  11542. /**
  11543. * lpfc_rq_create - Create a Receive Queue on the HBA
  11544. * @phba: HBA structure that indicates port to create a queue on.
  11545. * @hrq: The queue structure to use to create the header receive queue.
  11546. * @drq: The queue structure to use to create the data receive queue.
  11547. * @cq: The completion queue to bind this work queue to.
  11548. *
  11549. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11550. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11551. * to the HBA.
  11552. *
  11553. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11554. * struct is used to get the entry count that is necessary to determine the
  11555. * number of pages to use for this queue. The @cq is used to indicate which
  11556. * completion queue to bind received buffers that are posted to these queues to.
  11557. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11558. * receive queue pair. This function is asynchronous and will wait for the
  11559. * mailbox command to finish before continuing.
  11560. *
  11561. * On success this function will return a zero. If unable to allocate enough
  11562. * memory this function will return -ENOMEM. If the queue create mailbox command
  11563. * fails this function will return -ENXIO.
  11564. **/
  11565. uint32_t
  11566. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11567. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11568. {
  11569. struct lpfc_mbx_rq_create *rq_create;
  11570. struct lpfc_dmabuf *dmabuf;
  11571. LPFC_MBOXQ_t *mbox;
  11572. int rc, length, status = 0;
  11573. uint32_t shdr_status, shdr_add_status;
  11574. union lpfc_sli4_cfg_shdr *shdr;
  11575. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11576. /* sanity check on queue memory */
  11577. if (!hrq || !drq || !cq)
  11578. return -ENODEV;
  11579. if (!phba->sli4_hba.pc_sli4_params.supported)
  11580. hw_page_size = SLI4_PAGE_SIZE;
  11581. if (hrq->entry_count != drq->entry_count)
  11582. return -EINVAL;
  11583. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11584. if (!mbox)
  11585. return -ENOMEM;
  11586. length = (sizeof(struct lpfc_mbx_rq_create) -
  11587. sizeof(struct lpfc_sli4_cfg_mhdr));
  11588. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11589. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11590. length, LPFC_SLI4_MBX_EMBED);
  11591. rq_create = &mbox->u.mqe.un.rq_create;
  11592. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11593. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11594. phba->sli4_hba.pc_sli4_params.rqv);
  11595. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11596. bf_set(lpfc_rq_context_rqe_count_1,
  11597. &rq_create->u.request.context,
  11598. hrq->entry_count);
  11599. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11600. bf_set(lpfc_rq_context_rqe_size,
  11601. &rq_create->u.request.context,
  11602. LPFC_RQE_SIZE_8);
  11603. bf_set(lpfc_rq_context_page_size,
  11604. &rq_create->u.request.context,
  11605. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11606. } else {
  11607. switch (hrq->entry_count) {
  11608. default:
  11609. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11610. "2535 Unsupported RQ count. (%d)\n",
  11611. hrq->entry_count);
  11612. if (hrq->entry_count < 512)
  11613. return -EINVAL;
  11614. /* otherwise default to smallest count (drop through) */
  11615. case 512:
  11616. bf_set(lpfc_rq_context_rqe_count,
  11617. &rq_create->u.request.context,
  11618. LPFC_RQ_RING_SIZE_512);
  11619. break;
  11620. case 1024:
  11621. bf_set(lpfc_rq_context_rqe_count,
  11622. &rq_create->u.request.context,
  11623. LPFC_RQ_RING_SIZE_1024);
  11624. break;
  11625. case 2048:
  11626. bf_set(lpfc_rq_context_rqe_count,
  11627. &rq_create->u.request.context,
  11628. LPFC_RQ_RING_SIZE_2048);
  11629. break;
  11630. case 4096:
  11631. bf_set(lpfc_rq_context_rqe_count,
  11632. &rq_create->u.request.context,
  11633. LPFC_RQ_RING_SIZE_4096);
  11634. break;
  11635. }
  11636. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11637. LPFC_HDR_BUF_SIZE);
  11638. }
  11639. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11640. cq->queue_id);
  11641. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11642. hrq->page_count);
  11643. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11644. memset(dmabuf->virt, 0, hw_page_size);
  11645. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11646. putPaddrLow(dmabuf->phys);
  11647. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11648. putPaddrHigh(dmabuf->phys);
  11649. }
  11650. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11651. /* The IOCTL status is embedded in the mailbox subheader. */
  11652. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11653. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11654. if (shdr_status || shdr_add_status || rc) {
  11655. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11656. "2504 RQ_CREATE mailbox failed with "
  11657. "status x%x add_status x%x, mbx status x%x\n",
  11658. shdr_status, shdr_add_status, rc);
  11659. status = -ENXIO;
  11660. goto out;
  11661. }
  11662. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11663. if (hrq->queue_id == 0xFFFF) {
  11664. status = -ENXIO;
  11665. goto out;
  11666. }
  11667. hrq->type = LPFC_HRQ;
  11668. hrq->assoc_qid = cq->queue_id;
  11669. hrq->subtype = subtype;
  11670. hrq->host_index = 0;
  11671. hrq->hba_index = 0;
  11672. /* now create the data queue */
  11673. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11674. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11675. length, LPFC_SLI4_MBX_EMBED);
  11676. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11677. phba->sli4_hba.pc_sli4_params.rqv);
  11678. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11679. bf_set(lpfc_rq_context_rqe_count_1,
  11680. &rq_create->u.request.context, hrq->entry_count);
  11681. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  11682. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  11683. LPFC_RQE_SIZE_8);
  11684. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  11685. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11686. } else {
  11687. switch (drq->entry_count) {
  11688. default:
  11689. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11690. "2536 Unsupported RQ count. (%d)\n",
  11691. drq->entry_count);
  11692. if (drq->entry_count < 512)
  11693. return -EINVAL;
  11694. /* otherwise default to smallest count (drop through) */
  11695. case 512:
  11696. bf_set(lpfc_rq_context_rqe_count,
  11697. &rq_create->u.request.context,
  11698. LPFC_RQ_RING_SIZE_512);
  11699. break;
  11700. case 1024:
  11701. bf_set(lpfc_rq_context_rqe_count,
  11702. &rq_create->u.request.context,
  11703. LPFC_RQ_RING_SIZE_1024);
  11704. break;
  11705. case 2048:
  11706. bf_set(lpfc_rq_context_rqe_count,
  11707. &rq_create->u.request.context,
  11708. LPFC_RQ_RING_SIZE_2048);
  11709. break;
  11710. case 4096:
  11711. bf_set(lpfc_rq_context_rqe_count,
  11712. &rq_create->u.request.context,
  11713. LPFC_RQ_RING_SIZE_4096);
  11714. break;
  11715. }
  11716. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11717. LPFC_DATA_BUF_SIZE);
  11718. }
  11719. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11720. cq->queue_id);
  11721. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11722. drq->page_count);
  11723. list_for_each_entry(dmabuf, &drq->page_list, list) {
  11724. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11725. putPaddrLow(dmabuf->phys);
  11726. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11727. putPaddrHigh(dmabuf->phys);
  11728. }
  11729. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11730. /* The IOCTL status is embedded in the mailbox subheader. */
  11731. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11732. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11733. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11734. if (shdr_status || shdr_add_status || rc) {
  11735. status = -ENXIO;
  11736. goto out;
  11737. }
  11738. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11739. if (drq->queue_id == 0xFFFF) {
  11740. status = -ENXIO;
  11741. goto out;
  11742. }
  11743. drq->type = LPFC_DRQ;
  11744. drq->assoc_qid = cq->queue_id;
  11745. drq->subtype = subtype;
  11746. drq->host_index = 0;
  11747. drq->hba_index = 0;
  11748. /* link the header and data RQs onto the parent cq child list */
  11749. list_add_tail(&hrq->list, &cq->child_list);
  11750. list_add_tail(&drq->list, &cq->child_list);
  11751. out:
  11752. mempool_free(mbox, phba->mbox_mem_pool);
  11753. return status;
  11754. }
  11755. /**
  11756. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  11757. * @eq: The queue structure associated with the queue to destroy.
  11758. *
  11759. * This function destroys a queue, as detailed in @eq by sending an mailbox
  11760. * command, specific to the type of queue, to the HBA.
  11761. *
  11762. * The @eq struct is used to get the queue ID of the queue to destroy.
  11763. *
  11764. * On success this function will return a zero. If the queue destroy mailbox
  11765. * command fails this function will return -ENXIO.
  11766. **/
  11767. uint32_t
  11768. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11769. {
  11770. LPFC_MBOXQ_t *mbox;
  11771. int rc, length, status = 0;
  11772. uint32_t shdr_status, shdr_add_status;
  11773. union lpfc_sli4_cfg_shdr *shdr;
  11774. /* sanity check on queue memory */
  11775. if (!eq)
  11776. return -ENODEV;
  11777. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  11778. if (!mbox)
  11779. return -ENOMEM;
  11780. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  11781. sizeof(struct lpfc_sli4_cfg_mhdr));
  11782. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11783. LPFC_MBOX_OPCODE_EQ_DESTROY,
  11784. length, LPFC_SLI4_MBX_EMBED);
  11785. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  11786. eq->queue_id);
  11787. mbox->vport = eq->phba->pport;
  11788. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11789. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  11790. /* The IOCTL status is embedded in the mailbox subheader. */
  11791. shdr = (union lpfc_sli4_cfg_shdr *)
  11792. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  11793. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11794. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11795. if (shdr_status || shdr_add_status || rc) {
  11796. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11797. "2505 EQ_DESTROY mailbox failed with "
  11798. "status x%x add_status x%x, mbx status x%x\n",
  11799. shdr_status, shdr_add_status, rc);
  11800. status = -ENXIO;
  11801. }
  11802. /* Remove eq from any list */
  11803. list_del_init(&eq->list);
  11804. mempool_free(mbox, eq->phba->mbox_mem_pool);
  11805. return status;
  11806. }
  11807. /**
  11808. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  11809. * @cq: The queue structure associated with the queue to destroy.
  11810. *
  11811. * This function destroys a queue, as detailed in @cq by sending an mailbox
  11812. * command, specific to the type of queue, to the HBA.
  11813. *
  11814. * The @cq struct is used to get the queue ID of the queue to destroy.
  11815. *
  11816. * On success this function will return a zero. If the queue destroy mailbox
  11817. * command fails this function will return -ENXIO.
  11818. **/
  11819. uint32_t
  11820. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  11821. {
  11822. LPFC_MBOXQ_t *mbox;
  11823. int rc, length, status = 0;
  11824. uint32_t shdr_status, shdr_add_status;
  11825. union lpfc_sli4_cfg_shdr *shdr;
  11826. /* sanity check on queue memory */
  11827. if (!cq)
  11828. return -ENODEV;
  11829. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  11830. if (!mbox)
  11831. return -ENOMEM;
  11832. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  11833. sizeof(struct lpfc_sli4_cfg_mhdr));
  11834. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11835. LPFC_MBOX_OPCODE_CQ_DESTROY,
  11836. length, LPFC_SLI4_MBX_EMBED);
  11837. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  11838. cq->queue_id);
  11839. mbox->vport = cq->phba->pport;
  11840. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11841. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  11842. /* The IOCTL status is embedded in the mailbox subheader. */
  11843. shdr = (union lpfc_sli4_cfg_shdr *)
  11844. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  11845. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11846. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11847. if (shdr_status || shdr_add_status || rc) {
  11848. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11849. "2506 CQ_DESTROY mailbox failed with "
  11850. "status x%x add_status x%x, mbx status x%x\n",
  11851. shdr_status, shdr_add_status, rc);
  11852. status = -ENXIO;
  11853. }
  11854. /* Remove cq from any list */
  11855. list_del_init(&cq->list);
  11856. mempool_free(mbox, cq->phba->mbox_mem_pool);
  11857. return status;
  11858. }
  11859. /**
  11860. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  11861. * @qm: The queue structure associated with the queue to destroy.
  11862. *
  11863. * This function destroys a queue, as detailed in @mq by sending an mailbox
  11864. * command, specific to the type of queue, to the HBA.
  11865. *
  11866. * The @mq struct is used to get the queue ID of the queue to destroy.
  11867. *
  11868. * On success this function will return a zero. If the queue destroy mailbox
  11869. * command fails this function will return -ENXIO.
  11870. **/
  11871. uint32_t
  11872. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  11873. {
  11874. LPFC_MBOXQ_t *mbox;
  11875. int rc, length, status = 0;
  11876. uint32_t shdr_status, shdr_add_status;
  11877. union lpfc_sli4_cfg_shdr *shdr;
  11878. /* sanity check on queue memory */
  11879. if (!mq)
  11880. return -ENODEV;
  11881. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  11882. if (!mbox)
  11883. return -ENOMEM;
  11884. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  11885. sizeof(struct lpfc_sli4_cfg_mhdr));
  11886. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11887. LPFC_MBOX_OPCODE_MQ_DESTROY,
  11888. length, LPFC_SLI4_MBX_EMBED);
  11889. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  11890. mq->queue_id);
  11891. mbox->vport = mq->phba->pport;
  11892. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11893. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  11894. /* The IOCTL status is embedded in the mailbox subheader. */
  11895. shdr = (union lpfc_sli4_cfg_shdr *)
  11896. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  11897. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11898. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11899. if (shdr_status || shdr_add_status || rc) {
  11900. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11901. "2507 MQ_DESTROY mailbox failed with "
  11902. "status x%x add_status x%x, mbx status x%x\n",
  11903. shdr_status, shdr_add_status, rc);
  11904. status = -ENXIO;
  11905. }
  11906. /* Remove mq from any list */
  11907. list_del_init(&mq->list);
  11908. mempool_free(mbox, mq->phba->mbox_mem_pool);
  11909. return status;
  11910. }
  11911. /**
  11912. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  11913. * @wq: The queue structure associated with the queue to destroy.
  11914. *
  11915. * This function destroys a queue, as detailed in @wq by sending an mailbox
  11916. * command, specific to the type of queue, to the HBA.
  11917. *
  11918. * The @wq struct is used to get the queue ID of the queue to destroy.
  11919. *
  11920. * On success this function will return a zero. If the queue destroy mailbox
  11921. * command fails this function will return -ENXIO.
  11922. **/
  11923. uint32_t
  11924. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  11925. {
  11926. LPFC_MBOXQ_t *mbox;
  11927. int rc, length, status = 0;
  11928. uint32_t shdr_status, shdr_add_status;
  11929. union lpfc_sli4_cfg_shdr *shdr;
  11930. /* sanity check on queue memory */
  11931. if (!wq)
  11932. return -ENODEV;
  11933. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  11934. if (!mbox)
  11935. return -ENOMEM;
  11936. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  11937. sizeof(struct lpfc_sli4_cfg_mhdr));
  11938. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11939. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  11940. length, LPFC_SLI4_MBX_EMBED);
  11941. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  11942. wq->queue_id);
  11943. mbox->vport = wq->phba->pport;
  11944. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11945. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  11946. shdr = (union lpfc_sli4_cfg_shdr *)
  11947. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  11948. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11949. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11950. if (shdr_status || shdr_add_status || rc) {
  11951. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11952. "2508 WQ_DESTROY mailbox failed with "
  11953. "status x%x add_status x%x, mbx status x%x\n",
  11954. shdr_status, shdr_add_status, rc);
  11955. status = -ENXIO;
  11956. }
  11957. /* Remove wq from any list */
  11958. list_del_init(&wq->list);
  11959. mempool_free(mbox, wq->phba->mbox_mem_pool);
  11960. return status;
  11961. }
  11962. /**
  11963. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  11964. * @rq: The queue structure associated with the queue to destroy.
  11965. *
  11966. * This function destroys a queue, as detailed in @rq by sending an mailbox
  11967. * command, specific to the type of queue, to the HBA.
  11968. *
  11969. * The @rq struct is used to get the queue ID of the queue to destroy.
  11970. *
  11971. * On success this function will return a zero. If the queue destroy mailbox
  11972. * command fails this function will return -ENXIO.
  11973. **/
  11974. uint32_t
  11975. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11976. struct lpfc_queue *drq)
  11977. {
  11978. LPFC_MBOXQ_t *mbox;
  11979. int rc, length, status = 0;
  11980. uint32_t shdr_status, shdr_add_status;
  11981. union lpfc_sli4_cfg_shdr *shdr;
  11982. /* sanity check on queue memory */
  11983. if (!hrq || !drq)
  11984. return -ENODEV;
  11985. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  11986. if (!mbox)
  11987. return -ENOMEM;
  11988. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  11989. sizeof(struct lpfc_sli4_cfg_mhdr));
  11990. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11991. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  11992. length, LPFC_SLI4_MBX_EMBED);
  11993. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  11994. hrq->queue_id);
  11995. mbox->vport = hrq->phba->pport;
  11996. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11997. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  11998. /* The IOCTL status is embedded in the mailbox subheader. */
  11999. shdr = (union lpfc_sli4_cfg_shdr *)
  12000. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12001. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12002. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12003. if (shdr_status || shdr_add_status || rc) {
  12004. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12005. "2509 RQ_DESTROY mailbox failed with "
  12006. "status x%x add_status x%x, mbx status x%x\n",
  12007. shdr_status, shdr_add_status, rc);
  12008. if (rc != MBX_TIMEOUT)
  12009. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12010. return -ENXIO;
  12011. }
  12012. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12013. drq->queue_id);
  12014. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  12015. shdr = (union lpfc_sli4_cfg_shdr *)
  12016. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12017. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12018. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12019. if (shdr_status || shdr_add_status || rc) {
  12020. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12021. "2510 RQ_DESTROY mailbox failed with "
  12022. "status x%x add_status x%x, mbx status x%x\n",
  12023. shdr_status, shdr_add_status, rc);
  12024. status = -ENXIO;
  12025. }
  12026. list_del_init(&hrq->list);
  12027. list_del_init(&drq->list);
  12028. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12029. return status;
  12030. }
  12031. /**
  12032. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  12033. * @phba: The virtual port for which this call being executed.
  12034. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  12035. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  12036. * @xritag: the xritag that ties this io to the SGL pages.
  12037. *
  12038. * This routine will post the sgl pages for the IO that has the xritag
  12039. * that is in the iocbq structure. The xritag is assigned during iocbq
  12040. * creation and persists for as long as the driver is loaded.
  12041. * if the caller has fewer than 256 scatter gather segments to map then
  12042. * pdma_phys_addr1 should be 0.
  12043. * If the caller needs to map more than 256 scatter gather segment then
  12044. * pdma_phys_addr1 should be a valid physical address.
  12045. * physical address for SGLs must be 64 byte aligned.
  12046. * If you are going to map 2 SGL's then the first one must have 256 entries
  12047. * the second sgl can have between 1 and 256 entries.
  12048. *
  12049. * Return codes:
  12050. * 0 - Success
  12051. * -ENXIO, -ENOMEM - Failure
  12052. **/
  12053. int
  12054. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  12055. dma_addr_t pdma_phys_addr0,
  12056. dma_addr_t pdma_phys_addr1,
  12057. uint16_t xritag)
  12058. {
  12059. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  12060. LPFC_MBOXQ_t *mbox;
  12061. int rc;
  12062. uint32_t shdr_status, shdr_add_status;
  12063. uint32_t mbox_tmo;
  12064. union lpfc_sli4_cfg_shdr *shdr;
  12065. if (xritag == NO_XRI) {
  12066. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12067. "0364 Invalid param:\n");
  12068. return -EINVAL;
  12069. }
  12070. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12071. if (!mbox)
  12072. return -ENOMEM;
  12073. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12074. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12075. sizeof(struct lpfc_mbx_post_sgl_pages) -
  12076. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  12077. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  12078. &mbox->u.mqe.un.post_sgl_pages;
  12079. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  12080. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  12081. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  12082. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  12083. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  12084. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  12085. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  12086. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  12087. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  12088. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  12089. if (!phba->sli4_hba.intr_enable)
  12090. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12091. else {
  12092. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12093. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12094. }
  12095. /* The IOCTL status is embedded in the mailbox subheader. */
  12096. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  12097. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12098. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12099. if (rc != MBX_TIMEOUT)
  12100. mempool_free(mbox, phba->mbox_mem_pool);
  12101. if (shdr_status || shdr_add_status || rc) {
  12102. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12103. "2511 POST_SGL mailbox failed with "
  12104. "status x%x add_status x%x, mbx status x%x\n",
  12105. shdr_status, shdr_add_status, rc);
  12106. rc = -ENXIO;
  12107. }
  12108. return 0;
  12109. }
  12110. /**
  12111. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  12112. * @phba: pointer to lpfc hba data structure.
  12113. *
  12114. * This routine is invoked to post rpi header templates to the
  12115. * HBA consistent with the SLI-4 interface spec. This routine
  12116. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  12117. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  12118. *
  12119. * Returns
  12120. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  12121. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  12122. **/
  12123. uint16_t
  12124. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  12125. {
  12126. unsigned long xri;
  12127. /*
  12128. * Fetch the next logical xri. Because this index is logical,
  12129. * the driver starts at 0 each time.
  12130. */
  12131. spin_lock_irq(&phba->hbalock);
  12132. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  12133. phba->sli4_hba.max_cfg_param.max_xri, 0);
  12134. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  12135. spin_unlock_irq(&phba->hbalock);
  12136. return NO_XRI;
  12137. } else {
  12138. set_bit(xri, phba->sli4_hba.xri_bmask);
  12139. phba->sli4_hba.max_cfg_param.xri_used++;
  12140. }
  12141. spin_unlock_irq(&phba->hbalock);
  12142. return xri;
  12143. }
  12144. /**
  12145. * lpfc_sli4_free_xri - Release an xri for reuse.
  12146. * @phba: pointer to lpfc hba data structure.
  12147. *
  12148. * This routine is invoked to release an xri to the pool of
  12149. * available rpis maintained by the driver.
  12150. **/
  12151. void
  12152. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12153. {
  12154. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  12155. phba->sli4_hba.max_cfg_param.xri_used--;
  12156. }
  12157. }
  12158. /**
  12159. * lpfc_sli4_free_xri - Release an xri for reuse.
  12160. * @phba: pointer to lpfc hba data structure.
  12161. *
  12162. * This routine is invoked to release an xri to the pool of
  12163. * available rpis maintained by the driver.
  12164. **/
  12165. void
  12166. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12167. {
  12168. spin_lock_irq(&phba->hbalock);
  12169. __lpfc_sli4_free_xri(phba, xri);
  12170. spin_unlock_irq(&phba->hbalock);
  12171. }
  12172. /**
  12173. * lpfc_sli4_next_xritag - Get an xritag for the io
  12174. * @phba: Pointer to HBA context object.
  12175. *
  12176. * This function gets an xritag for the iocb. If there is no unused xritag
  12177. * it will return 0xffff.
  12178. * The function returns the allocated xritag if successful, else returns zero.
  12179. * Zero is not a valid xritag.
  12180. * The caller is not required to hold any lock.
  12181. **/
  12182. uint16_t
  12183. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  12184. {
  12185. uint16_t xri_index;
  12186. xri_index = lpfc_sli4_alloc_xri(phba);
  12187. if (xri_index == NO_XRI)
  12188. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  12189. "2004 Failed to allocate XRI.last XRITAG is %d"
  12190. " Max XRI is %d, Used XRI is %d\n",
  12191. xri_index,
  12192. phba->sli4_hba.max_cfg_param.max_xri,
  12193. phba->sli4_hba.max_cfg_param.xri_used);
  12194. return xri_index;
  12195. }
  12196. /**
  12197. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  12198. * @phba: pointer to lpfc hba data structure.
  12199. * @post_sgl_list: pointer to els sgl entry list.
  12200. * @count: number of els sgl entries on the list.
  12201. *
  12202. * This routine is invoked to post a block of driver's sgl pages to the
  12203. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12204. * is only called when the driver is loading and after all IO has been
  12205. * stopped.
  12206. **/
  12207. static int
  12208. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  12209. struct list_head *post_sgl_list,
  12210. int post_cnt)
  12211. {
  12212. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  12213. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12214. struct sgl_page_pairs *sgl_pg_pairs;
  12215. void *viraddr;
  12216. LPFC_MBOXQ_t *mbox;
  12217. uint32_t reqlen, alloclen, pg_pairs;
  12218. uint32_t mbox_tmo;
  12219. uint16_t xritag_start = 0;
  12220. int rc = 0;
  12221. uint32_t shdr_status, shdr_add_status;
  12222. union lpfc_sli4_cfg_shdr *shdr;
  12223. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12224. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12225. if (reqlen > SLI4_PAGE_SIZE) {
  12226. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12227. "2559 Block sgl registration required DMA "
  12228. "size (%d) great than a page\n", reqlen);
  12229. return -ENOMEM;
  12230. }
  12231. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12232. if (!mbox)
  12233. return -ENOMEM;
  12234. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12235. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12236. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12237. LPFC_SLI4_MBX_NEMBED);
  12238. if (alloclen < reqlen) {
  12239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12240. "0285 Allocated DMA memory size (%d) is "
  12241. "less than the requested DMA memory "
  12242. "size (%d)\n", alloclen, reqlen);
  12243. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12244. return -ENOMEM;
  12245. }
  12246. /* Set up the SGL pages in the non-embedded DMA pages */
  12247. viraddr = mbox->sge_array->addr[0];
  12248. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12249. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12250. pg_pairs = 0;
  12251. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  12252. /* Set up the sge entry */
  12253. sgl_pg_pairs->sgl_pg0_addr_lo =
  12254. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12255. sgl_pg_pairs->sgl_pg0_addr_hi =
  12256. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12257. sgl_pg_pairs->sgl_pg1_addr_lo =
  12258. cpu_to_le32(putPaddrLow(0));
  12259. sgl_pg_pairs->sgl_pg1_addr_hi =
  12260. cpu_to_le32(putPaddrHigh(0));
  12261. /* Keep the first xritag on the list */
  12262. if (pg_pairs == 0)
  12263. xritag_start = sglq_entry->sli4_xritag;
  12264. sgl_pg_pairs++;
  12265. pg_pairs++;
  12266. }
  12267. /* Complete initialization and perform endian conversion. */
  12268. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12269. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  12270. sgl->word0 = cpu_to_le32(sgl->word0);
  12271. if (!phba->sli4_hba.intr_enable)
  12272. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12273. else {
  12274. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12275. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12276. }
  12277. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12278. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12279. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12280. if (rc != MBX_TIMEOUT)
  12281. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12282. if (shdr_status || shdr_add_status || rc) {
  12283. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12284. "2513 POST_SGL_BLOCK mailbox command failed "
  12285. "status x%x add_status x%x mbx status x%x\n",
  12286. shdr_status, shdr_add_status, rc);
  12287. rc = -ENXIO;
  12288. }
  12289. return rc;
  12290. }
  12291. /**
  12292. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12293. * @phba: pointer to lpfc hba data structure.
  12294. * @sblist: pointer to scsi buffer list.
  12295. * @count: number of scsi buffers on the list.
  12296. *
  12297. * This routine is invoked to post a block of @count scsi sgl pages from a
  12298. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12299. * No Lock is held.
  12300. *
  12301. **/
  12302. int
  12303. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  12304. struct list_head *sblist,
  12305. int count)
  12306. {
  12307. struct lpfc_scsi_buf *psb;
  12308. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12309. struct sgl_page_pairs *sgl_pg_pairs;
  12310. void *viraddr;
  12311. LPFC_MBOXQ_t *mbox;
  12312. uint32_t reqlen, alloclen, pg_pairs;
  12313. uint32_t mbox_tmo;
  12314. uint16_t xritag_start = 0;
  12315. int rc = 0;
  12316. uint32_t shdr_status, shdr_add_status;
  12317. dma_addr_t pdma_phys_bpl1;
  12318. union lpfc_sli4_cfg_shdr *shdr;
  12319. /* Calculate the requested length of the dma memory */
  12320. reqlen = count * sizeof(struct sgl_page_pairs) +
  12321. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12322. if (reqlen > SLI4_PAGE_SIZE) {
  12323. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12324. "0217 Block sgl registration required DMA "
  12325. "size (%d) great than a page\n", reqlen);
  12326. return -ENOMEM;
  12327. }
  12328. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12329. if (!mbox) {
  12330. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12331. "0283 Failed to allocate mbox cmd memory\n");
  12332. return -ENOMEM;
  12333. }
  12334. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12335. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12336. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12337. LPFC_SLI4_MBX_NEMBED);
  12338. if (alloclen < reqlen) {
  12339. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12340. "2561 Allocated DMA memory size (%d) is "
  12341. "less than the requested DMA memory "
  12342. "size (%d)\n", alloclen, reqlen);
  12343. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12344. return -ENOMEM;
  12345. }
  12346. /* Get the first SGE entry from the non-embedded DMA memory */
  12347. viraddr = mbox->sge_array->addr[0];
  12348. /* Set up the SGL pages in the non-embedded DMA pages */
  12349. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12350. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12351. pg_pairs = 0;
  12352. list_for_each_entry(psb, sblist, list) {
  12353. /* Set up the sge entry */
  12354. sgl_pg_pairs->sgl_pg0_addr_lo =
  12355. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12356. sgl_pg_pairs->sgl_pg0_addr_hi =
  12357. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12358. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12359. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12360. else
  12361. pdma_phys_bpl1 = 0;
  12362. sgl_pg_pairs->sgl_pg1_addr_lo =
  12363. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12364. sgl_pg_pairs->sgl_pg1_addr_hi =
  12365. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12366. /* Keep the first xritag on the list */
  12367. if (pg_pairs == 0)
  12368. xritag_start = psb->cur_iocbq.sli4_xritag;
  12369. sgl_pg_pairs++;
  12370. pg_pairs++;
  12371. }
  12372. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12373. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12374. /* Perform endian conversion if necessary */
  12375. sgl->word0 = cpu_to_le32(sgl->word0);
  12376. if (!phba->sli4_hba.intr_enable)
  12377. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12378. else {
  12379. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12380. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12381. }
  12382. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12383. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12384. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12385. if (rc != MBX_TIMEOUT)
  12386. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12387. if (shdr_status || shdr_add_status || rc) {
  12388. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12389. "2564 POST_SGL_BLOCK mailbox command failed "
  12390. "status x%x add_status x%x mbx status x%x\n",
  12391. shdr_status, shdr_add_status, rc);
  12392. rc = -ENXIO;
  12393. }
  12394. return rc;
  12395. }
  12396. /**
  12397. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12398. * @phba: pointer to lpfc_hba struct that the frame was received on
  12399. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12400. *
  12401. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12402. * valid type of frame that the LPFC driver will handle. This function will
  12403. * return a zero if the frame is a valid frame or a non zero value when the
  12404. * frame does not pass the check.
  12405. **/
  12406. static int
  12407. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12408. {
  12409. /* make rctl_names static to save stack space */
  12410. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12411. char *type_names[] = FC_TYPE_NAMES_INIT;
  12412. struct fc_vft_header *fc_vft_hdr;
  12413. uint32_t *header = (uint32_t *) fc_hdr;
  12414. switch (fc_hdr->fh_r_ctl) {
  12415. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12416. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12417. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12418. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12419. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12420. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12421. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12422. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12423. case FC_RCTL_ELS_REQ: /* extended link services request */
  12424. case FC_RCTL_ELS_REP: /* extended link services reply */
  12425. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12426. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12427. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12428. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12429. case FC_RCTL_BA_RMC: /* remove connection */
  12430. case FC_RCTL_BA_ACC: /* basic accept */
  12431. case FC_RCTL_BA_RJT: /* basic reject */
  12432. case FC_RCTL_BA_PRMT:
  12433. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12434. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12435. case FC_RCTL_P_RJT: /* port reject */
  12436. case FC_RCTL_F_RJT: /* fabric reject */
  12437. case FC_RCTL_P_BSY: /* port busy */
  12438. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12439. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12440. case FC_RCTL_LCR: /* link credit reset */
  12441. case FC_RCTL_END: /* end */
  12442. break;
  12443. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12444. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12445. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12446. return lpfc_fc_frame_check(phba, fc_hdr);
  12447. default:
  12448. goto drop;
  12449. }
  12450. switch (fc_hdr->fh_type) {
  12451. case FC_TYPE_BLS:
  12452. case FC_TYPE_ELS:
  12453. case FC_TYPE_FCP:
  12454. case FC_TYPE_CT:
  12455. break;
  12456. case FC_TYPE_IP:
  12457. case FC_TYPE_ILS:
  12458. default:
  12459. goto drop;
  12460. }
  12461. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12462. "2538 Received frame rctl:%s type:%s "
  12463. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12464. rctl_names[fc_hdr->fh_r_ctl],
  12465. type_names[fc_hdr->fh_type],
  12466. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12467. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12468. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12469. return 0;
  12470. drop:
  12471. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12472. "2539 Dropped frame rctl:%s type:%s\n",
  12473. rctl_names[fc_hdr->fh_r_ctl],
  12474. type_names[fc_hdr->fh_type]);
  12475. return 1;
  12476. }
  12477. /**
  12478. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12479. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12480. *
  12481. * This function processes the FC header to retrieve the VFI from the VF
  12482. * header, if one exists. This function will return the VFI if one exists
  12483. * or 0 if no VSAN Header exists.
  12484. **/
  12485. static uint32_t
  12486. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12487. {
  12488. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12489. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12490. return 0;
  12491. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12492. }
  12493. /**
  12494. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12495. * @phba: Pointer to the HBA structure to search for the vport on
  12496. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12497. * @fcfi: The FC Fabric ID that the frame came from
  12498. *
  12499. * This function searches the @phba for a vport that matches the content of the
  12500. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12501. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12502. * returns the matching vport pointer or NULL if unable to match frame to a
  12503. * vport.
  12504. **/
  12505. static struct lpfc_vport *
  12506. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12507. uint16_t fcfi)
  12508. {
  12509. struct lpfc_vport **vports;
  12510. struct lpfc_vport *vport = NULL;
  12511. int i;
  12512. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12513. fc_hdr->fh_d_id[1] << 8 |
  12514. fc_hdr->fh_d_id[2]);
  12515. if (did == Fabric_DID)
  12516. return phba->pport;
  12517. if ((phba->pport->fc_flag & FC_PT2PT) &&
  12518. !(phba->link_state == LPFC_HBA_READY))
  12519. return phba->pport;
  12520. vports = lpfc_create_vport_work_array(phba);
  12521. if (vports != NULL)
  12522. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12523. if (phba->fcf.fcfi == fcfi &&
  12524. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12525. vports[i]->fc_myDID == did) {
  12526. vport = vports[i];
  12527. break;
  12528. }
  12529. }
  12530. lpfc_destroy_vport_work_array(phba, vports);
  12531. return vport;
  12532. }
  12533. /**
  12534. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12535. * @vport: The vport to work on.
  12536. *
  12537. * This function updates the receive sequence time stamp for this vport. The
  12538. * receive sequence time stamp indicates the time that the last frame of the
  12539. * the sequence that has been idle for the longest amount of time was received.
  12540. * the driver uses this time stamp to indicate if any received sequences have
  12541. * timed out.
  12542. **/
  12543. void
  12544. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12545. {
  12546. struct lpfc_dmabuf *h_buf;
  12547. struct hbq_dmabuf *dmabuf = NULL;
  12548. /* get the oldest sequence on the rcv list */
  12549. h_buf = list_get_first(&vport->rcv_buffer_list,
  12550. struct lpfc_dmabuf, list);
  12551. if (!h_buf)
  12552. return;
  12553. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12554. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12555. }
  12556. /**
  12557. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12558. * @vport: The vport that the received sequences were sent to.
  12559. *
  12560. * This function cleans up all outstanding received sequences. This is called
  12561. * by the driver when a link event or user action invalidates all the received
  12562. * sequences.
  12563. **/
  12564. void
  12565. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12566. {
  12567. struct lpfc_dmabuf *h_buf, *hnext;
  12568. struct lpfc_dmabuf *d_buf, *dnext;
  12569. struct hbq_dmabuf *dmabuf = NULL;
  12570. /* start with the oldest sequence on the rcv list */
  12571. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12572. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12573. list_del_init(&dmabuf->hbuf.list);
  12574. list_for_each_entry_safe(d_buf, dnext,
  12575. &dmabuf->dbuf.list, list) {
  12576. list_del_init(&d_buf->list);
  12577. lpfc_in_buf_free(vport->phba, d_buf);
  12578. }
  12579. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12580. }
  12581. }
  12582. /**
  12583. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12584. * @vport: The vport that the received sequences were sent to.
  12585. *
  12586. * This function determines whether any received sequences have timed out by
  12587. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12588. * indicates that there is at least one timed out sequence this routine will
  12589. * go through the received sequences one at a time from most inactive to most
  12590. * active to determine which ones need to be cleaned up. Once it has determined
  12591. * that a sequence needs to be cleaned up it will simply free up the resources
  12592. * without sending an abort.
  12593. **/
  12594. void
  12595. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12596. {
  12597. struct lpfc_dmabuf *h_buf, *hnext;
  12598. struct lpfc_dmabuf *d_buf, *dnext;
  12599. struct hbq_dmabuf *dmabuf = NULL;
  12600. unsigned long timeout;
  12601. int abort_count = 0;
  12602. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12603. vport->rcv_buffer_time_stamp);
  12604. if (list_empty(&vport->rcv_buffer_list) ||
  12605. time_before(jiffies, timeout))
  12606. return;
  12607. /* start with the oldest sequence on the rcv list */
  12608. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12609. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12610. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12611. dmabuf->time_stamp);
  12612. if (time_before(jiffies, timeout))
  12613. break;
  12614. abort_count++;
  12615. list_del_init(&dmabuf->hbuf.list);
  12616. list_for_each_entry_safe(d_buf, dnext,
  12617. &dmabuf->dbuf.list, list) {
  12618. list_del_init(&d_buf->list);
  12619. lpfc_in_buf_free(vport->phba, d_buf);
  12620. }
  12621. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12622. }
  12623. if (abort_count)
  12624. lpfc_update_rcv_time_stamp(vport);
  12625. }
  12626. /**
  12627. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12628. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12629. *
  12630. * This function searches through the existing incomplete sequences that have
  12631. * been sent to this @vport. If the frame matches one of the incomplete
  12632. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12633. * make up that sequence. If no sequence is found that matches this frame then
  12634. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12635. * This function returns a pointer to the first dmabuf in the sequence list that
  12636. * the frame was linked to.
  12637. **/
  12638. static struct hbq_dmabuf *
  12639. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12640. {
  12641. struct fc_frame_header *new_hdr;
  12642. struct fc_frame_header *temp_hdr;
  12643. struct lpfc_dmabuf *d_buf;
  12644. struct lpfc_dmabuf *h_buf;
  12645. struct hbq_dmabuf *seq_dmabuf = NULL;
  12646. struct hbq_dmabuf *temp_dmabuf = NULL;
  12647. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12648. dmabuf->time_stamp = jiffies;
  12649. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12650. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12651. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12652. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12653. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12654. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12655. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12656. continue;
  12657. /* found a pending sequence that matches this frame */
  12658. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12659. break;
  12660. }
  12661. if (!seq_dmabuf) {
  12662. /*
  12663. * This indicates first frame received for this sequence.
  12664. * Queue the buffer on the vport's rcv_buffer_list.
  12665. */
  12666. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12667. lpfc_update_rcv_time_stamp(vport);
  12668. return dmabuf;
  12669. }
  12670. temp_hdr = seq_dmabuf->hbuf.virt;
  12671. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  12672. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12673. list_del_init(&seq_dmabuf->hbuf.list);
  12674. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12675. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12676. lpfc_update_rcv_time_stamp(vport);
  12677. return dmabuf;
  12678. }
  12679. /* move this sequence to the tail to indicate a young sequence */
  12680. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12681. seq_dmabuf->time_stamp = jiffies;
  12682. lpfc_update_rcv_time_stamp(vport);
  12683. if (list_empty(&seq_dmabuf->dbuf.list)) {
  12684. temp_hdr = dmabuf->hbuf.virt;
  12685. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12686. return seq_dmabuf;
  12687. }
  12688. /* find the correct place in the sequence to insert this frame */
  12689. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  12690. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12691. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  12692. /*
  12693. * If the frame's sequence count is greater than the frame on
  12694. * the list then insert the frame right after this frame
  12695. */
  12696. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  12697. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12698. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  12699. return seq_dmabuf;
  12700. }
  12701. }
  12702. return NULL;
  12703. }
  12704. /**
  12705. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  12706. * @vport: pointer to a vitural port
  12707. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12708. *
  12709. * This function tries to abort from the partially assembed sequence, described
  12710. * by the information from basic abbort @dmabuf. It checks to see whether such
  12711. * partially assembled sequence held by the driver. If so, it shall free up all
  12712. * the frames from the partially assembled sequence.
  12713. *
  12714. * Return
  12715. * true -- if there is matching partially assembled sequence present and all
  12716. * the frames freed with the sequence;
  12717. * false -- if there is no matching partially assembled sequence present so
  12718. * nothing got aborted in the lower layer driver
  12719. **/
  12720. static bool
  12721. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  12722. struct hbq_dmabuf *dmabuf)
  12723. {
  12724. struct fc_frame_header *new_hdr;
  12725. struct fc_frame_header *temp_hdr;
  12726. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  12727. struct hbq_dmabuf *seq_dmabuf = NULL;
  12728. /* Use the hdr_buf to find the sequence that matches this frame */
  12729. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12730. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  12731. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12732. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12733. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12734. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12735. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12736. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12737. continue;
  12738. /* found a pending sequence that matches this frame */
  12739. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12740. break;
  12741. }
  12742. /* Free up all the frames from the partially assembled sequence */
  12743. if (seq_dmabuf) {
  12744. list_for_each_entry_safe(d_buf, n_buf,
  12745. &seq_dmabuf->dbuf.list, list) {
  12746. list_del_init(&d_buf->list);
  12747. lpfc_in_buf_free(vport->phba, d_buf);
  12748. }
  12749. return true;
  12750. }
  12751. return false;
  12752. }
  12753. /**
  12754. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  12755. * @phba: Pointer to HBA context object.
  12756. * @cmd_iocbq: pointer to the command iocbq structure.
  12757. * @rsp_iocbq: pointer to the response iocbq structure.
  12758. *
  12759. * This function handles the sequence abort response iocb command complete
  12760. * event. It properly releases the memory allocated to the sequence abort
  12761. * accept iocb.
  12762. **/
  12763. static void
  12764. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  12765. struct lpfc_iocbq *cmd_iocbq,
  12766. struct lpfc_iocbq *rsp_iocbq)
  12767. {
  12768. if (cmd_iocbq)
  12769. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  12770. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  12771. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  12772. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12773. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  12774. rsp_iocbq->iocb.ulpStatus,
  12775. rsp_iocbq->iocb.un.ulpWord[4]);
  12776. }
  12777. /**
  12778. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  12779. * @phba: Pointer to HBA context object.
  12780. * @xri: xri id in transaction.
  12781. *
  12782. * This function validates the xri maps to the known range of XRIs allocated an
  12783. * used by the driver.
  12784. **/
  12785. uint16_t
  12786. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  12787. uint16_t xri)
  12788. {
  12789. int i;
  12790. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  12791. if (xri == phba->sli4_hba.xri_ids[i])
  12792. return i;
  12793. }
  12794. return NO_XRI;
  12795. }
  12796. /**
  12797. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  12798. * @phba: Pointer to HBA context object.
  12799. * @fc_hdr: pointer to a FC frame header.
  12800. *
  12801. * This function sends a basic response to a previous unsol sequence abort
  12802. * event after aborting the sequence handling.
  12803. **/
  12804. static void
  12805. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  12806. struct fc_frame_header *fc_hdr)
  12807. {
  12808. struct lpfc_iocbq *ctiocb = NULL;
  12809. struct lpfc_nodelist *ndlp;
  12810. uint16_t oxid, rxid, xri, lxri;
  12811. uint32_t sid, fctl;
  12812. IOCB_t *icmd;
  12813. int rc;
  12814. if (!lpfc_is_link_up(phba))
  12815. return;
  12816. sid = sli4_sid_from_fc_hdr(fc_hdr);
  12817. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  12818. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  12819. ndlp = lpfc_findnode_did(phba->pport, sid);
  12820. if (!ndlp) {
  12821. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12822. "1268 Find ndlp returned NULL for oxid:x%x "
  12823. "SID:x%x\n", oxid, sid);
  12824. return;
  12825. }
  12826. /* Allocate buffer for rsp iocb */
  12827. ctiocb = lpfc_sli_get_iocbq(phba);
  12828. if (!ctiocb)
  12829. return;
  12830. /* Extract the F_CTL field from FC_HDR */
  12831. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  12832. icmd = &ctiocb->iocb;
  12833. icmd->un.xseq64.bdl.bdeSize = 0;
  12834. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  12835. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  12836. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  12837. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  12838. /* Fill in the rest of iocb fields */
  12839. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  12840. icmd->ulpBdeCount = 0;
  12841. icmd->ulpLe = 1;
  12842. icmd->ulpClass = CLASS3;
  12843. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  12844. ctiocb->context1 = ndlp;
  12845. ctiocb->iocb_cmpl = NULL;
  12846. ctiocb->vport = phba->pport;
  12847. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  12848. ctiocb->sli4_lxritag = NO_XRI;
  12849. ctiocb->sli4_xritag = NO_XRI;
  12850. if (fctl & FC_FC_EX_CTX)
  12851. /* Exchange responder sent the abort so we
  12852. * own the oxid.
  12853. */
  12854. xri = oxid;
  12855. else
  12856. xri = rxid;
  12857. lxri = lpfc_sli4_xri_inrange(phba, xri);
  12858. if (lxri != NO_XRI)
  12859. lpfc_set_rrq_active(phba, ndlp, lxri,
  12860. (xri == oxid) ? rxid : oxid, 0);
  12861. /* If the oxid maps to the FCP XRI range or if it is out of range,
  12862. * send a BLS_RJT. The driver no longer has that exchange.
  12863. * Override the IOCB for a BA_RJT.
  12864. */
  12865. if (xri > (phba->sli4_hba.max_cfg_param.max_xri +
  12866. phba->sli4_hba.max_cfg_param.xri_base) ||
  12867. xri > (lpfc_sli4_get_els_iocb_cnt(phba) +
  12868. phba->sli4_hba.max_cfg_param.xri_base)) {
  12869. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  12870. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  12871. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  12872. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  12873. }
  12874. if (fctl & FC_FC_EX_CTX) {
  12875. /* ABTS sent by responder to CT exchange, construction
  12876. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  12877. * field and RX_ID from ABTS for RX_ID field.
  12878. */
  12879. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  12880. } else {
  12881. /* ABTS sent by initiator to CT exchange, construction
  12882. * of BA_ACC will need to allocate a new XRI as for the
  12883. * XRI_TAG field.
  12884. */
  12885. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  12886. }
  12887. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  12888. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  12889. /* Xmit CT abts response on exchange <xid> */
  12890. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12891. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  12892. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  12893. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  12894. if (rc == IOCB_ERROR) {
  12895. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  12896. "2925 Failed to issue CT ABTS RSP x%x on "
  12897. "xri x%x, Data x%x\n",
  12898. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  12899. phba->link_state);
  12900. lpfc_sli_release_iocbq(phba, ctiocb);
  12901. }
  12902. }
  12903. /**
  12904. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  12905. * @vport: Pointer to the vport on which this sequence was received
  12906. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12907. *
  12908. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  12909. * receive sequence is only partially assembed by the driver, it shall abort
  12910. * the partially assembled frames for the sequence. Otherwise, if the
  12911. * unsolicited receive sequence has been completely assembled and passed to
  12912. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  12913. * unsolicited sequence has been aborted. After that, it will issue a basic
  12914. * accept to accept the abort.
  12915. **/
  12916. void
  12917. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  12918. struct hbq_dmabuf *dmabuf)
  12919. {
  12920. struct lpfc_hba *phba = vport->phba;
  12921. struct fc_frame_header fc_hdr;
  12922. uint32_t fctl;
  12923. bool abts_par;
  12924. /* Make a copy of fc_hdr before the dmabuf being released */
  12925. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  12926. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  12927. if (fctl & FC_FC_EX_CTX) {
  12928. /*
  12929. * ABTS sent by responder to exchange, just free the buffer
  12930. */
  12931. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  12932. } else {
  12933. /*
  12934. * ABTS sent by initiator to exchange, need to do cleanup
  12935. */
  12936. /* Try to abort partially assembled seq */
  12937. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  12938. /* Send abort to ULP if partially seq abort failed */
  12939. if (abts_par == false)
  12940. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  12941. else
  12942. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  12943. }
  12944. /* Send basic accept (BA_ACC) to the abort requester */
  12945. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  12946. }
  12947. /**
  12948. * lpfc_seq_complete - Indicates if a sequence is complete
  12949. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12950. *
  12951. * This function checks the sequence, starting with the frame described by
  12952. * @dmabuf, to see if all the frames associated with this sequence are present.
  12953. * the frames associated with this sequence are linked to the @dmabuf using the
  12954. * dbuf list. This function looks for two major things. 1) That the first frame
  12955. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  12956. * set. 3) That there are no holes in the sequence count. The function will
  12957. * return 1 when the sequence is complete, otherwise it will return 0.
  12958. **/
  12959. static int
  12960. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  12961. {
  12962. struct fc_frame_header *hdr;
  12963. struct lpfc_dmabuf *d_buf;
  12964. struct hbq_dmabuf *seq_dmabuf;
  12965. uint32_t fctl;
  12966. int seq_count = 0;
  12967. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12968. /* make sure first fame of sequence has a sequence count of zero */
  12969. if (hdr->fh_seq_cnt != seq_count)
  12970. return 0;
  12971. fctl = (hdr->fh_f_ctl[0] << 16 |
  12972. hdr->fh_f_ctl[1] << 8 |
  12973. hdr->fh_f_ctl[2]);
  12974. /* If last frame of sequence we can return success. */
  12975. if (fctl & FC_FC_END_SEQ)
  12976. return 1;
  12977. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  12978. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12979. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  12980. /* If there is a hole in the sequence count then fail. */
  12981. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  12982. return 0;
  12983. fctl = (hdr->fh_f_ctl[0] << 16 |
  12984. hdr->fh_f_ctl[1] << 8 |
  12985. hdr->fh_f_ctl[2]);
  12986. /* If last frame of sequence we can return success. */
  12987. if (fctl & FC_FC_END_SEQ)
  12988. return 1;
  12989. }
  12990. return 0;
  12991. }
  12992. /**
  12993. * lpfc_prep_seq - Prep sequence for ULP processing
  12994. * @vport: Pointer to the vport on which this sequence was received
  12995. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12996. *
  12997. * This function takes a sequence, described by a list of frames, and creates
  12998. * a list of iocbq structures to describe the sequence. This iocbq list will be
  12999. * used to issue to the generic unsolicited sequence handler. This routine
  13000. * returns a pointer to the first iocbq in the list. If the function is unable
  13001. * to allocate an iocbq then it throw out the received frames that were not
  13002. * able to be described and return a pointer to the first iocbq. If unable to
  13003. * allocate any iocbqs (including the first) this function will return NULL.
  13004. **/
  13005. static struct lpfc_iocbq *
  13006. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  13007. {
  13008. struct hbq_dmabuf *hbq_buf;
  13009. struct lpfc_dmabuf *d_buf, *n_buf;
  13010. struct lpfc_iocbq *first_iocbq, *iocbq;
  13011. struct fc_frame_header *fc_hdr;
  13012. uint32_t sid;
  13013. uint32_t len, tot_len;
  13014. struct ulp_bde64 *pbde;
  13015. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13016. /* remove from receive buffer list */
  13017. list_del_init(&seq_dmabuf->hbuf.list);
  13018. lpfc_update_rcv_time_stamp(vport);
  13019. /* get the Remote Port's SID */
  13020. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13021. tot_len = 0;
  13022. /* Get an iocbq struct to fill in. */
  13023. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13024. if (first_iocbq) {
  13025. /* Initialize the first IOCB. */
  13026. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13027. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13028. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  13029. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  13030. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  13031. first_iocbq->iocb.un.rcvels.parmRo =
  13032. sli4_did_from_fc_hdr(fc_hdr);
  13033. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  13034. } else
  13035. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13036. first_iocbq->iocb.ulpContext = NO_XRI;
  13037. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13038. be16_to_cpu(fc_hdr->fh_ox_id);
  13039. /* iocbq is prepped for internal consumption. Physical vpi. */
  13040. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13041. vport->phba->vpi_ids[vport->vpi];
  13042. /* put the first buffer into the first IOCBq */
  13043. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13044. first_iocbq->context3 = NULL;
  13045. first_iocbq->iocb.ulpBdeCount = 1;
  13046. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13047. LPFC_DATA_BUF_SIZE;
  13048. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13049. tot_len = bf_get(lpfc_rcqe_length,
  13050. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13051. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13052. }
  13053. iocbq = first_iocbq;
  13054. /*
  13055. * Each IOCBq can have two Buffers assigned, so go through the list
  13056. * of buffers for this sequence and save two buffers in each IOCBq
  13057. */
  13058. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13059. if (!iocbq) {
  13060. lpfc_in_buf_free(vport->phba, d_buf);
  13061. continue;
  13062. }
  13063. if (!iocbq->context3) {
  13064. iocbq->context3 = d_buf;
  13065. iocbq->iocb.ulpBdeCount++;
  13066. pbde = (struct ulp_bde64 *)
  13067. &iocbq->iocb.unsli3.sli3Words[4];
  13068. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13069. /* We need to get the size out of the right CQE */
  13070. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13071. len = bf_get(lpfc_rcqe_length,
  13072. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13073. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13074. tot_len += len;
  13075. } else {
  13076. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13077. if (!iocbq) {
  13078. if (first_iocbq) {
  13079. first_iocbq->iocb.ulpStatus =
  13080. IOSTAT_FCP_RSP_ERROR;
  13081. first_iocbq->iocb.un.ulpWord[4] =
  13082. IOERR_NO_RESOURCES;
  13083. }
  13084. lpfc_in_buf_free(vport->phba, d_buf);
  13085. continue;
  13086. }
  13087. iocbq->context2 = d_buf;
  13088. iocbq->context3 = NULL;
  13089. iocbq->iocb.ulpBdeCount = 1;
  13090. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13091. LPFC_DATA_BUF_SIZE;
  13092. /* We need to get the size out of the right CQE */
  13093. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13094. len = bf_get(lpfc_rcqe_length,
  13095. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13096. tot_len += len;
  13097. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13098. iocbq->iocb.un.rcvels.remoteID = sid;
  13099. list_add_tail(&iocbq->list, &first_iocbq->list);
  13100. }
  13101. }
  13102. return first_iocbq;
  13103. }
  13104. static void
  13105. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13106. struct hbq_dmabuf *seq_dmabuf)
  13107. {
  13108. struct fc_frame_header *fc_hdr;
  13109. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13110. struct lpfc_hba *phba = vport->phba;
  13111. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13112. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13113. if (!iocbq) {
  13114. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13115. "2707 Ring %d handler: Failed to allocate "
  13116. "iocb Rctl x%x Type x%x received\n",
  13117. LPFC_ELS_RING,
  13118. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13119. return;
  13120. }
  13121. if (!lpfc_complete_unsol_iocb(phba,
  13122. &phba->sli.ring[LPFC_ELS_RING],
  13123. iocbq, fc_hdr->fh_r_ctl,
  13124. fc_hdr->fh_type))
  13125. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13126. "2540 Ring %d handler: unexpected Rctl "
  13127. "x%x Type x%x received\n",
  13128. LPFC_ELS_RING,
  13129. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13130. /* Free iocb created in lpfc_prep_seq */
  13131. list_for_each_entry_safe(curr_iocb, next_iocb,
  13132. &iocbq->list, list) {
  13133. list_del_init(&curr_iocb->list);
  13134. lpfc_sli_release_iocbq(phba, curr_iocb);
  13135. }
  13136. lpfc_sli_release_iocbq(phba, iocbq);
  13137. }
  13138. /**
  13139. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13140. * @phba: Pointer to HBA context object.
  13141. *
  13142. * This function is called with no lock held. This function processes all
  13143. * the received buffers and gives it to upper layers when a received buffer
  13144. * indicates that it is the final frame in the sequence. The interrupt
  13145. * service routine processes received buffers at interrupt contexts and adds
  13146. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13147. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13148. * appropriate receive function when the final frame in a sequence is received.
  13149. **/
  13150. void
  13151. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13152. struct hbq_dmabuf *dmabuf)
  13153. {
  13154. struct hbq_dmabuf *seq_dmabuf;
  13155. struct fc_frame_header *fc_hdr;
  13156. struct lpfc_vport *vport;
  13157. uint32_t fcfi;
  13158. uint32_t did;
  13159. /* Process each received buffer */
  13160. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13161. /* check to see if this a valid type of frame */
  13162. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13163. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13164. return;
  13165. }
  13166. if ((bf_get(lpfc_cqe_code,
  13167. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13168. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13169. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13170. else
  13171. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13172. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13173. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13174. if (!vport) {
  13175. /* throw out the frame */
  13176. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13177. return;
  13178. }
  13179. /* d_id this frame is directed to */
  13180. did = sli4_did_from_fc_hdr(fc_hdr);
  13181. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  13182. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  13183. (did != Fabric_DID)) {
  13184. /*
  13185. * Throw out the frame if we are not pt2pt.
  13186. * The pt2pt protocol allows for discovery frames
  13187. * to be received without a registered VPI.
  13188. */
  13189. if (!(vport->fc_flag & FC_PT2PT) ||
  13190. (phba->link_state == LPFC_HBA_READY)) {
  13191. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13192. return;
  13193. }
  13194. }
  13195. /* Handle the basic abort sequence (BA_ABTS) event */
  13196. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13197. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13198. return;
  13199. }
  13200. /* Link this frame */
  13201. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13202. if (!seq_dmabuf) {
  13203. /* unable to add frame to vport - throw it out */
  13204. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13205. return;
  13206. }
  13207. /* If not last frame in sequence continue processing frames. */
  13208. if (!lpfc_seq_complete(seq_dmabuf))
  13209. return;
  13210. /* Send the complete sequence to the upper layer protocol */
  13211. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13212. }
  13213. /**
  13214. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13215. * @phba: pointer to lpfc hba data structure.
  13216. *
  13217. * This routine is invoked to post rpi header templates to the
  13218. * HBA consistent with the SLI-4 interface spec. This routine
  13219. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13220. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13221. *
  13222. * This routine does not require any locks. It's usage is expected
  13223. * to be driver load or reset recovery when the driver is
  13224. * sequential.
  13225. *
  13226. * Return codes
  13227. * 0 - successful
  13228. * -EIO - The mailbox failed to complete successfully.
  13229. * When this error occurs, the driver is not guaranteed
  13230. * to have any rpi regions posted to the device and
  13231. * must either attempt to repost the regions or take a
  13232. * fatal error.
  13233. **/
  13234. int
  13235. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13236. {
  13237. struct lpfc_rpi_hdr *rpi_page;
  13238. uint32_t rc = 0;
  13239. uint16_t lrpi = 0;
  13240. /* SLI4 ports that support extents do not require RPI headers. */
  13241. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13242. goto exit;
  13243. if (phba->sli4_hba.extents_in_use)
  13244. return -EIO;
  13245. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13246. /*
  13247. * Assign the rpi headers a physical rpi only if the driver
  13248. * has not initialized those resources. A port reset only
  13249. * needs the headers posted.
  13250. */
  13251. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13252. LPFC_RPI_RSRC_RDY)
  13253. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13254. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13255. if (rc != MBX_SUCCESS) {
  13256. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13257. "2008 Error %d posting all rpi "
  13258. "headers\n", rc);
  13259. rc = -EIO;
  13260. break;
  13261. }
  13262. }
  13263. exit:
  13264. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13265. LPFC_RPI_RSRC_RDY);
  13266. return rc;
  13267. }
  13268. /**
  13269. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13270. * @phba: pointer to lpfc hba data structure.
  13271. * @rpi_page: pointer to the rpi memory region.
  13272. *
  13273. * This routine is invoked to post a single rpi header to the
  13274. * HBA consistent with the SLI-4 interface spec. This memory region
  13275. * maps up to 64 rpi context regions.
  13276. *
  13277. * Return codes
  13278. * 0 - successful
  13279. * -ENOMEM - No available memory
  13280. * -EIO - The mailbox failed to complete successfully.
  13281. **/
  13282. int
  13283. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13284. {
  13285. LPFC_MBOXQ_t *mboxq;
  13286. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13287. uint32_t rc = 0;
  13288. uint32_t shdr_status, shdr_add_status;
  13289. union lpfc_sli4_cfg_shdr *shdr;
  13290. /* SLI4 ports that support extents do not require RPI headers. */
  13291. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13292. return rc;
  13293. if (phba->sli4_hba.extents_in_use)
  13294. return -EIO;
  13295. /* The port is notified of the header region via a mailbox command. */
  13296. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13297. if (!mboxq) {
  13298. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13299. "2001 Unable to allocate memory for issuing "
  13300. "SLI_CONFIG_SPECIAL mailbox command\n");
  13301. return -ENOMEM;
  13302. }
  13303. /* Post all rpi memory regions to the port. */
  13304. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13305. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13306. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13307. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13308. sizeof(struct lpfc_sli4_cfg_mhdr),
  13309. LPFC_SLI4_MBX_EMBED);
  13310. /* Post the physical rpi to the port for this rpi header. */
  13311. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13312. rpi_page->start_rpi);
  13313. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13314. hdr_tmpl, rpi_page->page_count);
  13315. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13316. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13317. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13318. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13319. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13320. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13321. if (rc != MBX_TIMEOUT)
  13322. mempool_free(mboxq, phba->mbox_mem_pool);
  13323. if (shdr_status || shdr_add_status || rc) {
  13324. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13325. "2514 POST_RPI_HDR mailbox failed with "
  13326. "status x%x add_status x%x, mbx status x%x\n",
  13327. shdr_status, shdr_add_status, rc);
  13328. rc = -ENXIO;
  13329. }
  13330. return rc;
  13331. }
  13332. /**
  13333. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13334. * @phba: pointer to lpfc hba data structure.
  13335. *
  13336. * This routine is invoked to post rpi header templates to the
  13337. * HBA consistent with the SLI-4 interface spec. This routine
  13338. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13339. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13340. *
  13341. * Returns
  13342. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13343. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13344. **/
  13345. int
  13346. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13347. {
  13348. unsigned long rpi;
  13349. uint16_t max_rpi, rpi_limit;
  13350. uint16_t rpi_remaining, lrpi = 0;
  13351. struct lpfc_rpi_hdr *rpi_hdr;
  13352. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13353. rpi_limit = phba->sli4_hba.next_rpi;
  13354. /*
  13355. * Fetch the next logical rpi. Because this index is logical,
  13356. * the driver starts at 0 each time.
  13357. */
  13358. spin_lock_irq(&phba->hbalock);
  13359. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13360. if (rpi >= rpi_limit)
  13361. rpi = LPFC_RPI_ALLOC_ERROR;
  13362. else {
  13363. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13364. phba->sli4_hba.max_cfg_param.rpi_used++;
  13365. phba->sli4_hba.rpi_count++;
  13366. }
  13367. /*
  13368. * Don't try to allocate more rpi header regions if the device limit
  13369. * has been exhausted.
  13370. */
  13371. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13372. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13373. spin_unlock_irq(&phba->hbalock);
  13374. return rpi;
  13375. }
  13376. /*
  13377. * RPI header postings are not required for SLI4 ports capable of
  13378. * extents.
  13379. */
  13380. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13381. spin_unlock_irq(&phba->hbalock);
  13382. return rpi;
  13383. }
  13384. /*
  13385. * If the driver is running low on rpi resources, allocate another
  13386. * page now. Note that the next_rpi value is used because
  13387. * it represents how many are actually in use whereas max_rpi notes
  13388. * how many are supported max by the device.
  13389. */
  13390. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13391. spin_unlock_irq(&phba->hbalock);
  13392. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13393. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13394. if (!rpi_hdr) {
  13395. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13396. "2002 Error Could not grow rpi "
  13397. "count\n");
  13398. } else {
  13399. lrpi = rpi_hdr->start_rpi;
  13400. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13401. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13402. }
  13403. }
  13404. return rpi;
  13405. }
  13406. /**
  13407. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13408. * @phba: pointer to lpfc hba data structure.
  13409. *
  13410. * This routine is invoked to release an rpi to the pool of
  13411. * available rpis maintained by the driver.
  13412. **/
  13413. void
  13414. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13415. {
  13416. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13417. phba->sli4_hba.rpi_count--;
  13418. phba->sli4_hba.max_cfg_param.rpi_used--;
  13419. }
  13420. }
  13421. /**
  13422. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13423. * @phba: pointer to lpfc hba data structure.
  13424. *
  13425. * This routine is invoked to release an rpi to the pool of
  13426. * available rpis maintained by the driver.
  13427. **/
  13428. void
  13429. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13430. {
  13431. spin_lock_irq(&phba->hbalock);
  13432. __lpfc_sli4_free_rpi(phba, rpi);
  13433. spin_unlock_irq(&phba->hbalock);
  13434. }
  13435. /**
  13436. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13437. * @phba: pointer to lpfc hba data structure.
  13438. *
  13439. * This routine is invoked to remove the memory region that
  13440. * provided rpi via a bitmask.
  13441. **/
  13442. void
  13443. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13444. {
  13445. kfree(phba->sli4_hba.rpi_bmask);
  13446. kfree(phba->sli4_hba.rpi_ids);
  13447. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13448. }
  13449. /**
  13450. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13451. * @phba: pointer to lpfc hba data structure.
  13452. *
  13453. * This routine is invoked to remove the memory region that
  13454. * provided rpi via a bitmask.
  13455. **/
  13456. int
  13457. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  13458. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  13459. {
  13460. LPFC_MBOXQ_t *mboxq;
  13461. struct lpfc_hba *phba = ndlp->phba;
  13462. int rc;
  13463. /* The port is notified of the header region via a mailbox command. */
  13464. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13465. if (!mboxq)
  13466. return -ENOMEM;
  13467. /* Post all rpi memory regions to the port. */
  13468. lpfc_resume_rpi(mboxq, ndlp);
  13469. if (cmpl) {
  13470. mboxq->mbox_cmpl = cmpl;
  13471. mboxq->context1 = arg;
  13472. mboxq->context2 = ndlp;
  13473. } else
  13474. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13475. mboxq->vport = ndlp->vport;
  13476. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13477. if (rc == MBX_NOT_FINISHED) {
  13478. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13479. "2010 Resume RPI Mailbox failed "
  13480. "status %d, mbxStatus x%x\n", rc,
  13481. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13482. mempool_free(mboxq, phba->mbox_mem_pool);
  13483. return -EIO;
  13484. }
  13485. return 0;
  13486. }
  13487. /**
  13488. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13489. * @vport: Pointer to the vport for which the vpi is being initialized
  13490. *
  13491. * This routine is invoked to activate a vpi with the port.
  13492. *
  13493. * Returns:
  13494. * 0 success
  13495. * -Evalue otherwise
  13496. **/
  13497. int
  13498. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13499. {
  13500. LPFC_MBOXQ_t *mboxq;
  13501. int rc = 0;
  13502. int retval = MBX_SUCCESS;
  13503. uint32_t mbox_tmo;
  13504. struct lpfc_hba *phba = vport->phba;
  13505. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13506. if (!mboxq)
  13507. return -ENOMEM;
  13508. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13509. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13510. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13511. if (rc != MBX_SUCCESS) {
  13512. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13513. "2022 INIT VPI Mailbox failed "
  13514. "status %d, mbxStatus x%x\n", rc,
  13515. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13516. retval = -EIO;
  13517. }
  13518. if (rc != MBX_TIMEOUT)
  13519. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13520. return retval;
  13521. }
  13522. /**
  13523. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13524. * @phba: pointer to lpfc hba data structure.
  13525. * @mboxq: Pointer to mailbox object.
  13526. *
  13527. * This routine is invoked to manually add a single FCF record. The caller
  13528. * must pass a completely initialized FCF_Record. This routine takes
  13529. * care of the nonembedded mailbox operations.
  13530. **/
  13531. static void
  13532. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13533. {
  13534. void *virt_addr;
  13535. union lpfc_sli4_cfg_shdr *shdr;
  13536. uint32_t shdr_status, shdr_add_status;
  13537. virt_addr = mboxq->sge_array->addr[0];
  13538. /* The IOCTL status is embedded in the mailbox subheader. */
  13539. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13540. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13541. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13542. if ((shdr_status || shdr_add_status) &&
  13543. (shdr_status != STATUS_FCF_IN_USE))
  13544. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13545. "2558 ADD_FCF_RECORD mailbox failed with "
  13546. "status x%x add_status x%x\n",
  13547. shdr_status, shdr_add_status);
  13548. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13549. }
  13550. /**
  13551. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13552. * @phba: pointer to lpfc hba data structure.
  13553. * @fcf_record: pointer to the initialized fcf record to add.
  13554. *
  13555. * This routine is invoked to manually add a single FCF record. The caller
  13556. * must pass a completely initialized FCF_Record. This routine takes
  13557. * care of the nonembedded mailbox operations.
  13558. **/
  13559. int
  13560. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13561. {
  13562. int rc = 0;
  13563. LPFC_MBOXQ_t *mboxq;
  13564. uint8_t *bytep;
  13565. void *virt_addr;
  13566. dma_addr_t phys_addr;
  13567. struct lpfc_mbx_sge sge;
  13568. uint32_t alloc_len, req_len;
  13569. uint32_t fcfindex;
  13570. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13571. if (!mboxq) {
  13572. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13573. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13574. return -ENOMEM;
  13575. }
  13576. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13577. sizeof(uint32_t);
  13578. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13579. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13580. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13581. req_len, LPFC_SLI4_MBX_NEMBED);
  13582. if (alloc_len < req_len) {
  13583. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13584. "2523 Allocated DMA memory size (x%x) is "
  13585. "less than the requested DMA memory "
  13586. "size (x%x)\n", alloc_len, req_len);
  13587. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13588. return -ENOMEM;
  13589. }
  13590. /*
  13591. * Get the first SGE entry from the non-embedded DMA memory. This
  13592. * routine only uses a single SGE.
  13593. */
  13594. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13595. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13596. virt_addr = mboxq->sge_array->addr[0];
  13597. /*
  13598. * Configure the FCF record for FCFI 0. This is the driver's
  13599. * hardcoded default and gets used in nonFIP mode.
  13600. */
  13601. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  13602. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  13603. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  13604. /*
  13605. * Copy the fcf_index and the FCF Record Data. The data starts after
  13606. * the FCoE header plus word10. The data copy needs to be endian
  13607. * correct.
  13608. */
  13609. bytep += sizeof(uint32_t);
  13610. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  13611. mboxq->vport = phba->pport;
  13612. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  13613. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13614. if (rc == MBX_NOT_FINISHED) {
  13615. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13616. "2515 ADD_FCF_RECORD mailbox failed with "
  13617. "status 0x%x\n", rc);
  13618. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13619. rc = -EIO;
  13620. } else
  13621. rc = 0;
  13622. return rc;
  13623. }
  13624. /**
  13625. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  13626. * @phba: pointer to lpfc hba data structure.
  13627. * @fcf_record: pointer to the fcf record to write the default data.
  13628. * @fcf_index: FCF table entry index.
  13629. *
  13630. * This routine is invoked to build the driver's default FCF record. The
  13631. * values used are hardcoded. This routine handles memory initialization.
  13632. *
  13633. **/
  13634. void
  13635. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  13636. struct fcf_record *fcf_record,
  13637. uint16_t fcf_index)
  13638. {
  13639. memset(fcf_record, 0, sizeof(struct fcf_record));
  13640. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  13641. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  13642. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  13643. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  13644. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  13645. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  13646. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  13647. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  13648. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  13649. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  13650. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  13651. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  13652. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  13653. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  13654. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  13655. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  13656. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  13657. /* Set the VLAN bit map */
  13658. if (phba->valid_vlan) {
  13659. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  13660. = 1 << (phba->vlan_id % 8);
  13661. }
  13662. }
  13663. /**
  13664. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  13665. * @phba: pointer to lpfc hba data structure.
  13666. * @fcf_index: FCF table entry offset.
  13667. *
  13668. * This routine is invoked to scan the entire FCF table by reading FCF
  13669. * record and processing it one at a time starting from the @fcf_index
  13670. * for initial FCF discovery or fast FCF failover rediscovery.
  13671. *
  13672. * Return 0 if the mailbox command is submitted successfully, none 0
  13673. * otherwise.
  13674. **/
  13675. int
  13676. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13677. {
  13678. int rc = 0, error;
  13679. LPFC_MBOXQ_t *mboxq;
  13680. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  13681. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  13682. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13683. if (!mboxq) {
  13684. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13685. "2000 Failed to allocate mbox for "
  13686. "READ_FCF cmd\n");
  13687. error = -ENOMEM;
  13688. goto fail_fcf_scan;
  13689. }
  13690. /* Construct the read FCF record mailbox command */
  13691. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13692. if (rc) {
  13693. error = -EINVAL;
  13694. goto fail_fcf_scan;
  13695. }
  13696. /* Issue the mailbox command asynchronously */
  13697. mboxq->vport = phba->pport;
  13698. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  13699. spin_lock_irq(&phba->hbalock);
  13700. phba->hba_flag |= FCF_TS_INPROG;
  13701. spin_unlock_irq(&phba->hbalock);
  13702. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13703. if (rc == MBX_NOT_FINISHED)
  13704. error = -EIO;
  13705. else {
  13706. /* Reset eligible FCF count for new scan */
  13707. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  13708. phba->fcf.eligible_fcf_cnt = 0;
  13709. error = 0;
  13710. }
  13711. fail_fcf_scan:
  13712. if (error) {
  13713. if (mboxq)
  13714. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13715. /* FCF scan failed, clear FCF_TS_INPROG flag */
  13716. spin_lock_irq(&phba->hbalock);
  13717. phba->hba_flag &= ~FCF_TS_INPROG;
  13718. spin_unlock_irq(&phba->hbalock);
  13719. }
  13720. return error;
  13721. }
  13722. /**
  13723. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  13724. * @phba: pointer to lpfc hba data structure.
  13725. * @fcf_index: FCF table entry offset.
  13726. *
  13727. * This routine is invoked to read an FCF record indicated by @fcf_index
  13728. * and to use it for FLOGI roundrobin FCF failover.
  13729. *
  13730. * Return 0 if the mailbox command is submitted successfully, none 0
  13731. * otherwise.
  13732. **/
  13733. int
  13734. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13735. {
  13736. int rc = 0, error;
  13737. LPFC_MBOXQ_t *mboxq;
  13738. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13739. if (!mboxq) {
  13740. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13741. "2763 Failed to allocate mbox for "
  13742. "READ_FCF cmd\n");
  13743. error = -ENOMEM;
  13744. goto fail_fcf_read;
  13745. }
  13746. /* Construct the read FCF record mailbox command */
  13747. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13748. if (rc) {
  13749. error = -EINVAL;
  13750. goto fail_fcf_read;
  13751. }
  13752. /* Issue the mailbox command asynchronously */
  13753. mboxq->vport = phba->pport;
  13754. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  13755. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13756. if (rc == MBX_NOT_FINISHED)
  13757. error = -EIO;
  13758. else
  13759. error = 0;
  13760. fail_fcf_read:
  13761. if (error && mboxq)
  13762. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13763. return error;
  13764. }
  13765. /**
  13766. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  13767. * @phba: pointer to lpfc hba data structure.
  13768. * @fcf_index: FCF table entry offset.
  13769. *
  13770. * This routine is invoked to read an FCF record indicated by @fcf_index to
  13771. * determine whether it's eligible for FLOGI roundrobin failover list.
  13772. *
  13773. * Return 0 if the mailbox command is submitted successfully, none 0
  13774. * otherwise.
  13775. **/
  13776. int
  13777. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13778. {
  13779. int rc = 0, error;
  13780. LPFC_MBOXQ_t *mboxq;
  13781. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13782. if (!mboxq) {
  13783. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13784. "2758 Failed to allocate mbox for "
  13785. "READ_FCF cmd\n");
  13786. error = -ENOMEM;
  13787. goto fail_fcf_read;
  13788. }
  13789. /* Construct the read FCF record mailbox command */
  13790. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13791. if (rc) {
  13792. error = -EINVAL;
  13793. goto fail_fcf_read;
  13794. }
  13795. /* Issue the mailbox command asynchronously */
  13796. mboxq->vport = phba->pport;
  13797. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  13798. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13799. if (rc == MBX_NOT_FINISHED)
  13800. error = -EIO;
  13801. else
  13802. error = 0;
  13803. fail_fcf_read:
  13804. if (error && mboxq)
  13805. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13806. return error;
  13807. }
  13808. /**
  13809. * lpfc_check_next_fcf_pri
  13810. * phba pointer to the lpfc_hba struct for this port.
  13811. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  13812. * routine when the rr_bmask is empty. The FCF indecies are put into the
  13813. * rr_bmask based on their priority level. Starting from the highest priority
  13814. * to the lowest. The most likely FCF candidate will be in the highest
  13815. * priority group. When this routine is called it searches the fcf_pri list for
  13816. * next lowest priority group and repopulates the rr_bmask with only those
  13817. * fcf_indexes.
  13818. * returns:
  13819. * 1=success 0=failure
  13820. **/
  13821. int
  13822. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  13823. {
  13824. uint16_t next_fcf_pri;
  13825. uint16_t last_index;
  13826. struct lpfc_fcf_pri *fcf_pri;
  13827. int rc;
  13828. int ret = 0;
  13829. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  13830. LPFC_SLI4_FCF_TBL_INDX_MAX);
  13831. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13832. "3060 Last IDX %d\n", last_index);
  13833. if (list_empty(&phba->fcf.fcf_pri_list)) {
  13834. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13835. "3061 Last IDX %d\n", last_index);
  13836. return 0; /* Empty rr list */
  13837. }
  13838. next_fcf_pri = 0;
  13839. /*
  13840. * Clear the rr_bmask and set all of the bits that are at this
  13841. * priority.
  13842. */
  13843. memset(phba->fcf.fcf_rr_bmask, 0,
  13844. sizeof(*phba->fcf.fcf_rr_bmask));
  13845. spin_lock_irq(&phba->hbalock);
  13846. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13847. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  13848. continue;
  13849. /*
  13850. * the 1st priority that has not FLOGI failed
  13851. * will be the highest.
  13852. */
  13853. if (!next_fcf_pri)
  13854. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13855. spin_unlock_irq(&phba->hbalock);
  13856. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13857. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13858. fcf_pri->fcf_rec.fcf_index);
  13859. if (rc)
  13860. return 0;
  13861. }
  13862. spin_lock_irq(&phba->hbalock);
  13863. }
  13864. /*
  13865. * if next_fcf_pri was not set above and the list is not empty then
  13866. * we have failed flogis on all of them. So reset flogi failed
  13867. * and start at the begining.
  13868. */
  13869. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  13870. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13871. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  13872. /*
  13873. * the 1st priority that has not FLOGI failed
  13874. * will be the highest.
  13875. */
  13876. if (!next_fcf_pri)
  13877. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13878. spin_unlock_irq(&phba->hbalock);
  13879. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13880. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13881. fcf_pri->fcf_rec.fcf_index);
  13882. if (rc)
  13883. return 0;
  13884. }
  13885. spin_lock_irq(&phba->hbalock);
  13886. }
  13887. } else
  13888. ret = 1;
  13889. spin_unlock_irq(&phba->hbalock);
  13890. return ret;
  13891. }
  13892. /**
  13893. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  13894. * @phba: pointer to lpfc hba data structure.
  13895. *
  13896. * This routine is to get the next eligible FCF record index in a round
  13897. * robin fashion. If the next eligible FCF record index equals to the
  13898. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  13899. * shall be returned, otherwise, the next eligible FCF record's index
  13900. * shall be returned.
  13901. **/
  13902. uint16_t
  13903. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  13904. {
  13905. uint16_t next_fcf_index;
  13906. /* Search start from next bit of currently registered FCF index */
  13907. next_priority:
  13908. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  13909. LPFC_SLI4_FCF_TBL_INDX_MAX;
  13910. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  13911. LPFC_SLI4_FCF_TBL_INDX_MAX,
  13912. next_fcf_index);
  13913. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  13914. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13915. /*
  13916. * If we have wrapped then we need to clear the bits that
  13917. * have been tested so that we can detect when we should
  13918. * change the priority level.
  13919. */
  13920. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  13921. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  13922. }
  13923. /* Check roundrobin failover list empty condition */
  13924. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  13925. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  13926. /*
  13927. * If next fcf index is not found check if there are lower
  13928. * Priority level fcf's in the fcf_priority list.
  13929. * Set up the rr_bmask with all of the avaiable fcf bits
  13930. * at that level and continue the selection process.
  13931. */
  13932. if (lpfc_check_next_fcf_pri_level(phba))
  13933. goto next_priority;
  13934. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  13935. "2844 No roundrobin failover FCF available\n");
  13936. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  13937. return LPFC_FCOE_FCF_NEXT_NONE;
  13938. else {
  13939. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  13940. "3063 Only FCF available idx %d, flag %x\n",
  13941. next_fcf_index,
  13942. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  13943. return next_fcf_index;
  13944. }
  13945. }
  13946. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  13947. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  13948. LPFC_FCF_FLOGI_FAILED)
  13949. goto next_priority;
  13950. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13951. "2845 Get next roundrobin failover FCF (x%x)\n",
  13952. next_fcf_index);
  13953. return next_fcf_index;
  13954. }
  13955. /**
  13956. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  13957. * @phba: pointer to lpfc hba data structure.
  13958. *
  13959. * This routine sets the FCF record index in to the eligible bmask for
  13960. * roundrobin failover search. It checks to make sure that the index
  13961. * does not go beyond the range of the driver allocated bmask dimension
  13962. * before setting the bit.
  13963. *
  13964. * Returns 0 if the index bit successfully set, otherwise, it returns
  13965. * -EINVAL.
  13966. **/
  13967. int
  13968. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  13969. {
  13970. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13971. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13972. "2610 FCF (x%x) reached driver's book "
  13973. "keeping dimension:x%x\n",
  13974. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  13975. return -EINVAL;
  13976. }
  13977. /* Set the eligible FCF record index bmask */
  13978. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  13979. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13980. "2790 Set FCF (x%x) to roundrobin FCF failover "
  13981. "bmask\n", fcf_index);
  13982. return 0;
  13983. }
  13984. /**
  13985. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  13986. * @phba: pointer to lpfc hba data structure.
  13987. *
  13988. * This routine clears the FCF record index from the eligible bmask for
  13989. * roundrobin failover search. It checks to make sure that the index
  13990. * does not go beyond the range of the driver allocated bmask dimension
  13991. * before clearing the bit.
  13992. **/
  13993. void
  13994. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  13995. {
  13996. struct lpfc_fcf_pri *fcf_pri;
  13997. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13998. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13999. "2762 FCF (x%x) reached driver's book "
  14000. "keeping dimension:x%x\n",
  14001. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14002. return;
  14003. }
  14004. /* Clear the eligible FCF record index bmask */
  14005. spin_lock_irq(&phba->hbalock);
  14006. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14007. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  14008. list_del_init(&fcf_pri->list);
  14009. break;
  14010. }
  14011. }
  14012. spin_unlock_irq(&phba->hbalock);
  14013. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14014. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14015. "2791 Clear FCF (x%x) from roundrobin failover "
  14016. "bmask\n", fcf_index);
  14017. }
  14018. /**
  14019. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  14020. * @phba: pointer to lpfc hba data structure.
  14021. *
  14022. * This routine is the completion routine for the rediscover FCF table mailbox
  14023. * command. If the mailbox command returned failure, it will try to stop the
  14024. * FCF rediscover wait timer.
  14025. **/
  14026. void
  14027. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14028. {
  14029. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14030. uint32_t shdr_status, shdr_add_status;
  14031. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14032. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14033. &redisc_fcf->header.cfg_shdr.response);
  14034. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14035. &redisc_fcf->header.cfg_shdr.response);
  14036. if (shdr_status || shdr_add_status) {
  14037. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14038. "2746 Requesting for FCF rediscovery failed "
  14039. "status x%x add_status x%x\n",
  14040. shdr_status, shdr_add_status);
  14041. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14042. spin_lock_irq(&phba->hbalock);
  14043. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14044. spin_unlock_irq(&phba->hbalock);
  14045. /*
  14046. * CVL event triggered FCF rediscover request failed,
  14047. * last resort to re-try current registered FCF entry.
  14048. */
  14049. lpfc_retry_pport_discovery(phba);
  14050. } else {
  14051. spin_lock_irq(&phba->hbalock);
  14052. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14053. spin_unlock_irq(&phba->hbalock);
  14054. /*
  14055. * DEAD FCF event triggered FCF rediscover request
  14056. * failed, last resort to fail over as a link down
  14057. * to FCF registration.
  14058. */
  14059. lpfc_sli4_fcf_dead_failthrough(phba);
  14060. }
  14061. } else {
  14062. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14063. "2775 Start FCF rediscover quiescent timer\n");
  14064. /*
  14065. * Start FCF rediscovery wait timer for pending FCF
  14066. * before rescan FCF record table.
  14067. */
  14068. lpfc_fcf_redisc_wait_start_timer(phba);
  14069. }
  14070. mempool_free(mbox, phba->mbox_mem_pool);
  14071. }
  14072. /**
  14073. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14074. * @phba: pointer to lpfc hba data structure.
  14075. *
  14076. * This routine is invoked to request for rediscovery of the entire FCF table
  14077. * by the port.
  14078. **/
  14079. int
  14080. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14081. {
  14082. LPFC_MBOXQ_t *mbox;
  14083. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14084. int rc, length;
  14085. /* Cancel retry delay timers to all vports before FCF rediscover */
  14086. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14087. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14088. if (!mbox) {
  14089. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14090. "2745 Failed to allocate mbox for "
  14091. "requesting FCF rediscover.\n");
  14092. return -ENOMEM;
  14093. }
  14094. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14095. sizeof(struct lpfc_sli4_cfg_mhdr));
  14096. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14097. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14098. length, LPFC_SLI4_MBX_EMBED);
  14099. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14100. /* Set count to 0 for invalidating the entire FCF database */
  14101. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14102. /* Issue the mailbox command asynchronously */
  14103. mbox->vport = phba->pport;
  14104. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14105. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14106. if (rc == MBX_NOT_FINISHED) {
  14107. mempool_free(mbox, phba->mbox_mem_pool);
  14108. return -EIO;
  14109. }
  14110. return 0;
  14111. }
  14112. /**
  14113. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14114. * @phba: pointer to lpfc hba data structure.
  14115. *
  14116. * This function is the failover routine as a last resort to the FCF DEAD
  14117. * event when driver failed to perform fast FCF failover.
  14118. **/
  14119. void
  14120. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14121. {
  14122. uint32_t link_state;
  14123. /*
  14124. * Last resort as FCF DEAD event failover will treat this as
  14125. * a link down, but save the link state because we don't want
  14126. * it to be changed to Link Down unless it is already down.
  14127. */
  14128. link_state = phba->link_state;
  14129. lpfc_linkdown(phba);
  14130. phba->link_state = link_state;
  14131. /* Unregister FCF if no devices connected to it */
  14132. lpfc_unregister_unused_fcf(phba);
  14133. }
  14134. /**
  14135. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14136. * @phba: pointer to lpfc hba data structure.
  14137. * @rgn23_data: pointer to configure region 23 data.
  14138. *
  14139. * This function gets SLI3 port configure region 23 data through memory dump
  14140. * mailbox command. When it successfully retrieves data, the size of the data
  14141. * will be returned, otherwise, 0 will be returned.
  14142. **/
  14143. static uint32_t
  14144. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14145. {
  14146. LPFC_MBOXQ_t *pmb = NULL;
  14147. MAILBOX_t *mb;
  14148. uint32_t offset = 0;
  14149. int rc;
  14150. if (!rgn23_data)
  14151. return 0;
  14152. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14153. if (!pmb) {
  14154. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14155. "2600 failed to allocate mailbox memory\n");
  14156. return 0;
  14157. }
  14158. mb = &pmb->u.mb;
  14159. do {
  14160. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14161. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14162. if (rc != MBX_SUCCESS) {
  14163. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14164. "2601 failed to read config "
  14165. "region 23, rc 0x%x Status 0x%x\n",
  14166. rc, mb->mbxStatus);
  14167. mb->un.varDmp.word_cnt = 0;
  14168. }
  14169. /*
  14170. * dump mem may return a zero when finished or we got a
  14171. * mailbox error, either way we are done.
  14172. */
  14173. if (mb->un.varDmp.word_cnt == 0)
  14174. break;
  14175. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14176. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14177. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14178. rgn23_data + offset,
  14179. mb->un.varDmp.word_cnt);
  14180. offset += mb->un.varDmp.word_cnt;
  14181. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14182. mempool_free(pmb, phba->mbox_mem_pool);
  14183. return offset;
  14184. }
  14185. /**
  14186. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14187. * @phba: pointer to lpfc hba data structure.
  14188. * @rgn23_data: pointer to configure region 23 data.
  14189. *
  14190. * This function gets SLI4 port configure region 23 data through memory dump
  14191. * mailbox command. When it successfully retrieves data, the size of the data
  14192. * will be returned, otherwise, 0 will be returned.
  14193. **/
  14194. static uint32_t
  14195. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14196. {
  14197. LPFC_MBOXQ_t *mboxq = NULL;
  14198. struct lpfc_dmabuf *mp = NULL;
  14199. struct lpfc_mqe *mqe;
  14200. uint32_t data_length = 0;
  14201. int rc;
  14202. if (!rgn23_data)
  14203. return 0;
  14204. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14205. if (!mboxq) {
  14206. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14207. "3105 failed to allocate mailbox memory\n");
  14208. return 0;
  14209. }
  14210. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14211. goto out;
  14212. mqe = &mboxq->u.mqe;
  14213. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14214. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14215. if (rc)
  14216. goto out;
  14217. data_length = mqe->un.mb_words[5];
  14218. if (data_length == 0)
  14219. goto out;
  14220. if (data_length > DMP_RGN23_SIZE) {
  14221. data_length = 0;
  14222. goto out;
  14223. }
  14224. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14225. out:
  14226. mempool_free(mboxq, phba->mbox_mem_pool);
  14227. if (mp) {
  14228. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14229. kfree(mp);
  14230. }
  14231. return data_length;
  14232. }
  14233. /**
  14234. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14235. * @phba: pointer to lpfc hba data structure.
  14236. *
  14237. * This function read region 23 and parse TLV for port status to
  14238. * decide if the user disaled the port. If the TLV indicates the
  14239. * port is disabled, the hba_flag is set accordingly.
  14240. **/
  14241. void
  14242. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14243. {
  14244. uint8_t *rgn23_data = NULL;
  14245. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14246. uint32_t offset = 0;
  14247. /* Get adapter Region 23 data */
  14248. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14249. if (!rgn23_data)
  14250. goto out;
  14251. if (phba->sli_rev < LPFC_SLI_REV4)
  14252. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14253. else {
  14254. if_type = bf_get(lpfc_sli_intf_if_type,
  14255. &phba->sli4_hba.sli_intf);
  14256. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14257. goto out;
  14258. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14259. }
  14260. if (!data_size)
  14261. goto out;
  14262. /* Check the region signature first */
  14263. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14264. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14265. "2619 Config region 23 has bad signature\n");
  14266. goto out;
  14267. }
  14268. offset += 4;
  14269. /* Check the data structure version */
  14270. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14271. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14272. "2620 Config region 23 has bad version\n");
  14273. goto out;
  14274. }
  14275. offset += 4;
  14276. /* Parse TLV entries in the region */
  14277. while (offset < data_size) {
  14278. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14279. break;
  14280. /*
  14281. * If the TLV is not driver specific TLV or driver id is
  14282. * not linux driver id, skip the record.
  14283. */
  14284. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14285. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14286. (rgn23_data[offset + 3] != 0)) {
  14287. offset += rgn23_data[offset + 1] * 4 + 4;
  14288. continue;
  14289. }
  14290. /* Driver found a driver specific TLV in the config region */
  14291. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14292. offset += 4;
  14293. tlv_offset = 0;
  14294. /*
  14295. * Search for configured port state sub-TLV.
  14296. */
  14297. while ((offset < data_size) &&
  14298. (tlv_offset < sub_tlv_len)) {
  14299. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14300. offset += 4;
  14301. tlv_offset += 4;
  14302. break;
  14303. }
  14304. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14305. offset += rgn23_data[offset + 1] * 4 + 4;
  14306. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14307. continue;
  14308. }
  14309. /* This HBA contains PORT_STE configured */
  14310. if (!rgn23_data[offset + 2])
  14311. phba->hba_flag |= LINK_DISABLED;
  14312. goto out;
  14313. }
  14314. }
  14315. out:
  14316. kfree(rgn23_data);
  14317. return;
  14318. }
  14319. /**
  14320. * lpfc_wr_object - write an object to the firmware
  14321. * @phba: HBA structure that indicates port to create a queue on.
  14322. * @dmabuf_list: list of dmabufs to write to the port.
  14323. * @size: the total byte value of the objects to write to the port.
  14324. * @offset: the current offset to be used to start the transfer.
  14325. *
  14326. * This routine will create a wr_object mailbox command to send to the port.
  14327. * the mailbox command will be constructed using the dma buffers described in
  14328. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14329. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14330. * used to indicate the starting offset of the transfer and will also return
  14331. * the offset after the write object mailbox has completed. @size is used to
  14332. * determine the end of the object and whether the eof bit should be set.
  14333. *
  14334. * Return 0 is successful and offset will contain the the new offset to use
  14335. * for the next write.
  14336. * Return negative value for error cases.
  14337. **/
  14338. int
  14339. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14340. uint32_t size, uint32_t *offset)
  14341. {
  14342. struct lpfc_mbx_wr_object *wr_object;
  14343. LPFC_MBOXQ_t *mbox;
  14344. int rc = 0, i = 0;
  14345. uint32_t shdr_status, shdr_add_status;
  14346. uint32_t mbox_tmo;
  14347. union lpfc_sli4_cfg_shdr *shdr;
  14348. struct lpfc_dmabuf *dmabuf;
  14349. uint32_t written = 0;
  14350. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14351. if (!mbox)
  14352. return -ENOMEM;
  14353. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14354. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14355. sizeof(struct lpfc_mbx_wr_object) -
  14356. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14357. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14358. wr_object->u.request.write_offset = *offset;
  14359. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14360. wr_object->u.request.object_name[0] =
  14361. cpu_to_le32(wr_object->u.request.object_name[0]);
  14362. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14363. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14364. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14365. break;
  14366. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14367. wr_object->u.request.bde[i].addrHigh =
  14368. putPaddrHigh(dmabuf->phys);
  14369. if (written + SLI4_PAGE_SIZE >= size) {
  14370. wr_object->u.request.bde[i].tus.f.bdeSize =
  14371. (size - written);
  14372. written += (size - written);
  14373. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14374. } else {
  14375. wr_object->u.request.bde[i].tus.f.bdeSize =
  14376. SLI4_PAGE_SIZE;
  14377. written += SLI4_PAGE_SIZE;
  14378. }
  14379. i++;
  14380. }
  14381. wr_object->u.request.bde_count = i;
  14382. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14383. if (!phba->sli4_hba.intr_enable)
  14384. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14385. else {
  14386. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14387. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14388. }
  14389. /* The IOCTL status is embedded in the mailbox subheader. */
  14390. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14391. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14392. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14393. if (rc != MBX_TIMEOUT)
  14394. mempool_free(mbox, phba->mbox_mem_pool);
  14395. if (shdr_status || shdr_add_status || rc) {
  14396. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14397. "3025 Write Object mailbox failed with "
  14398. "status x%x add_status x%x, mbx status x%x\n",
  14399. shdr_status, shdr_add_status, rc);
  14400. rc = -ENXIO;
  14401. } else
  14402. *offset += wr_object->u.response.actual_write_length;
  14403. return rc;
  14404. }
  14405. /**
  14406. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14407. * @vport: pointer to vport data structure.
  14408. *
  14409. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14410. * and REG_VPI mailbox commands associated with the vport. This function
  14411. * is called when driver want to restart discovery of the vport due to
  14412. * a Clear Virtual Link event.
  14413. **/
  14414. void
  14415. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14416. {
  14417. struct lpfc_hba *phba = vport->phba;
  14418. LPFC_MBOXQ_t *mb, *nextmb;
  14419. struct lpfc_dmabuf *mp;
  14420. struct lpfc_nodelist *ndlp;
  14421. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14422. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14423. LIST_HEAD(mbox_cmd_list);
  14424. uint8_t restart_loop;
  14425. /* Clean up internally queued mailbox commands with the vport */
  14426. spin_lock_irq(&phba->hbalock);
  14427. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14428. if (mb->vport != vport)
  14429. continue;
  14430. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14431. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14432. continue;
  14433. list_del(&mb->list);
  14434. list_add_tail(&mb->list, &mbox_cmd_list);
  14435. }
  14436. /* Clean up active mailbox command with the vport */
  14437. mb = phba->sli.mbox_active;
  14438. if (mb && (mb->vport == vport)) {
  14439. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14440. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14441. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14442. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14443. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14444. /* Put reference count for delayed processing */
  14445. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14446. /* Unregister the RPI when mailbox complete */
  14447. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14448. }
  14449. }
  14450. /* Cleanup any mailbox completions which are not yet processed */
  14451. do {
  14452. restart_loop = 0;
  14453. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14454. /*
  14455. * If this mailox is already processed or it is
  14456. * for another vport ignore it.
  14457. */
  14458. if ((mb->vport != vport) ||
  14459. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14460. continue;
  14461. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14462. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14463. continue;
  14464. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14465. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14466. ndlp = (struct lpfc_nodelist *)mb->context2;
  14467. /* Unregister the RPI when mailbox complete */
  14468. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14469. restart_loop = 1;
  14470. spin_unlock_irq(&phba->hbalock);
  14471. spin_lock(shost->host_lock);
  14472. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14473. spin_unlock(shost->host_lock);
  14474. spin_lock_irq(&phba->hbalock);
  14475. break;
  14476. }
  14477. }
  14478. } while (restart_loop);
  14479. spin_unlock_irq(&phba->hbalock);
  14480. /* Release the cleaned-up mailbox commands */
  14481. while (!list_empty(&mbox_cmd_list)) {
  14482. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14483. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14484. mp = (struct lpfc_dmabuf *) (mb->context1);
  14485. if (mp) {
  14486. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14487. kfree(mp);
  14488. }
  14489. ndlp = (struct lpfc_nodelist *) mb->context2;
  14490. mb->context2 = NULL;
  14491. if (ndlp) {
  14492. spin_lock(shost->host_lock);
  14493. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14494. spin_unlock(shost->host_lock);
  14495. lpfc_nlp_put(ndlp);
  14496. }
  14497. }
  14498. mempool_free(mb, phba->mbox_mem_pool);
  14499. }
  14500. /* Release the ndlp with the cleaned-up active mailbox command */
  14501. if (act_mbx_ndlp) {
  14502. spin_lock(shost->host_lock);
  14503. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14504. spin_unlock(shost->host_lock);
  14505. lpfc_nlp_put(act_mbx_ndlp);
  14506. }
  14507. }
  14508. /**
  14509. * lpfc_drain_txq - Drain the txq
  14510. * @phba: Pointer to HBA context object.
  14511. *
  14512. * This function attempt to submit IOCBs on the txq
  14513. * to the adapter. For SLI4 adapters, the txq contains
  14514. * ELS IOCBs that have been deferred because the there
  14515. * are no SGLs. This congestion can occur with large
  14516. * vport counts during node discovery.
  14517. **/
  14518. uint32_t
  14519. lpfc_drain_txq(struct lpfc_hba *phba)
  14520. {
  14521. LIST_HEAD(completions);
  14522. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14523. struct lpfc_iocbq *piocbq = 0;
  14524. unsigned long iflags = 0;
  14525. char *fail_msg = NULL;
  14526. struct lpfc_sglq *sglq;
  14527. union lpfc_wqe wqe;
  14528. spin_lock_irqsave(&phba->hbalock, iflags);
  14529. if (pring->txq_cnt > pring->txq_max)
  14530. pring->txq_max = pring->txq_cnt;
  14531. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14532. while (pring->txq_cnt) {
  14533. spin_lock_irqsave(&phba->hbalock, iflags);
  14534. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14535. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14536. if (!sglq) {
  14537. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14538. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14539. break;
  14540. } else {
  14541. if (!piocbq) {
  14542. /* The txq_cnt out of sync. This should
  14543. * never happen
  14544. */
  14545. sglq = __lpfc_clear_active_sglq(phba,
  14546. sglq->sli4_lxritag);
  14547. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14548. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14549. "2823 txq empty and txq_cnt is %d\n ",
  14550. pring->txq_cnt);
  14551. break;
  14552. }
  14553. }
  14554. /* The xri and iocb resources secured,
  14555. * attempt to issue request
  14556. */
  14557. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14558. piocbq->sli4_xritag = sglq->sli4_xritag;
  14559. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14560. fail_msg = "to convert bpl to sgl";
  14561. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14562. fail_msg = "to convert iocb to wqe";
  14563. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14564. fail_msg = " - Wq is full";
  14565. else
  14566. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14567. if (fail_msg) {
  14568. /* Failed means we can't issue and need to cancel */
  14569. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14570. "2822 IOCB failed %s iotag 0x%x "
  14571. "xri 0x%x\n",
  14572. fail_msg,
  14573. piocbq->iotag, piocbq->sli4_xritag);
  14574. list_add_tail(&piocbq->list, &completions);
  14575. }
  14576. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14577. }
  14578. /* Cancel all the IOCBs that cannot be issued */
  14579. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14580. IOERR_SLI_ABORTED);
  14581. return pring->txq_cnt;
  14582. }