lpfc_sli.c 487 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909
  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. int rc;
  3539. /* Reset HBA */
  3540. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3541. "0295 Reset HBA Data: x%x x%x\n",
  3542. phba->pport->port_state, psli->sli_flag);
  3543. /* perform board reset */
  3544. phba->fc_eventTag = 0;
  3545. phba->link_events = 0;
  3546. phba->pport->fc_myDID = 0;
  3547. phba->pport->fc_prevDID = 0;
  3548. spin_lock_irq(&phba->hbalock);
  3549. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3550. phba->fcf.fcf_flag = 0;
  3551. spin_unlock_irq(&phba->hbalock);
  3552. /* Now physically reset the device */
  3553. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3554. "0389 Performing PCI function reset!\n");
  3555. /* Turn off parity checking and serr during the physical reset */
  3556. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3557. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3558. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3559. /* Perform FCoE PCI function reset */
  3560. lpfc_sli4_queue_destroy(phba);
  3561. rc = lpfc_pci_function_reset(phba);
  3562. /* Restore PCI cmd register */
  3563. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3564. return rc;
  3565. }
  3566. /**
  3567. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3568. * @phba: Pointer to HBA context object.
  3569. *
  3570. * This function is called in the SLI initialization code path to
  3571. * restart the HBA. The caller is not required to hold any lock.
  3572. * This function writes MBX_RESTART mailbox command to the SLIM and
  3573. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3574. * function to free any pending commands. The function enables
  3575. * POST only during the first initialization. The function returns zero.
  3576. * The function does not guarantee completion of MBX_RESTART mailbox
  3577. * command before the return of this function.
  3578. **/
  3579. static int
  3580. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3581. {
  3582. MAILBOX_t *mb;
  3583. struct lpfc_sli *psli;
  3584. volatile uint32_t word0;
  3585. void __iomem *to_slim;
  3586. uint32_t hba_aer_enabled;
  3587. spin_lock_irq(&phba->hbalock);
  3588. /* Take PCIe device Advanced Error Reporting (AER) state */
  3589. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3590. psli = &phba->sli;
  3591. /* Restart HBA */
  3592. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3593. "0337 Restart HBA Data: x%x x%x\n",
  3594. phba->pport->port_state, psli->sli_flag);
  3595. word0 = 0;
  3596. mb = (MAILBOX_t *) &word0;
  3597. mb->mbxCommand = MBX_RESTART;
  3598. mb->mbxHc = 1;
  3599. lpfc_reset_barrier(phba);
  3600. to_slim = phba->MBslimaddr;
  3601. writel(*(uint32_t *) mb, to_slim);
  3602. readl(to_slim); /* flush */
  3603. /* Only skip post after fc_ffinit is completed */
  3604. if (phba->pport->port_state)
  3605. word0 = 1; /* This is really setting up word1 */
  3606. else
  3607. word0 = 0; /* This is really setting up word1 */
  3608. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3609. writel(*(uint32_t *) mb, to_slim);
  3610. readl(to_slim); /* flush */
  3611. lpfc_sli_brdreset(phba);
  3612. phba->pport->stopped = 0;
  3613. phba->link_state = LPFC_INIT_START;
  3614. phba->hba_flag = 0;
  3615. spin_unlock_irq(&phba->hbalock);
  3616. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3617. psli->stats_start = get_seconds();
  3618. /* Give the INITFF and Post time to settle. */
  3619. mdelay(100);
  3620. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3621. if (hba_aer_enabled)
  3622. pci_disable_pcie_error_reporting(phba->pcidev);
  3623. lpfc_hba_down_post(phba);
  3624. return 0;
  3625. }
  3626. /**
  3627. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3628. * @phba: Pointer to HBA context object.
  3629. *
  3630. * This function is called in the SLI initialization code path to restart
  3631. * a SLI4 HBA. The caller is not required to hold any lock.
  3632. * At the end of the function, it calls lpfc_hba_down_post function to
  3633. * free any pending commands.
  3634. **/
  3635. static int
  3636. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3637. {
  3638. struct lpfc_sli *psli = &phba->sli;
  3639. uint32_t hba_aer_enabled;
  3640. int rc;
  3641. /* Restart HBA */
  3642. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3643. "0296 Restart HBA Data: x%x x%x\n",
  3644. phba->pport->port_state, psli->sli_flag);
  3645. /* Take PCIe device Advanced Error Reporting (AER) state */
  3646. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3647. rc = lpfc_sli4_brdreset(phba);
  3648. spin_lock_irq(&phba->hbalock);
  3649. phba->pport->stopped = 0;
  3650. phba->link_state = LPFC_INIT_START;
  3651. phba->hba_flag = 0;
  3652. spin_unlock_irq(&phba->hbalock);
  3653. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3654. psli->stats_start = get_seconds();
  3655. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3656. if (hba_aer_enabled)
  3657. pci_disable_pcie_error_reporting(phba->pcidev);
  3658. lpfc_hba_down_post(phba);
  3659. return rc;
  3660. }
  3661. /**
  3662. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3663. * @phba: Pointer to HBA context object.
  3664. *
  3665. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3666. * API jump table function pointer from the lpfc_hba struct.
  3667. **/
  3668. int
  3669. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3670. {
  3671. return phba->lpfc_sli_brdrestart(phba);
  3672. }
  3673. /**
  3674. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3675. * @phba: Pointer to HBA context object.
  3676. *
  3677. * This function is called after a HBA restart to wait for successful
  3678. * restart of the HBA. Successful restart of the HBA is indicated by
  3679. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3680. * iteration, the function will restart the HBA again. The function returns
  3681. * zero if HBA successfully restarted else returns negative error code.
  3682. **/
  3683. static int
  3684. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3685. {
  3686. uint32_t status, i = 0;
  3687. /* Read the HBA Host Status Register */
  3688. if (lpfc_readl(phba->HSregaddr, &status))
  3689. return -EIO;
  3690. /* Check status register to see what current state is */
  3691. i = 0;
  3692. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3693. /* Check every 10ms for 10 retries, then every 100ms for 90
  3694. * retries, then every 1 sec for 50 retires for a total of
  3695. * ~60 seconds before reset the board again and check every
  3696. * 1 sec for 50 retries. The up to 60 seconds before the
  3697. * board ready is required by the Falcon FIPS zeroization
  3698. * complete, and any reset the board in between shall cause
  3699. * restart of zeroization, further delay the board ready.
  3700. */
  3701. if (i++ >= 200) {
  3702. /* Adapter failed to init, timeout, status reg
  3703. <status> */
  3704. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3705. "0436 Adapter failed to init, "
  3706. "timeout, status reg x%x, "
  3707. "FW Data: A8 x%x AC x%x\n", status,
  3708. readl(phba->MBslimaddr + 0xa8),
  3709. readl(phba->MBslimaddr + 0xac));
  3710. phba->link_state = LPFC_HBA_ERROR;
  3711. return -ETIMEDOUT;
  3712. }
  3713. /* Check to see if any errors occurred during init */
  3714. if (status & HS_FFERM) {
  3715. /* ERROR: During chipset initialization */
  3716. /* Adapter failed to init, chipset, status reg
  3717. <status> */
  3718. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3719. "0437 Adapter failed to init, "
  3720. "chipset, status reg x%x, "
  3721. "FW Data: A8 x%x AC x%x\n", status,
  3722. readl(phba->MBslimaddr + 0xa8),
  3723. readl(phba->MBslimaddr + 0xac));
  3724. phba->link_state = LPFC_HBA_ERROR;
  3725. return -EIO;
  3726. }
  3727. if (i <= 10)
  3728. msleep(10);
  3729. else if (i <= 100)
  3730. msleep(100);
  3731. else
  3732. msleep(1000);
  3733. if (i == 150) {
  3734. /* Do post */
  3735. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3736. lpfc_sli_brdrestart(phba);
  3737. }
  3738. /* Read the HBA Host Status Register */
  3739. if (lpfc_readl(phba->HSregaddr, &status))
  3740. return -EIO;
  3741. }
  3742. /* Check to see if any errors occurred during init */
  3743. if (status & HS_FFERM) {
  3744. /* ERROR: During chipset initialization */
  3745. /* Adapter failed to init, chipset, status reg <status> */
  3746. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3747. "0438 Adapter failed to init, chipset, "
  3748. "status reg x%x, "
  3749. "FW Data: A8 x%x AC x%x\n", status,
  3750. readl(phba->MBslimaddr + 0xa8),
  3751. readl(phba->MBslimaddr + 0xac));
  3752. phba->link_state = LPFC_HBA_ERROR;
  3753. return -EIO;
  3754. }
  3755. /* Clear all interrupt enable conditions */
  3756. writel(0, phba->HCregaddr);
  3757. readl(phba->HCregaddr); /* flush */
  3758. /* setup host attn register */
  3759. writel(0xffffffff, phba->HAregaddr);
  3760. readl(phba->HAregaddr); /* flush */
  3761. return 0;
  3762. }
  3763. /**
  3764. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3765. *
  3766. * This function calculates and returns the number of HBQs required to be
  3767. * configured.
  3768. **/
  3769. int
  3770. lpfc_sli_hbq_count(void)
  3771. {
  3772. return ARRAY_SIZE(lpfc_hbq_defs);
  3773. }
  3774. /**
  3775. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3776. *
  3777. * This function adds the number of hbq entries in every HBQ to get
  3778. * the total number of hbq entries required for the HBA and returns
  3779. * the total count.
  3780. **/
  3781. static int
  3782. lpfc_sli_hbq_entry_count(void)
  3783. {
  3784. int hbq_count = lpfc_sli_hbq_count();
  3785. int count = 0;
  3786. int i;
  3787. for (i = 0; i < hbq_count; ++i)
  3788. count += lpfc_hbq_defs[i]->entry_count;
  3789. return count;
  3790. }
  3791. /**
  3792. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3793. *
  3794. * This function calculates amount of memory required for all hbq entries
  3795. * to be configured and returns the total memory required.
  3796. **/
  3797. int
  3798. lpfc_sli_hbq_size(void)
  3799. {
  3800. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3801. }
  3802. /**
  3803. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3804. * @phba: Pointer to HBA context object.
  3805. *
  3806. * This function is called during the SLI initialization to configure
  3807. * all the HBQs and post buffers to the HBQ. The caller is not
  3808. * required to hold any locks. This function will return zero if successful
  3809. * else it will return negative error code.
  3810. **/
  3811. static int
  3812. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3813. {
  3814. int hbq_count = lpfc_sli_hbq_count();
  3815. LPFC_MBOXQ_t *pmb;
  3816. MAILBOX_t *pmbox;
  3817. uint32_t hbqno;
  3818. uint32_t hbq_entry_index;
  3819. /* Get a Mailbox buffer to setup mailbox
  3820. * commands for HBA initialization
  3821. */
  3822. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3823. if (!pmb)
  3824. return -ENOMEM;
  3825. pmbox = &pmb->u.mb;
  3826. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3827. phba->link_state = LPFC_INIT_MBX_CMDS;
  3828. phba->hbq_in_use = 1;
  3829. hbq_entry_index = 0;
  3830. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3831. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3832. phba->hbqs[hbqno].hbqPutIdx = 0;
  3833. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3834. phba->hbqs[hbqno].entry_count =
  3835. lpfc_hbq_defs[hbqno]->entry_count;
  3836. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3837. hbq_entry_index, pmb);
  3838. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3839. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3840. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3841. mbxStatus <status>, ring <num> */
  3842. lpfc_printf_log(phba, KERN_ERR,
  3843. LOG_SLI | LOG_VPORT,
  3844. "1805 Adapter failed to init. "
  3845. "Data: x%x x%x x%x\n",
  3846. pmbox->mbxCommand,
  3847. pmbox->mbxStatus, hbqno);
  3848. phba->link_state = LPFC_HBA_ERROR;
  3849. mempool_free(pmb, phba->mbox_mem_pool);
  3850. return -ENXIO;
  3851. }
  3852. }
  3853. phba->hbq_count = hbq_count;
  3854. mempool_free(pmb, phba->mbox_mem_pool);
  3855. /* Initially populate or replenish the HBQs */
  3856. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3857. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3858. return 0;
  3859. }
  3860. /**
  3861. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3862. * @phba: Pointer to HBA context object.
  3863. *
  3864. * This function is called during the SLI initialization to configure
  3865. * all the HBQs and post buffers to the HBQ. The caller is not
  3866. * required to hold any locks. This function will return zero if successful
  3867. * else it will return negative error code.
  3868. **/
  3869. static int
  3870. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3871. {
  3872. phba->hbq_in_use = 1;
  3873. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3874. phba->hbq_count = 1;
  3875. /* Initially populate or replenish the HBQs */
  3876. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3877. return 0;
  3878. }
  3879. /**
  3880. * lpfc_sli_config_port - Issue config port mailbox command
  3881. * @phba: Pointer to HBA context object.
  3882. * @sli_mode: sli mode - 2/3
  3883. *
  3884. * This function is called by the sli intialization code path
  3885. * to issue config_port mailbox command. This function restarts the
  3886. * HBA firmware and issues a config_port mailbox command to configure
  3887. * the SLI interface in the sli mode specified by sli_mode
  3888. * variable. The caller is not required to hold any locks.
  3889. * The function returns 0 if successful, else returns negative error
  3890. * code.
  3891. **/
  3892. int
  3893. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3894. {
  3895. LPFC_MBOXQ_t *pmb;
  3896. uint32_t resetcount = 0, rc = 0, done = 0;
  3897. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3898. if (!pmb) {
  3899. phba->link_state = LPFC_HBA_ERROR;
  3900. return -ENOMEM;
  3901. }
  3902. phba->sli_rev = sli_mode;
  3903. while (resetcount < 2 && !done) {
  3904. spin_lock_irq(&phba->hbalock);
  3905. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3906. spin_unlock_irq(&phba->hbalock);
  3907. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3908. lpfc_sli_brdrestart(phba);
  3909. rc = lpfc_sli_chipset_init(phba);
  3910. if (rc)
  3911. break;
  3912. spin_lock_irq(&phba->hbalock);
  3913. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3914. spin_unlock_irq(&phba->hbalock);
  3915. resetcount++;
  3916. /* Call pre CONFIG_PORT mailbox command initialization. A
  3917. * value of 0 means the call was successful. Any other
  3918. * nonzero value is a failure, but if ERESTART is returned,
  3919. * the driver may reset the HBA and try again.
  3920. */
  3921. rc = lpfc_config_port_prep(phba);
  3922. if (rc == -ERESTART) {
  3923. phba->link_state = LPFC_LINK_UNKNOWN;
  3924. continue;
  3925. } else if (rc)
  3926. break;
  3927. phba->link_state = LPFC_INIT_MBX_CMDS;
  3928. lpfc_config_port(phba, pmb);
  3929. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3930. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3931. LPFC_SLI3_HBQ_ENABLED |
  3932. LPFC_SLI3_CRP_ENABLED |
  3933. LPFC_SLI3_BG_ENABLED |
  3934. LPFC_SLI3_DSS_ENABLED);
  3935. if (rc != MBX_SUCCESS) {
  3936. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3937. "0442 Adapter failed to init, mbxCmd x%x "
  3938. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3939. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3940. spin_lock_irq(&phba->hbalock);
  3941. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3942. spin_unlock_irq(&phba->hbalock);
  3943. rc = -ENXIO;
  3944. } else {
  3945. /* Allow asynchronous mailbox command to go through */
  3946. spin_lock_irq(&phba->hbalock);
  3947. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3948. spin_unlock_irq(&phba->hbalock);
  3949. done = 1;
  3950. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  3951. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  3952. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3953. "3110 Port did not grant ASABT\n");
  3954. }
  3955. }
  3956. if (!done) {
  3957. rc = -EINVAL;
  3958. goto do_prep_failed;
  3959. }
  3960. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3961. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3962. rc = -ENXIO;
  3963. goto do_prep_failed;
  3964. }
  3965. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3966. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3967. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3968. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3969. phba->max_vpi : phba->max_vports;
  3970. } else
  3971. phba->max_vpi = 0;
  3972. phba->fips_level = 0;
  3973. phba->fips_spec_rev = 0;
  3974. if (pmb->u.mb.un.varCfgPort.gdss) {
  3975. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3976. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3977. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3978. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3979. "2850 Security Crypto Active. FIPS x%d "
  3980. "(Spec Rev: x%d)",
  3981. phba->fips_level, phba->fips_spec_rev);
  3982. }
  3983. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3984. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3985. "2856 Config Port Security Crypto "
  3986. "Error: x%x ",
  3987. pmb->u.mb.un.varCfgPort.sec_err);
  3988. }
  3989. if (pmb->u.mb.un.varCfgPort.gerbm)
  3990. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  3991. if (pmb->u.mb.un.varCfgPort.gcrp)
  3992. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  3993. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  3994. phba->port_gp = phba->mbox->us.s3_pgp.port;
  3995. if (phba->cfg_enable_bg) {
  3996. if (pmb->u.mb.un.varCfgPort.gbg)
  3997. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  3998. else
  3999. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4000. "0443 Adapter did not grant "
  4001. "BlockGuard\n");
  4002. }
  4003. } else {
  4004. phba->hbq_get = NULL;
  4005. phba->port_gp = phba->mbox->us.s2.port;
  4006. phba->max_vpi = 0;
  4007. }
  4008. do_prep_failed:
  4009. mempool_free(pmb, phba->mbox_mem_pool);
  4010. return rc;
  4011. }
  4012. /**
  4013. * lpfc_sli_hba_setup - SLI intialization function
  4014. * @phba: Pointer to HBA context object.
  4015. *
  4016. * This function is the main SLI intialization function. This function
  4017. * is called by the HBA intialization code, HBA reset code and HBA
  4018. * error attention handler code. Caller is not required to hold any
  4019. * locks. This function issues config_port mailbox command to configure
  4020. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4021. * calls the config_port_post function to issue init_link mailbox
  4022. * command and to start the discovery. The function will return zero
  4023. * if successful, else it will return negative error code.
  4024. **/
  4025. int
  4026. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4027. {
  4028. uint32_t rc;
  4029. int mode = 3, i;
  4030. int longs;
  4031. switch (lpfc_sli_mode) {
  4032. case 2:
  4033. if (phba->cfg_enable_npiv) {
  4034. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4035. "1824 NPIV enabled: Override lpfc_sli_mode "
  4036. "parameter (%d) to auto (0).\n",
  4037. lpfc_sli_mode);
  4038. break;
  4039. }
  4040. mode = 2;
  4041. break;
  4042. case 0:
  4043. case 3:
  4044. break;
  4045. default:
  4046. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4047. "1819 Unrecognized lpfc_sli_mode "
  4048. "parameter: %d.\n", lpfc_sli_mode);
  4049. break;
  4050. }
  4051. rc = lpfc_sli_config_port(phba, mode);
  4052. if (rc && lpfc_sli_mode == 3)
  4053. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4054. "1820 Unable to select SLI-3. "
  4055. "Not supported by adapter.\n");
  4056. if (rc && mode != 2)
  4057. rc = lpfc_sli_config_port(phba, 2);
  4058. if (rc)
  4059. goto lpfc_sli_hba_setup_error;
  4060. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4061. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4062. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4063. if (!rc) {
  4064. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4065. "2709 This device supports "
  4066. "Advanced Error Reporting (AER)\n");
  4067. spin_lock_irq(&phba->hbalock);
  4068. phba->hba_flag |= HBA_AER_ENABLED;
  4069. spin_unlock_irq(&phba->hbalock);
  4070. } else {
  4071. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4072. "2708 This device does not support "
  4073. "Advanced Error Reporting (AER)\n");
  4074. phba->cfg_aer_support = 0;
  4075. }
  4076. }
  4077. if (phba->sli_rev == 3) {
  4078. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4079. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4080. } else {
  4081. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4082. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4083. phba->sli3_options = 0;
  4084. }
  4085. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4086. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4087. phba->sli_rev, phba->max_vpi);
  4088. rc = lpfc_sli_ring_map(phba);
  4089. if (rc)
  4090. goto lpfc_sli_hba_setup_error;
  4091. /* Initialize VPIs. */
  4092. if (phba->sli_rev == LPFC_SLI_REV3) {
  4093. /*
  4094. * The VPI bitmask and physical ID array are allocated
  4095. * and initialized once only - at driver load. A port
  4096. * reset doesn't need to reinitialize this memory.
  4097. */
  4098. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4099. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4100. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4101. GFP_KERNEL);
  4102. if (!phba->vpi_bmask) {
  4103. rc = -ENOMEM;
  4104. goto lpfc_sli_hba_setup_error;
  4105. }
  4106. phba->vpi_ids = kzalloc(
  4107. (phba->max_vpi+1) * sizeof(uint16_t),
  4108. GFP_KERNEL);
  4109. if (!phba->vpi_ids) {
  4110. kfree(phba->vpi_bmask);
  4111. rc = -ENOMEM;
  4112. goto lpfc_sli_hba_setup_error;
  4113. }
  4114. for (i = 0; i < phba->max_vpi; i++)
  4115. phba->vpi_ids[i] = i;
  4116. }
  4117. }
  4118. /* Init HBQs */
  4119. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4120. rc = lpfc_sli_hbq_setup(phba);
  4121. if (rc)
  4122. goto lpfc_sli_hba_setup_error;
  4123. }
  4124. spin_lock_irq(&phba->hbalock);
  4125. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4126. spin_unlock_irq(&phba->hbalock);
  4127. rc = lpfc_config_port_post(phba);
  4128. if (rc)
  4129. goto lpfc_sli_hba_setup_error;
  4130. return rc;
  4131. lpfc_sli_hba_setup_error:
  4132. phba->link_state = LPFC_HBA_ERROR;
  4133. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4134. "0445 Firmware initialization failed\n");
  4135. return rc;
  4136. }
  4137. /**
  4138. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4139. * @phba: Pointer to HBA context object.
  4140. * @mboxq: mailbox pointer.
  4141. * This function issue a dump mailbox command to read config region
  4142. * 23 and parse the records in the region and populate driver
  4143. * data structure.
  4144. **/
  4145. static int
  4146. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4147. {
  4148. LPFC_MBOXQ_t *mboxq;
  4149. struct lpfc_dmabuf *mp;
  4150. struct lpfc_mqe *mqe;
  4151. uint32_t data_length;
  4152. int rc;
  4153. /* Program the default value of vlan_id and fc_map */
  4154. phba->valid_vlan = 0;
  4155. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4156. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4157. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4158. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4159. if (!mboxq)
  4160. return -ENOMEM;
  4161. mqe = &mboxq->u.mqe;
  4162. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4163. rc = -ENOMEM;
  4164. goto out_free_mboxq;
  4165. }
  4166. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4167. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4168. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4169. "(%d):2571 Mailbox cmd x%x Status x%x "
  4170. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4171. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4172. "CQ: x%x x%x x%x x%x\n",
  4173. mboxq->vport ? mboxq->vport->vpi : 0,
  4174. bf_get(lpfc_mqe_command, mqe),
  4175. bf_get(lpfc_mqe_status, mqe),
  4176. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4177. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4178. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4179. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4180. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4181. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4182. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4183. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4184. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4185. mboxq->mcqe.word0,
  4186. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4187. mboxq->mcqe.trailer);
  4188. if (rc) {
  4189. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4190. kfree(mp);
  4191. rc = -EIO;
  4192. goto out_free_mboxq;
  4193. }
  4194. data_length = mqe->un.mb_words[5];
  4195. if (data_length > DMP_RGN23_SIZE) {
  4196. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4197. kfree(mp);
  4198. rc = -EIO;
  4199. goto out_free_mboxq;
  4200. }
  4201. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4202. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4203. kfree(mp);
  4204. rc = 0;
  4205. out_free_mboxq:
  4206. mempool_free(mboxq, phba->mbox_mem_pool);
  4207. return rc;
  4208. }
  4209. /**
  4210. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4211. * @phba: pointer to lpfc hba data structure.
  4212. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4213. * @vpd: pointer to the memory to hold resulting port vpd data.
  4214. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4215. * On output, the number of data bytes in @vpd.
  4216. *
  4217. * This routine executes a READ_REV SLI4 mailbox command. In
  4218. * addition, this routine gets the port vpd data.
  4219. *
  4220. * Return codes
  4221. * 0 - successful
  4222. * -ENOMEM - could not allocated memory.
  4223. **/
  4224. static int
  4225. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4226. uint8_t *vpd, uint32_t *vpd_size)
  4227. {
  4228. int rc = 0;
  4229. uint32_t dma_size;
  4230. struct lpfc_dmabuf *dmabuf;
  4231. struct lpfc_mqe *mqe;
  4232. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4233. if (!dmabuf)
  4234. return -ENOMEM;
  4235. /*
  4236. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4237. * mailbox command.
  4238. */
  4239. dma_size = *vpd_size;
  4240. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4241. dma_size,
  4242. &dmabuf->phys,
  4243. GFP_KERNEL);
  4244. if (!dmabuf->virt) {
  4245. kfree(dmabuf);
  4246. return -ENOMEM;
  4247. }
  4248. memset(dmabuf->virt, 0, dma_size);
  4249. /*
  4250. * The SLI4 implementation of READ_REV conflicts at word1,
  4251. * bits 31:16 and SLI4 adds vpd functionality not present
  4252. * in SLI3. This code corrects the conflicts.
  4253. */
  4254. lpfc_read_rev(phba, mboxq);
  4255. mqe = &mboxq->u.mqe;
  4256. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4257. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4258. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4259. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4260. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4261. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4262. if (rc) {
  4263. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4264. dmabuf->virt, dmabuf->phys);
  4265. kfree(dmabuf);
  4266. return -EIO;
  4267. }
  4268. /*
  4269. * The available vpd length cannot be bigger than the
  4270. * DMA buffer passed to the port. Catch the less than
  4271. * case and update the caller's size.
  4272. */
  4273. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4274. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4275. memcpy(vpd, dmabuf->virt, *vpd_size);
  4276. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4277. dmabuf->virt, dmabuf->phys);
  4278. kfree(dmabuf);
  4279. return 0;
  4280. }
  4281. /**
  4282. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4283. * @phba: pointer to lpfc hba data structure.
  4284. *
  4285. * This routine retrieves SLI4 device physical port name this PCI function
  4286. * is attached to.
  4287. *
  4288. * Return codes
  4289. * 0 - sucessful
  4290. * otherwise - failed to retrieve physical port name
  4291. **/
  4292. static int
  4293. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4294. {
  4295. LPFC_MBOXQ_t *mboxq;
  4296. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4297. struct lpfc_controller_attribute *cntl_attr;
  4298. struct lpfc_mbx_get_port_name *get_port_name;
  4299. void *virtaddr = NULL;
  4300. uint32_t alloclen, reqlen;
  4301. uint32_t shdr_status, shdr_add_status;
  4302. union lpfc_sli4_cfg_shdr *shdr;
  4303. char cport_name = 0;
  4304. int rc;
  4305. /* We assume nothing at this point */
  4306. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4307. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4308. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4309. if (!mboxq)
  4310. return -ENOMEM;
  4311. /* obtain link type and link number via READ_CONFIG */
  4312. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4313. lpfc_sli4_read_config(phba);
  4314. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4315. goto retrieve_ppname;
  4316. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4317. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4318. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4319. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4320. LPFC_SLI4_MBX_NEMBED);
  4321. if (alloclen < reqlen) {
  4322. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4323. "3084 Allocated DMA memory size (%d) is "
  4324. "less than the requested DMA memory size "
  4325. "(%d)\n", alloclen, reqlen);
  4326. rc = -ENOMEM;
  4327. goto out_free_mboxq;
  4328. }
  4329. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4330. virtaddr = mboxq->sge_array->addr[0];
  4331. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4332. shdr = &mbx_cntl_attr->cfg_shdr;
  4333. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4334. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4335. if (shdr_status || shdr_add_status || rc) {
  4336. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4337. "3085 Mailbox x%x (x%x/x%x) failed, "
  4338. "rc:x%x, status:x%x, add_status:x%x\n",
  4339. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4340. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4341. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4342. rc, shdr_status, shdr_add_status);
  4343. rc = -ENXIO;
  4344. goto out_free_mboxq;
  4345. }
  4346. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4347. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4348. phba->sli4_hba.lnk_info.lnk_tp =
  4349. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4350. phba->sli4_hba.lnk_info.lnk_no =
  4351. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4352. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4353. "3086 lnk_type:%d, lnk_numb:%d\n",
  4354. phba->sli4_hba.lnk_info.lnk_tp,
  4355. phba->sli4_hba.lnk_info.lnk_no);
  4356. retrieve_ppname:
  4357. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4358. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4359. sizeof(struct lpfc_mbx_get_port_name) -
  4360. sizeof(struct lpfc_sli4_cfg_mhdr),
  4361. LPFC_SLI4_MBX_EMBED);
  4362. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4363. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4364. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4365. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4366. phba->sli4_hba.lnk_info.lnk_tp);
  4367. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4368. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4369. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4370. if (shdr_status || shdr_add_status || rc) {
  4371. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4372. "3087 Mailbox x%x (x%x/x%x) failed: "
  4373. "rc:x%x, status:x%x, add_status:x%x\n",
  4374. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4375. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4376. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4377. rc, shdr_status, shdr_add_status);
  4378. rc = -ENXIO;
  4379. goto out_free_mboxq;
  4380. }
  4381. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4382. case LPFC_LINK_NUMBER_0:
  4383. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4384. &get_port_name->u.response);
  4385. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4386. break;
  4387. case LPFC_LINK_NUMBER_1:
  4388. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4389. &get_port_name->u.response);
  4390. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4391. break;
  4392. case LPFC_LINK_NUMBER_2:
  4393. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4394. &get_port_name->u.response);
  4395. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4396. break;
  4397. case LPFC_LINK_NUMBER_3:
  4398. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4399. &get_port_name->u.response);
  4400. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4401. break;
  4402. default:
  4403. break;
  4404. }
  4405. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4406. phba->Port[0] = cport_name;
  4407. phba->Port[1] = '\0';
  4408. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4409. "3091 SLI get port name: %s\n", phba->Port);
  4410. }
  4411. out_free_mboxq:
  4412. if (rc != MBX_TIMEOUT) {
  4413. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4414. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4415. else
  4416. mempool_free(mboxq, phba->mbox_mem_pool);
  4417. }
  4418. return rc;
  4419. }
  4420. /**
  4421. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4422. * @phba: pointer to lpfc hba data structure.
  4423. *
  4424. * This routine is called to explicitly arm the SLI4 device's completion and
  4425. * event queues
  4426. **/
  4427. static void
  4428. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4429. {
  4430. uint8_t fcp_eqidx;
  4431. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4432. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4433. fcp_eqidx = 0;
  4434. if (phba->sli4_hba.fcp_cq) {
  4435. do
  4436. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4437. LPFC_QUEUE_REARM);
  4438. while (++fcp_eqidx < phba->cfg_fcp_eq_count);
  4439. }
  4440. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4441. if (phba->sli4_hba.fp_eq) {
  4442. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count;
  4443. fcp_eqidx++)
  4444. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4445. LPFC_QUEUE_REARM);
  4446. }
  4447. }
  4448. /**
  4449. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4450. * @phba: Pointer to HBA context object.
  4451. * @type: The resource extent type.
  4452. * @extnt_count: buffer to hold port available extent count.
  4453. * @extnt_size: buffer to hold element count per extent.
  4454. *
  4455. * This function calls the port and retrievs the number of available
  4456. * extents and their size for a particular extent type.
  4457. *
  4458. * Returns: 0 if successful. Nonzero otherwise.
  4459. **/
  4460. int
  4461. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4462. uint16_t *extnt_count, uint16_t *extnt_size)
  4463. {
  4464. int rc = 0;
  4465. uint32_t length;
  4466. uint32_t mbox_tmo;
  4467. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4468. LPFC_MBOXQ_t *mbox;
  4469. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4470. if (!mbox)
  4471. return -ENOMEM;
  4472. /* Find out how many extents are available for this resource type */
  4473. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4474. sizeof(struct lpfc_sli4_cfg_mhdr));
  4475. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4476. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4477. length, LPFC_SLI4_MBX_EMBED);
  4478. /* Send an extents count of 0 - the GET doesn't use it. */
  4479. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4480. LPFC_SLI4_MBX_EMBED);
  4481. if (unlikely(rc)) {
  4482. rc = -EIO;
  4483. goto err_exit;
  4484. }
  4485. if (!phba->sli4_hba.intr_enable)
  4486. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4487. else {
  4488. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4489. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4490. }
  4491. if (unlikely(rc)) {
  4492. rc = -EIO;
  4493. goto err_exit;
  4494. }
  4495. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4496. if (bf_get(lpfc_mbox_hdr_status,
  4497. &rsrc_info->header.cfg_shdr.response)) {
  4498. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4499. "2930 Failed to get resource extents "
  4500. "Status 0x%x Add'l Status 0x%x\n",
  4501. bf_get(lpfc_mbox_hdr_status,
  4502. &rsrc_info->header.cfg_shdr.response),
  4503. bf_get(lpfc_mbox_hdr_add_status,
  4504. &rsrc_info->header.cfg_shdr.response));
  4505. rc = -EIO;
  4506. goto err_exit;
  4507. }
  4508. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4509. &rsrc_info->u.rsp);
  4510. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4511. &rsrc_info->u.rsp);
  4512. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4513. "3162 Retrieved extents type-%d from port: count:%d, "
  4514. "size:%d\n", type, *extnt_count, *extnt_size);
  4515. err_exit:
  4516. mempool_free(mbox, phba->mbox_mem_pool);
  4517. return rc;
  4518. }
  4519. /**
  4520. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4521. * @phba: Pointer to HBA context object.
  4522. * @type: The extent type to check.
  4523. *
  4524. * This function reads the current available extents from the port and checks
  4525. * if the extent count or extent size has changed since the last access.
  4526. * Callers use this routine post port reset to understand if there is a
  4527. * extent reprovisioning requirement.
  4528. *
  4529. * Returns:
  4530. * -Error: error indicates problem.
  4531. * 1: Extent count or size has changed.
  4532. * 0: No changes.
  4533. **/
  4534. static int
  4535. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4536. {
  4537. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4538. uint16_t size_diff, rsrc_ext_size;
  4539. int rc = 0;
  4540. struct lpfc_rsrc_blks *rsrc_entry;
  4541. struct list_head *rsrc_blk_list = NULL;
  4542. size_diff = 0;
  4543. curr_ext_cnt = 0;
  4544. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4545. &rsrc_ext_cnt,
  4546. &rsrc_ext_size);
  4547. if (unlikely(rc))
  4548. return -EIO;
  4549. switch (type) {
  4550. case LPFC_RSC_TYPE_FCOE_RPI:
  4551. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4552. break;
  4553. case LPFC_RSC_TYPE_FCOE_VPI:
  4554. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4555. break;
  4556. case LPFC_RSC_TYPE_FCOE_XRI:
  4557. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4558. break;
  4559. case LPFC_RSC_TYPE_FCOE_VFI:
  4560. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4561. break;
  4562. default:
  4563. break;
  4564. }
  4565. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4566. curr_ext_cnt++;
  4567. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4568. size_diff++;
  4569. }
  4570. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4571. rc = 1;
  4572. return rc;
  4573. }
  4574. /**
  4575. * lpfc_sli4_cfg_post_extnts -
  4576. * @phba: Pointer to HBA context object.
  4577. * @extnt_cnt - number of available extents.
  4578. * @type - the extent type (rpi, xri, vfi, vpi).
  4579. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4580. * @mbox - pointer to the caller's allocated mailbox structure.
  4581. *
  4582. * This function executes the extents allocation request. It also
  4583. * takes care of the amount of memory needed to allocate or get the
  4584. * allocated extents. It is the caller's responsibility to evaluate
  4585. * the response.
  4586. *
  4587. * Returns:
  4588. * -Error: Error value describes the condition found.
  4589. * 0: if successful
  4590. **/
  4591. static int
  4592. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  4593. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4594. {
  4595. int rc = 0;
  4596. uint32_t req_len;
  4597. uint32_t emb_len;
  4598. uint32_t alloc_len, mbox_tmo;
  4599. /* Calculate the total requested length of the dma memory */
  4600. req_len = extnt_cnt * sizeof(uint16_t);
  4601. /*
  4602. * Calculate the size of an embedded mailbox. The uint32_t
  4603. * accounts for extents-specific word.
  4604. */
  4605. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4606. sizeof(uint32_t);
  4607. /*
  4608. * Presume the allocation and response will fit into an embedded
  4609. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4610. */
  4611. *emb = LPFC_SLI4_MBX_EMBED;
  4612. if (req_len > emb_len) {
  4613. req_len = extnt_cnt * sizeof(uint16_t) +
  4614. sizeof(union lpfc_sli4_cfg_shdr) +
  4615. sizeof(uint32_t);
  4616. *emb = LPFC_SLI4_MBX_NEMBED;
  4617. }
  4618. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4619. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4620. req_len, *emb);
  4621. if (alloc_len < req_len) {
  4622. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4623. "2982 Allocated DMA memory size (x%x) is "
  4624. "less than the requested DMA memory "
  4625. "size (x%x)\n", alloc_len, req_len);
  4626. return -ENOMEM;
  4627. }
  4628. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  4629. if (unlikely(rc))
  4630. return -EIO;
  4631. if (!phba->sli4_hba.intr_enable)
  4632. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4633. else {
  4634. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4635. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4636. }
  4637. if (unlikely(rc))
  4638. rc = -EIO;
  4639. return rc;
  4640. }
  4641. /**
  4642. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4643. * @phba: Pointer to HBA context object.
  4644. * @type: The resource extent type to allocate.
  4645. *
  4646. * This function allocates the number of elements for the specified
  4647. * resource type.
  4648. **/
  4649. static int
  4650. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4651. {
  4652. bool emb = false;
  4653. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4654. uint16_t rsrc_id, rsrc_start, j, k;
  4655. uint16_t *ids;
  4656. int i, rc;
  4657. unsigned long longs;
  4658. unsigned long *bmask;
  4659. struct lpfc_rsrc_blks *rsrc_blks;
  4660. LPFC_MBOXQ_t *mbox;
  4661. uint32_t length;
  4662. struct lpfc_id_range *id_array = NULL;
  4663. void *virtaddr = NULL;
  4664. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4665. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4666. struct list_head *ext_blk_list;
  4667. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4668. &rsrc_cnt,
  4669. &rsrc_size);
  4670. if (unlikely(rc))
  4671. return -EIO;
  4672. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4673. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4674. "3009 No available Resource Extents "
  4675. "for resource type 0x%x: Count: 0x%x, "
  4676. "Size 0x%x\n", type, rsrc_cnt,
  4677. rsrc_size);
  4678. return -ENOMEM;
  4679. }
  4680. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  4681. "2903 Post resource extents type-0x%x: "
  4682. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  4683. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4684. if (!mbox)
  4685. return -ENOMEM;
  4686. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  4687. if (unlikely(rc)) {
  4688. rc = -EIO;
  4689. goto err_exit;
  4690. }
  4691. /*
  4692. * Figure out where the response is located. Then get local pointers
  4693. * to the response data. The port does not guarantee to respond to
  4694. * all extents counts request so update the local variable with the
  4695. * allocated count from the port.
  4696. */
  4697. if (emb == LPFC_SLI4_MBX_EMBED) {
  4698. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4699. id_array = &rsrc_ext->u.rsp.id[0];
  4700. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4701. } else {
  4702. virtaddr = mbox->sge_array->addr[0];
  4703. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4704. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4705. id_array = &n_rsrc->id;
  4706. }
  4707. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4708. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4709. /*
  4710. * Based on the resource size and count, correct the base and max
  4711. * resource values.
  4712. */
  4713. length = sizeof(struct lpfc_rsrc_blks);
  4714. switch (type) {
  4715. case LPFC_RSC_TYPE_FCOE_RPI:
  4716. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4717. sizeof(unsigned long),
  4718. GFP_KERNEL);
  4719. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4720. rc = -ENOMEM;
  4721. goto err_exit;
  4722. }
  4723. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4724. sizeof(uint16_t),
  4725. GFP_KERNEL);
  4726. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4727. kfree(phba->sli4_hba.rpi_bmask);
  4728. rc = -ENOMEM;
  4729. goto err_exit;
  4730. }
  4731. /*
  4732. * The next_rpi was initialized with the maximum available
  4733. * count but the port may allocate a smaller number. Catch
  4734. * that case and update the next_rpi.
  4735. */
  4736. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4737. /* Initialize local ptrs for common extent processing later. */
  4738. bmask = phba->sli4_hba.rpi_bmask;
  4739. ids = phba->sli4_hba.rpi_ids;
  4740. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4741. break;
  4742. case LPFC_RSC_TYPE_FCOE_VPI:
  4743. phba->vpi_bmask = kzalloc(longs *
  4744. sizeof(unsigned long),
  4745. GFP_KERNEL);
  4746. if (unlikely(!phba->vpi_bmask)) {
  4747. rc = -ENOMEM;
  4748. goto err_exit;
  4749. }
  4750. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4751. sizeof(uint16_t),
  4752. GFP_KERNEL);
  4753. if (unlikely(!phba->vpi_ids)) {
  4754. kfree(phba->vpi_bmask);
  4755. rc = -ENOMEM;
  4756. goto err_exit;
  4757. }
  4758. /* Initialize local ptrs for common extent processing later. */
  4759. bmask = phba->vpi_bmask;
  4760. ids = phba->vpi_ids;
  4761. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4762. break;
  4763. case LPFC_RSC_TYPE_FCOE_XRI:
  4764. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4765. sizeof(unsigned long),
  4766. GFP_KERNEL);
  4767. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4768. rc = -ENOMEM;
  4769. goto err_exit;
  4770. }
  4771. phba->sli4_hba.max_cfg_param.xri_used = 0;
  4772. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4773. sizeof(uint16_t),
  4774. GFP_KERNEL);
  4775. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4776. kfree(phba->sli4_hba.xri_bmask);
  4777. rc = -ENOMEM;
  4778. goto err_exit;
  4779. }
  4780. /* Initialize local ptrs for common extent processing later. */
  4781. bmask = phba->sli4_hba.xri_bmask;
  4782. ids = phba->sli4_hba.xri_ids;
  4783. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4784. break;
  4785. case LPFC_RSC_TYPE_FCOE_VFI:
  4786. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4787. sizeof(unsigned long),
  4788. GFP_KERNEL);
  4789. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4790. rc = -ENOMEM;
  4791. goto err_exit;
  4792. }
  4793. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4794. sizeof(uint16_t),
  4795. GFP_KERNEL);
  4796. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4797. kfree(phba->sli4_hba.vfi_bmask);
  4798. rc = -ENOMEM;
  4799. goto err_exit;
  4800. }
  4801. /* Initialize local ptrs for common extent processing later. */
  4802. bmask = phba->sli4_hba.vfi_bmask;
  4803. ids = phba->sli4_hba.vfi_ids;
  4804. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4805. break;
  4806. default:
  4807. /* Unsupported Opcode. Fail call. */
  4808. id_array = NULL;
  4809. bmask = NULL;
  4810. ids = NULL;
  4811. ext_blk_list = NULL;
  4812. goto err_exit;
  4813. }
  4814. /*
  4815. * Complete initializing the extent configuration with the
  4816. * allocated ids assigned to this function. The bitmask serves
  4817. * as an index into the array and manages the available ids. The
  4818. * array just stores the ids communicated to the port via the wqes.
  4819. */
  4820. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4821. if ((i % 2) == 0)
  4822. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4823. &id_array[k]);
  4824. else
  4825. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4826. &id_array[k]);
  4827. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4828. if (unlikely(!rsrc_blks)) {
  4829. rc = -ENOMEM;
  4830. kfree(bmask);
  4831. kfree(ids);
  4832. goto err_exit;
  4833. }
  4834. rsrc_blks->rsrc_start = rsrc_id;
  4835. rsrc_blks->rsrc_size = rsrc_size;
  4836. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4837. rsrc_start = rsrc_id;
  4838. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4839. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4840. lpfc_sli4_get_els_iocb_cnt(phba);
  4841. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4842. ids[j] = rsrc_id;
  4843. rsrc_id++;
  4844. j++;
  4845. }
  4846. /* Entire word processed. Get next word.*/
  4847. if ((i % 2) == 1)
  4848. k++;
  4849. }
  4850. err_exit:
  4851. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4852. return rc;
  4853. }
  4854. /**
  4855. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4856. * @phba: Pointer to HBA context object.
  4857. * @type: the extent's type.
  4858. *
  4859. * This function deallocates all extents of a particular resource type.
  4860. * SLI4 does not allow for deallocating a particular extent range. It
  4861. * is the caller's responsibility to release all kernel memory resources.
  4862. **/
  4863. static int
  4864. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4865. {
  4866. int rc;
  4867. uint32_t length, mbox_tmo = 0;
  4868. LPFC_MBOXQ_t *mbox;
  4869. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4870. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4871. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4872. if (!mbox)
  4873. return -ENOMEM;
  4874. /*
  4875. * This function sends an embedded mailbox because it only sends the
  4876. * the resource type. All extents of this type are released by the
  4877. * port.
  4878. */
  4879. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4880. sizeof(struct lpfc_sli4_cfg_mhdr));
  4881. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4882. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4883. length, LPFC_SLI4_MBX_EMBED);
  4884. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4885. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4886. LPFC_SLI4_MBX_EMBED);
  4887. if (unlikely(rc)) {
  4888. rc = -EIO;
  4889. goto out_free_mbox;
  4890. }
  4891. if (!phba->sli4_hba.intr_enable)
  4892. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4893. else {
  4894. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4895. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4896. }
  4897. if (unlikely(rc)) {
  4898. rc = -EIO;
  4899. goto out_free_mbox;
  4900. }
  4901. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4902. if (bf_get(lpfc_mbox_hdr_status,
  4903. &dealloc_rsrc->header.cfg_shdr.response)) {
  4904. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4905. "2919 Failed to release resource extents "
  4906. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4907. "Resource memory not released.\n",
  4908. type,
  4909. bf_get(lpfc_mbox_hdr_status,
  4910. &dealloc_rsrc->header.cfg_shdr.response),
  4911. bf_get(lpfc_mbox_hdr_add_status,
  4912. &dealloc_rsrc->header.cfg_shdr.response));
  4913. rc = -EIO;
  4914. goto out_free_mbox;
  4915. }
  4916. /* Release kernel memory resources for the specific type. */
  4917. switch (type) {
  4918. case LPFC_RSC_TYPE_FCOE_VPI:
  4919. kfree(phba->vpi_bmask);
  4920. kfree(phba->vpi_ids);
  4921. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4922. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4923. &phba->lpfc_vpi_blk_list, list) {
  4924. list_del_init(&rsrc_blk->list);
  4925. kfree(rsrc_blk);
  4926. }
  4927. break;
  4928. case LPFC_RSC_TYPE_FCOE_XRI:
  4929. kfree(phba->sli4_hba.xri_bmask);
  4930. kfree(phba->sli4_hba.xri_ids);
  4931. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4932. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  4933. list_del_init(&rsrc_blk->list);
  4934. kfree(rsrc_blk);
  4935. }
  4936. break;
  4937. case LPFC_RSC_TYPE_FCOE_VFI:
  4938. kfree(phba->sli4_hba.vfi_bmask);
  4939. kfree(phba->sli4_hba.vfi_ids);
  4940. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4941. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4942. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  4943. list_del_init(&rsrc_blk->list);
  4944. kfree(rsrc_blk);
  4945. }
  4946. break;
  4947. case LPFC_RSC_TYPE_FCOE_RPI:
  4948. /* RPI bitmask and physical id array are cleaned up earlier. */
  4949. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4950. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  4951. list_del_init(&rsrc_blk->list);
  4952. kfree(rsrc_blk);
  4953. }
  4954. break;
  4955. default:
  4956. break;
  4957. }
  4958. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4959. out_free_mbox:
  4960. mempool_free(mbox, phba->mbox_mem_pool);
  4961. return rc;
  4962. }
  4963. /**
  4964. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  4965. * @phba: Pointer to HBA context object.
  4966. *
  4967. * This function allocates all SLI4 resource identifiers.
  4968. **/
  4969. int
  4970. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  4971. {
  4972. int i, rc, error = 0;
  4973. uint16_t count, base;
  4974. unsigned long longs;
  4975. if (!phba->sli4_hba.rpi_hdrs_in_use)
  4976. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  4977. if (phba->sli4_hba.extents_in_use) {
  4978. /*
  4979. * The port supports resource extents. The XRI, VPI, VFI, RPI
  4980. * resource extent count must be read and allocated before
  4981. * provisioning the resource id arrays.
  4982. */
  4983. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  4984. LPFC_IDX_RSRC_RDY) {
  4985. /*
  4986. * Extent-based resources are set - the driver could
  4987. * be in a port reset. Figure out if any corrective
  4988. * actions need to be taken.
  4989. */
  4990. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4991. LPFC_RSC_TYPE_FCOE_VFI);
  4992. if (rc != 0)
  4993. error++;
  4994. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4995. LPFC_RSC_TYPE_FCOE_VPI);
  4996. if (rc != 0)
  4997. error++;
  4998. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4999. LPFC_RSC_TYPE_FCOE_XRI);
  5000. if (rc != 0)
  5001. error++;
  5002. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5003. LPFC_RSC_TYPE_FCOE_RPI);
  5004. if (rc != 0)
  5005. error++;
  5006. /*
  5007. * It's possible that the number of resources
  5008. * provided to this port instance changed between
  5009. * resets. Detect this condition and reallocate
  5010. * resources. Otherwise, there is no action.
  5011. */
  5012. if (error) {
  5013. lpfc_printf_log(phba, KERN_INFO,
  5014. LOG_MBOX | LOG_INIT,
  5015. "2931 Detected extent resource "
  5016. "change. Reallocating all "
  5017. "extents.\n");
  5018. rc = lpfc_sli4_dealloc_extent(phba,
  5019. LPFC_RSC_TYPE_FCOE_VFI);
  5020. rc = lpfc_sli4_dealloc_extent(phba,
  5021. LPFC_RSC_TYPE_FCOE_VPI);
  5022. rc = lpfc_sli4_dealloc_extent(phba,
  5023. LPFC_RSC_TYPE_FCOE_XRI);
  5024. rc = lpfc_sli4_dealloc_extent(phba,
  5025. LPFC_RSC_TYPE_FCOE_RPI);
  5026. } else
  5027. return 0;
  5028. }
  5029. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5030. if (unlikely(rc))
  5031. goto err_exit;
  5032. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5033. if (unlikely(rc))
  5034. goto err_exit;
  5035. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5036. if (unlikely(rc))
  5037. goto err_exit;
  5038. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5039. if (unlikely(rc))
  5040. goto err_exit;
  5041. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5042. LPFC_IDX_RSRC_RDY);
  5043. return rc;
  5044. } else {
  5045. /*
  5046. * The port does not support resource extents. The XRI, VPI,
  5047. * VFI, RPI resource ids were determined from READ_CONFIG.
  5048. * Just allocate the bitmasks and provision the resource id
  5049. * arrays. If a port reset is active, the resources don't
  5050. * need any action - just exit.
  5051. */
  5052. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5053. LPFC_IDX_RSRC_RDY) {
  5054. lpfc_sli4_dealloc_resource_identifiers(phba);
  5055. lpfc_sli4_remove_rpis(phba);
  5056. }
  5057. /* RPIs. */
  5058. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5059. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5060. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5061. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5062. sizeof(unsigned long),
  5063. GFP_KERNEL);
  5064. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5065. rc = -ENOMEM;
  5066. goto err_exit;
  5067. }
  5068. phba->sli4_hba.rpi_ids = kzalloc(count *
  5069. sizeof(uint16_t),
  5070. GFP_KERNEL);
  5071. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5072. rc = -ENOMEM;
  5073. goto free_rpi_bmask;
  5074. }
  5075. for (i = 0; i < count; i++)
  5076. phba->sli4_hba.rpi_ids[i] = base + i;
  5077. /* VPIs. */
  5078. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5079. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5080. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5081. phba->vpi_bmask = kzalloc(longs *
  5082. sizeof(unsigned long),
  5083. GFP_KERNEL);
  5084. if (unlikely(!phba->vpi_bmask)) {
  5085. rc = -ENOMEM;
  5086. goto free_rpi_ids;
  5087. }
  5088. phba->vpi_ids = kzalloc(count *
  5089. sizeof(uint16_t),
  5090. GFP_KERNEL);
  5091. if (unlikely(!phba->vpi_ids)) {
  5092. rc = -ENOMEM;
  5093. goto free_vpi_bmask;
  5094. }
  5095. for (i = 0; i < count; i++)
  5096. phba->vpi_ids[i] = base + i;
  5097. /* XRIs. */
  5098. count = phba->sli4_hba.max_cfg_param.max_xri;
  5099. base = phba->sli4_hba.max_cfg_param.xri_base;
  5100. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5101. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5102. sizeof(unsigned long),
  5103. GFP_KERNEL);
  5104. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5105. rc = -ENOMEM;
  5106. goto free_vpi_ids;
  5107. }
  5108. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5109. phba->sli4_hba.xri_ids = kzalloc(count *
  5110. sizeof(uint16_t),
  5111. GFP_KERNEL);
  5112. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5113. rc = -ENOMEM;
  5114. goto free_xri_bmask;
  5115. }
  5116. for (i = 0; i < count; i++)
  5117. phba->sli4_hba.xri_ids[i] = base + i;
  5118. /* VFIs. */
  5119. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5120. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5121. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5122. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5123. sizeof(unsigned long),
  5124. GFP_KERNEL);
  5125. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5126. rc = -ENOMEM;
  5127. goto free_xri_ids;
  5128. }
  5129. phba->sli4_hba.vfi_ids = kzalloc(count *
  5130. sizeof(uint16_t),
  5131. GFP_KERNEL);
  5132. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5133. rc = -ENOMEM;
  5134. goto free_vfi_bmask;
  5135. }
  5136. for (i = 0; i < count; i++)
  5137. phba->sli4_hba.vfi_ids[i] = base + i;
  5138. /*
  5139. * Mark all resources ready. An HBA reset doesn't need
  5140. * to reset the initialization.
  5141. */
  5142. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5143. LPFC_IDX_RSRC_RDY);
  5144. return 0;
  5145. }
  5146. free_vfi_bmask:
  5147. kfree(phba->sli4_hba.vfi_bmask);
  5148. free_xri_ids:
  5149. kfree(phba->sli4_hba.xri_ids);
  5150. free_xri_bmask:
  5151. kfree(phba->sli4_hba.xri_bmask);
  5152. free_vpi_ids:
  5153. kfree(phba->vpi_ids);
  5154. free_vpi_bmask:
  5155. kfree(phba->vpi_bmask);
  5156. free_rpi_ids:
  5157. kfree(phba->sli4_hba.rpi_ids);
  5158. free_rpi_bmask:
  5159. kfree(phba->sli4_hba.rpi_bmask);
  5160. err_exit:
  5161. return rc;
  5162. }
  5163. /**
  5164. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5165. * @phba: Pointer to HBA context object.
  5166. *
  5167. * This function allocates the number of elements for the specified
  5168. * resource type.
  5169. **/
  5170. int
  5171. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5172. {
  5173. if (phba->sli4_hba.extents_in_use) {
  5174. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5175. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5176. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5177. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5178. } else {
  5179. kfree(phba->vpi_bmask);
  5180. kfree(phba->vpi_ids);
  5181. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5182. kfree(phba->sli4_hba.xri_bmask);
  5183. kfree(phba->sli4_hba.xri_ids);
  5184. kfree(phba->sli4_hba.vfi_bmask);
  5185. kfree(phba->sli4_hba.vfi_ids);
  5186. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5187. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5188. }
  5189. return 0;
  5190. }
  5191. /**
  5192. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5193. * @phba: Pointer to HBA context object.
  5194. * @type: The resource extent type.
  5195. * @extnt_count: buffer to hold port extent count response
  5196. * @extnt_size: buffer to hold port extent size response.
  5197. *
  5198. * This function calls the port to read the host allocated extents
  5199. * for a particular type.
  5200. **/
  5201. int
  5202. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5203. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5204. {
  5205. bool emb;
  5206. int rc = 0;
  5207. uint16_t curr_blks = 0;
  5208. uint32_t req_len, emb_len;
  5209. uint32_t alloc_len, mbox_tmo;
  5210. struct list_head *blk_list_head;
  5211. struct lpfc_rsrc_blks *rsrc_blk;
  5212. LPFC_MBOXQ_t *mbox;
  5213. void *virtaddr = NULL;
  5214. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5215. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5216. union lpfc_sli4_cfg_shdr *shdr;
  5217. switch (type) {
  5218. case LPFC_RSC_TYPE_FCOE_VPI:
  5219. blk_list_head = &phba->lpfc_vpi_blk_list;
  5220. break;
  5221. case LPFC_RSC_TYPE_FCOE_XRI:
  5222. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5223. break;
  5224. case LPFC_RSC_TYPE_FCOE_VFI:
  5225. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5226. break;
  5227. case LPFC_RSC_TYPE_FCOE_RPI:
  5228. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5229. break;
  5230. default:
  5231. return -EIO;
  5232. }
  5233. /* Count the number of extents currently allocatd for this type. */
  5234. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5235. if (curr_blks == 0) {
  5236. /*
  5237. * The GET_ALLOCATED mailbox does not return the size,
  5238. * just the count. The size should be just the size
  5239. * stored in the current allocated block and all sizes
  5240. * for an extent type are the same so set the return
  5241. * value now.
  5242. */
  5243. *extnt_size = rsrc_blk->rsrc_size;
  5244. }
  5245. curr_blks++;
  5246. }
  5247. /* Calculate the total requested length of the dma memory. */
  5248. req_len = curr_blks * sizeof(uint16_t);
  5249. /*
  5250. * Calculate the size of an embedded mailbox. The uint32_t
  5251. * accounts for extents-specific word.
  5252. */
  5253. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5254. sizeof(uint32_t);
  5255. /*
  5256. * Presume the allocation and response will fit into an embedded
  5257. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5258. */
  5259. emb = LPFC_SLI4_MBX_EMBED;
  5260. req_len = emb_len;
  5261. if (req_len > emb_len) {
  5262. req_len = curr_blks * sizeof(uint16_t) +
  5263. sizeof(union lpfc_sli4_cfg_shdr) +
  5264. sizeof(uint32_t);
  5265. emb = LPFC_SLI4_MBX_NEMBED;
  5266. }
  5267. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5268. if (!mbox)
  5269. return -ENOMEM;
  5270. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5271. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5272. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5273. req_len, emb);
  5274. if (alloc_len < req_len) {
  5275. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5276. "2983 Allocated DMA memory size (x%x) is "
  5277. "less than the requested DMA memory "
  5278. "size (x%x)\n", alloc_len, req_len);
  5279. rc = -ENOMEM;
  5280. goto err_exit;
  5281. }
  5282. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5283. if (unlikely(rc)) {
  5284. rc = -EIO;
  5285. goto err_exit;
  5286. }
  5287. if (!phba->sli4_hba.intr_enable)
  5288. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5289. else {
  5290. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5291. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5292. }
  5293. if (unlikely(rc)) {
  5294. rc = -EIO;
  5295. goto err_exit;
  5296. }
  5297. /*
  5298. * Figure out where the response is located. Then get local pointers
  5299. * to the response data. The port does not guarantee to respond to
  5300. * all extents counts request so update the local variable with the
  5301. * allocated count from the port.
  5302. */
  5303. if (emb == LPFC_SLI4_MBX_EMBED) {
  5304. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5305. shdr = &rsrc_ext->header.cfg_shdr;
  5306. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5307. } else {
  5308. virtaddr = mbox->sge_array->addr[0];
  5309. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5310. shdr = &n_rsrc->cfg_shdr;
  5311. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5312. }
  5313. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5314. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5315. "2984 Failed to read allocated resources "
  5316. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5317. type,
  5318. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5319. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5320. rc = -EIO;
  5321. goto err_exit;
  5322. }
  5323. err_exit:
  5324. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5325. return rc;
  5326. }
  5327. /**
  5328. * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
  5329. * @phba: pointer to lpfc hba data structure.
  5330. *
  5331. * This routine walks the list of els buffers that have been allocated and
  5332. * repost them to the port by using SGL block post. This is needed after a
  5333. * pci_function_reset/warm_start or start. It attempts to construct blocks
  5334. * of els buffer sgls which contains contiguous xris and uses the non-embedded
  5335. * SGL block post mailbox commands to post them to the port. For single els
  5336. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  5337. * mailbox command for posting.
  5338. *
  5339. * Returns: 0 = success, non-zero failure.
  5340. **/
  5341. static int
  5342. lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba)
  5343. {
  5344. struct lpfc_sglq *sglq_entry = NULL;
  5345. struct lpfc_sglq *sglq_entry_next = NULL;
  5346. struct lpfc_sglq *sglq_entry_first = NULL;
  5347. int status, post_cnt = 0, num_posted = 0, block_cnt = 0;
  5348. int last_xritag = NO_XRI;
  5349. LIST_HEAD(prep_sgl_list);
  5350. LIST_HEAD(blck_sgl_list);
  5351. LIST_HEAD(allc_sgl_list);
  5352. LIST_HEAD(post_sgl_list);
  5353. LIST_HEAD(free_sgl_list);
  5354. spin_lock(&phba->hbalock);
  5355. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list);
  5356. spin_unlock(&phba->hbalock);
  5357. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  5358. &allc_sgl_list, list) {
  5359. list_del_init(&sglq_entry->list);
  5360. block_cnt++;
  5361. if ((last_xritag != NO_XRI) &&
  5362. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  5363. /* a hole in xri block, form a sgl posting block */
  5364. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  5365. post_cnt = block_cnt - 1;
  5366. /* prepare list for next posting block */
  5367. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5368. block_cnt = 1;
  5369. } else {
  5370. /* prepare list for next posting block */
  5371. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  5372. /* enough sgls for non-embed sgl mbox command */
  5373. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  5374. list_splice_init(&prep_sgl_list,
  5375. &blck_sgl_list);
  5376. post_cnt = block_cnt;
  5377. block_cnt = 0;
  5378. }
  5379. }
  5380. num_posted++;
  5381. /* keep track of last sgl's xritag */
  5382. last_xritag = sglq_entry->sli4_xritag;
  5383. /* end of repost sgl list condition for els buffers */
  5384. if (num_posted == phba->sli4_hba.els_xri_cnt) {
  5385. if (post_cnt == 0) {
  5386. list_splice_init(&prep_sgl_list,
  5387. &blck_sgl_list);
  5388. post_cnt = block_cnt;
  5389. } else if (block_cnt == 1) {
  5390. status = lpfc_sli4_post_sgl(phba,
  5391. sglq_entry->phys, 0,
  5392. sglq_entry->sli4_xritag);
  5393. if (!status) {
  5394. /* successful, put sgl to posted list */
  5395. list_add_tail(&sglq_entry->list,
  5396. &post_sgl_list);
  5397. } else {
  5398. /* Failure, put sgl to free list */
  5399. lpfc_printf_log(phba, KERN_WARNING,
  5400. LOG_SLI,
  5401. "3159 Failed to post els "
  5402. "sgl, xritag:x%x\n",
  5403. sglq_entry->sli4_xritag);
  5404. list_add_tail(&sglq_entry->list,
  5405. &free_sgl_list);
  5406. spin_lock_irq(&phba->hbalock);
  5407. phba->sli4_hba.els_xri_cnt--;
  5408. spin_unlock_irq(&phba->hbalock);
  5409. }
  5410. }
  5411. }
  5412. /* continue until a nembed page worth of sgls */
  5413. if (post_cnt == 0)
  5414. continue;
  5415. /* post the els buffer list sgls as a block */
  5416. status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list,
  5417. post_cnt);
  5418. if (!status) {
  5419. /* success, put sgl list to posted sgl list */
  5420. list_splice_init(&blck_sgl_list, &post_sgl_list);
  5421. } else {
  5422. /* Failure, put sgl list to free sgl list */
  5423. sglq_entry_first = list_first_entry(&blck_sgl_list,
  5424. struct lpfc_sglq,
  5425. list);
  5426. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5427. "3160 Failed to post els sgl-list, "
  5428. "xritag:x%x-x%x\n",
  5429. sglq_entry_first->sli4_xritag,
  5430. (sglq_entry_first->sli4_xritag +
  5431. post_cnt - 1));
  5432. list_splice_init(&blck_sgl_list, &free_sgl_list);
  5433. spin_lock_irq(&phba->hbalock);
  5434. phba->sli4_hba.els_xri_cnt -= post_cnt;
  5435. spin_unlock_irq(&phba->hbalock);
  5436. }
  5437. /* don't reset xirtag due to hole in xri block */
  5438. if (block_cnt == 0)
  5439. last_xritag = NO_XRI;
  5440. /* reset els sgl post count for next round of posting */
  5441. post_cnt = 0;
  5442. }
  5443. /* free the els sgls failed to post */
  5444. lpfc_free_sgl_list(phba, &free_sgl_list);
  5445. /* push els sgls posted to the availble list */
  5446. if (!list_empty(&post_sgl_list)) {
  5447. spin_lock(&phba->hbalock);
  5448. list_splice_init(&post_sgl_list,
  5449. &phba->sli4_hba.lpfc_sgl_list);
  5450. spin_unlock(&phba->hbalock);
  5451. } else {
  5452. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5453. "3161 Failure to post els sgl to port.\n");
  5454. return -EIO;
  5455. }
  5456. return 0;
  5457. }
  5458. /**
  5459. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5460. * @phba: Pointer to HBA context object.
  5461. *
  5462. * This function is the main SLI4 device intialization PCI function. This
  5463. * function is called by the HBA intialization code, HBA reset code and
  5464. * HBA error attention handler code. Caller is not required to hold any
  5465. * locks.
  5466. **/
  5467. int
  5468. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5469. {
  5470. int rc;
  5471. LPFC_MBOXQ_t *mboxq;
  5472. struct lpfc_mqe *mqe;
  5473. uint8_t *vpd;
  5474. uint32_t vpd_size;
  5475. uint32_t ftr_rsp = 0;
  5476. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5477. struct lpfc_vport *vport = phba->pport;
  5478. struct lpfc_dmabuf *mp;
  5479. /* Perform a PCI function reset to start from clean */
  5480. rc = lpfc_pci_function_reset(phba);
  5481. if (unlikely(rc))
  5482. return -ENODEV;
  5483. /* Check the HBA Host Status Register for readyness */
  5484. rc = lpfc_sli4_post_status_check(phba);
  5485. if (unlikely(rc))
  5486. return -ENODEV;
  5487. else {
  5488. spin_lock_irq(&phba->hbalock);
  5489. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5490. spin_unlock_irq(&phba->hbalock);
  5491. }
  5492. /*
  5493. * Allocate a single mailbox container for initializing the
  5494. * port.
  5495. */
  5496. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5497. if (!mboxq)
  5498. return -ENOMEM;
  5499. /* Issue READ_REV to collect vpd and FW information. */
  5500. vpd_size = SLI4_PAGE_SIZE;
  5501. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5502. if (!vpd) {
  5503. rc = -ENOMEM;
  5504. goto out_free_mbox;
  5505. }
  5506. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5507. if (unlikely(rc)) {
  5508. kfree(vpd);
  5509. goto out_free_mbox;
  5510. }
  5511. mqe = &mboxq->u.mqe;
  5512. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5513. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5514. phba->hba_flag |= HBA_FCOE_MODE;
  5515. else
  5516. phba->hba_flag &= ~HBA_FCOE_MODE;
  5517. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5518. LPFC_DCBX_CEE_MODE)
  5519. phba->hba_flag |= HBA_FIP_SUPPORT;
  5520. else
  5521. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5522. phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
  5523. if (phba->sli_rev != LPFC_SLI_REV4) {
  5524. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5525. "0376 READ_REV Error. SLI Level %d "
  5526. "FCoE enabled %d\n",
  5527. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5528. rc = -EIO;
  5529. kfree(vpd);
  5530. goto out_free_mbox;
  5531. }
  5532. /*
  5533. * Continue initialization with default values even if driver failed
  5534. * to read FCoE param config regions, only read parameters if the
  5535. * board is FCoE
  5536. */
  5537. if (phba->hba_flag & HBA_FCOE_MODE &&
  5538. lpfc_sli4_read_fcoe_params(phba))
  5539. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5540. "2570 Failed to read FCoE parameters\n");
  5541. /*
  5542. * Retrieve sli4 device physical port name, failure of doing it
  5543. * is considered as non-fatal.
  5544. */
  5545. rc = lpfc_sli4_retrieve_pport_name(phba);
  5546. if (!rc)
  5547. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5548. "3080 Successful retrieving SLI4 device "
  5549. "physical port name: %s.\n", phba->Port);
  5550. /*
  5551. * Evaluate the read rev and vpd data. Populate the driver
  5552. * state with the results. If this routine fails, the failure
  5553. * is not fatal as the driver will use generic values.
  5554. */
  5555. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5556. if (unlikely(!rc)) {
  5557. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5558. "0377 Error %d parsing vpd. "
  5559. "Using defaults.\n", rc);
  5560. rc = 0;
  5561. }
  5562. kfree(vpd);
  5563. /* Save information as VPD data */
  5564. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5565. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5566. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5567. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5568. &mqe->un.read_rev);
  5569. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5570. &mqe->un.read_rev);
  5571. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5572. &mqe->un.read_rev);
  5573. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5574. &mqe->un.read_rev);
  5575. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5576. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5577. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5578. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5579. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5580. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5581. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5582. "(%d):0380 READ_REV Status x%x "
  5583. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5584. mboxq->vport ? mboxq->vport->vpi : 0,
  5585. bf_get(lpfc_mqe_status, mqe),
  5586. phba->vpd.rev.opFwName,
  5587. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5588. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5589. /*
  5590. * Discover the port's supported feature set and match it against the
  5591. * hosts requests.
  5592. */
  5593. lpfc_request_features(phba, mboxq);
  5594. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5595. if (unlikely(rc)) {
  5596. rc = -EIO;
  5597. goto out_free_mbox;
  5598. }
  5599. /*
  5600. * The port must support FCP initiator mode as this is the
  5601. * only mode running in the host.
  5602. */
  5603. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5604. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5605. "0378 No support for fcpi mode.\n");
  5606. ftr_rsp++;
  5607. }
  5608. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5609. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5610. else
  5611. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5612. /*
  5613. * If the port cannot support the host's requested features
  5614. * then turn off the global config parameters to disable the
  5615. * feature in the driver. This is not a fatal error.
  5616. */
  5617. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5618. if (phba->cfg_enable_bg) {
  5619. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5620. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5621. else
  5622. ftr_rsp++;
  5623. }
  5624. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5625. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5626. ftr_rsp++;
  5627. if (ftr_rsp) {
  5628. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5629. "0379 Feature Mismatch Data: x%08x %08x "
  5630. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5631. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5632. phba->cfg_enable_npiv, phba->max_vpi);
  5633. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5634. phba->cfg_enable_bg = 0;
  5635. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5636. phba->cfg_enable_npiv = 0;
  5637. }
  5638. /* These SLI3 features are assumed in SLI4 */
  5639. spin_lock_irq(&phba->hbalock);
  5640. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5641. spin_unlock_irq(&phba->hbalock);
  5642. /*
  5643. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5644. * calls depends on these resources to complete port setup.
  5645. */
  5646. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5647. if (rc) {
  5648. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5649. "2920 Failed to alloc Resource IDs "
  5650. "rc = x%x\n", rc);
  5651. goto out_free_mbox;
  5652. }
  5653. /* Read the port's service parameters. */
  5654. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5655. if (rc) {
  5656. phba->link_state = LPFC_HBA_ERROR;
  5657. rc = -ENOMEM;
  5658. goto out_free_mbox;
  5659. }
  5660. mboxq->vport = vport;
  5661. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5662. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5663. if (rc == MBX_SUCCESS) {
  5664. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5665. rc = 0;
  5666. }
  5667. /*
  5668. * This memory was allocated by the lpfc_read_sparam routine. Release
  5669. * it to the mbuf pool.
  5670. */
  5671. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5672. kfree(mp);
  5673. mboxq->context1 = NULL;
  5674. if (unlikely(rc)) {
  5675. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5676. "0382 READ_SPARAM command failed "
  5677. "status %d, mbxStatus x%x\n",
  5678. rc, bf_get(lpfc_mqe_status, mqe));
  5679. phba->link_state = LPFC_HBA_ERROR;
  5680. rc = -EIO;
  5681. goto out_free_mbox;
  5682. }
  5683. lpfc_update_vport_wwn(vport);
  5684. /* Update the fc_host data structures with new wwn. */
  5685. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5686. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5687. /* update host els and scsi xri-sgl sizes and mappings */
  5688. rc = lpfc_sli4_xri_sgl_update(phba);
  5689. if (unlikely(rc)) {
  5690. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5691. "1400 Failed to update xri-sgl size and "
  5692. "mapping: %d\n", rc);
  5693. goto out_free_mbox;
  5694. }
  5695. /* register the els sgl pool to the port */
  5696. rc = lpfc_sli4_repost_els_sgl_list(phba);
  5697. if (unlikely(rc)) {
  5698. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5699. "0582 Error %d during els sgl post "
  5700. "operation\n", rc);
  5701. rc = -ENODEV;
  5702. goto out_free_mbox;
  5703. }
  5704. /* register the allocated scsi sgl pool to the port */
  5705. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5706. if (unlikely(rc)) {
  5707. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5708. "0383 Error %d during scsi sgl post "
  5709. "operation\n", rc);
  5710. /* Some Scsi buffers were moved to the abort scsi list */
  5711. /* A pci function reset will repost them */
  5712. rc = -ENODEV;
  5713. goto out_free_mbox;
  5714. }
  5715. /* Post the rpi header region to the device. */
  5716. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5717. if (unlikely(rc)) {
  5718. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5719. "0393 Error %d during rpi post operation\n",
  5720. rc);
  5721. rc = -ENODEV;
  5722. goto out_free_mbox;
  5723. }
  5724. lpfc_sli4_node_prep(phba);
  5725. /* Create all the SLI4 queues */
  5726. rc = lpfc_sli4_queue_create(phba);
  5727. if (rc) {
  5728. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5729. "3089 Failed to allocate queues\n");
  5730. rc = -ENODEV;
  5731. goto out_stop_timers;
  5732. }
  5733. /* Set up all the queues to the device */
  5734. rc = lpfc_sli4_queue_setup(phba);
  5735. if (unlikely(rc)) {
  5736. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5737. "0381 Error %d during queue setup.\n ", rc);
  5738. goto out_destroy_queue;
  5739. }
  5740. /* Arm the CQs and then EQs on device */
  5741. lpfc_sli4_arm_cqeq_intr(phba);
  5742. /* Indicate device interrupt mode */
  5743. phba->sli4_hba.intr_enable = 1;
  5744. /* Allow asynchronous mailbox command to go through */
  5745. spin_lock_irq(&phba->hbalock);
  5746. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5747. spin_unlock_irq(&phba->hbalock);
  5748. /* Post receive buffers to the device */
  5749. lpfc_sli4_rb_setup(phba);
  5750. /* Reset HBA FCF states after HBA reset */
  5751. phba->fcf.fcf_flag = 0;
  5752. phba->fcf.current_rec.flag = 0;
  5753. /* Start the ELS watchdog timer */
  5754. mod_timer(&vport->els_tmofunc,
  5755. jiffies + HZ * (phba->fc_ratov * 2));
  5756. /* Start heart beat timer */
  5757. mod_timer(&phba->hb_tmofunc,
  5758. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  5759. phba->hb_outstanding = 0;
  5760. phba->last_completion_time = jiffies;
  5761. /* Start error attention (ERATT) polling timer */
  5762. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  5763. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5764. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5765. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5766. if (!rc) {
  5767. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5768. "2829 This device supports "
  5769. "Advanced Error Reporting (AER)\n");
  5770. spin_lock_irq(&phba->hbalock);
  5771. phba->hba_flag |= HBA_AER_ENABLED;
  5772. spin_unlock_irq(&phba->hbalock);
  5773. } else {
  5774. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5775. "2830 This device does not support "
  5776. "Advanced Error Reporting (AER)\n");
  5777. phba->cfg_aer_support = 0;
  5778. }
  5779. rc = 0;
  5780. }
  5781. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5782. /*
  5783. * The FC Port needs to register FCFI (index 0)
  5784. */
  5785. lpfc_reg_fcfi(phba, mboxq);
  5786. mboxq->vport = phba->pport;
  5787. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5788. if (rc != MBX_SUCCESS)
  5789. goto out_unset_queue;
  5790. rc = 0;
  5791. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5792. &mboxq->u.mqe.un.reg_fcfi);
  5793. /* Check if the port is configured to be disabled */
  5794. lpfc_sli_read_link_ste(phba);
  5795. }
  5796. /*
  5797. * The port is ready, set the host's link state to LINK_DOWN
  5798. * in preparation for link interrupts.
  5799. */
  5800. spin_lock_irq(&phba->hbalock);
  5801. phba->link_state = LPFC_LINK_DOWN;
  5802. spin_unlock_irq(&phba->hbalock);
  5803. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5804. (phba->hba_flag & LINK_DISABLED)) {
  5805. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5806. "3103 Adapter Link is disabled.\n");
  5807. lpfc_down_link(phba, mboxq);
  5808. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5809. if (rc != MBX_SUCCESS) {
  5810. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5811. "3104 Adapter failed to issue "
  5812. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5813. goto out_unset_queue;
  5814. }
  5815. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5816. /* don't perform init_link on SLI4 FC port loopback test */
  5817. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  5818. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5819. if (rc)
  5820. goto out_unset_queue;
  5821. }
  5822. }
  5823. mempool_free(mboxq, phba->mbox_mem_pool);
  5824. return rc;
  5825. out_unset_queue:
  5826. /* Unset all the queues set up in this routine when error out */
  5827. lpfc_sli4_queue_unset(phba);
  5828. out_destroy_queue:
  5829. lpfc_sli4_queue_destroy(phba);
  5830. out_stop_timers:
  5831. lpfc_stop_hba_timers(phba);
  5832. out_free_mbox:
  5833. mempool_free(mboxq, phba->mbox_mem_pool);
  5834. return rc;
  5835. }
  5836. /**
  5837. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5838. * @ptr: context object - pointer to hba structure.
  5839. *
  5840. * This is the callback function for mailbox timer. The mailbox
  5841. * timer is armed when a new mailbox command is issued and the timer
  5842. * is deleted when the mailbox complete. The function is called by
  5843. * the kernel timer code when a mailbox does not complete within
  5844. * expected time. This function wakes up the worker thread to
  5845. * process the mailbox timeout and returns. All the processing is
  5846. * done by the worker thread function lpfc_mbox_timeout_handler.
  5847. **/
  5848. void
  5849. lpfc_mbox_timeout(unsigned long ptr)
  5850. {
  5851. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5852. unsigned long iflag;
  5853. uint32_t tmo_posted;
  5854. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5855. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5856. if (!tmo_posted)
  5857. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5858. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5859. if (!tmo_posted)
  5860. lpfc_worker_wake_up(phba);
  5861. return;
  5862. }
  5863. /**
  5864. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5865. * @phba: Pointer to HBA context object.
  5866. *
  5867. * This function is called from worker thread when a mailbox command times out.
  5868. * The caller is not required to hold any locks. This function will reset the
  5869. * HBA and recover all the pending commands.
  5870. **/
  5871. void
  5872. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5873. {
  5874. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5875. MAILBOX_t *mb = &pmbox->u.mb;
  5876. struct lpfc_sli *psli = &phba->sli;
  5877. struct lpfc_sli_ring *pring;
  5878. /* Check the pmbox pointer first. There is a race condition
  5879. * between the mbox timeout handler getting executed in the
  5880. * worklist and the mailbox actually completing. When this
  5881. * race condition occurs, the mbox_active will be NULL.
  5882. */
  5883. spin_lock_irq(&phba->hbalock);
  5884. if (pmbox == NULL) {
  5885. lpfc_printf_log(phba, KERN_WARNING,
  5886. LOG_MBOX | LOG_SLI,
  5887. "0353 Active Mailbox cleared - mailbox timeout "
  5888. "exiting\n");
  5889. spin_unlock_irq(&phba->hbalock);
  5890. return;
  5891. }
  5892. /* Mbox cmd <mbxCommand> timeout */
  5893. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5894. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  5895. mb->mbxCommand,
  5896. phba->pport->port_state,
  5897. phba->sli.sli_flag,
  5898. phba->sli.mbox_active);
  5899. spin_unlock_irq(&phba->hbalock);
  5900. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  5901. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  5902. * it to fail all outstanding SCSI IO.
  5903. */
  5904. spin_lock_irq(&phba->pport->work_port_lock);
  5905. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  5906. spin_unlock_irq(&phba->pport->work_port_lock);
  5907. spin_lock_irq(&phba->hbalock);
  5908. phba->link_state = LPFC_LINK_UNKNOWN;
  5909. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  5910. spin_unlock_irq(&phba->hbalock);
  5911. pring = &psli->ring[psli->fcp_ring];
  5912. lpfc_sli_abort_iocb_ring(phba, pring);
  5913. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5914. "0345 Resetting board due to mailbox timeout\n");
  5915. /* Reset the HBA device */
  5916. lpfc_reset_hba(phba);
  5917. }
  5918. /**
  5919. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  5920. * @phba: Pointer to HBA context object.
  5921. * @pmbox: Pointer to mailbox object.
  5922. * @flag: Flag indicating how the mailbox need to be processed.
  5923. *
  5924. * This function is called by discovery code and HBA management code
  5925. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  5926. * function gets the hbalock to protect the data structures.
  5927. * The mailbox command can be submitted in polling mode, in which case
  5928. * this function will wait in a polling loop for the completion of the
  5929. * mailbox.
  5930. * If the mailbox is submitted in no_wait mode (not polling) the
  5931. * function will submit the command and returns immediately without waiting
  5932. * for the mailbox completion. The no_wait is supported only when HBA
  5933. * is in SLI2/SLI3 mode - interrupts are enabled.
  5934. * The SLI interface allows only one mailbox pending at a time. If the
  5935. * mailbox is issued in polling mode and there is already a mailbox
  5936. * pending, then the function will return an error. If the mailbox is issued
  5937. * in NO_WAIT mode and there is a mailbox pending already, the function
  5938. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  5939. * The sli layer owns the mailbox object until the completion of mailbox
  5940. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  5941. * return codes the caller owns the mailbox command after the return of
  5942. * the function.
  5943. **/
  5944. static int
  5945. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  5946. uint32_t flag)
  5947. {
  5948. MAILBOX_t *mb;
  5949. struct lpfc_sli *psli = &phba->sli;
  5950. uint32_t status, evtctr;
  5951. uint32_t ha_copy, hc_copy;
  5952. int i;
  5953. unsigned long timeout;
  5954. unsigned long drvr_flag = 0;
  5955. uint32_t word0, ldata;
  5956. void __iomem *to_slim;
  5957. int processing_queue = 0;
  5958. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  5959. if (!pmbox) {
  5960. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5961. /* processing mbox queue from intr_handler */
  5962. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5963. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5964. return MBX_SUCCESS;
  5965. }
  5966. processing_queue = 1;
  5967. pmbox = lpfc_mbox_get(phba);
  5968. if (!pmbox) {
  5969. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5970. return MBX_SUCCESS;
  5971. }
  5972. }
  5973. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  5974. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  5975. if(!pmbox->vport) {
  5976. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5977. lpfc_printf_log(phba, KERN_ERR,
  5978. LOG_MBOX | LOG_VPORT,
  5979. "1806 Mbox x%x failed. No vport\n",
  5980. pmbox->u.mb.mbxCommand);
  5981. dump_stack();
  5982. goto out_not_finished;
  5983. }
  5984. }
  5985. /* If the PCI channel is in offline state, do not post mbox. */
  5986. if (unlikely(pci_channel_offline(phba->pcidev))) {
  5987. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5988. goto out_not_finished;
  5989. }
  5990. /* If HBA has a deferred error attention, fail the iocb. */
  5991. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  5992. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5993. goto out_not_finished;
  5994. }
  5995. psli = &phba->sli;
  5996. mb = &pmbox->u.mb;
  5997. status = MBX_SUCCESS;
  5998. if (phba->link_state == LPFC_HBA_ERROR) {
  5999. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6000. /* Mbox command <mbxCommand> cannot issue */
  6001. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6002. "(%d):0311 Mailbox command x%x cannot "
  6003. "issue Data: x%x x%x\n",
  6004. pmbox->vport ? pmbox->vport->vpi : 0,
  6005. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6006. goto out_not_finished;
  6007. }
  6008. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  6009. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  6010. !(hc_copy & HC_MBINT_ENA)) {
  6011. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6012. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6013. "(%d):2528 Mailbox command x%x cannot "
  6014. "issue Data: x%x x%x\n",
  6015. pmbox->vport ? pmbox->vport->vpi : 0,
  6016. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  6017. goto out_not_finished;
  6018. }
  6019. }
  6020. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6021. /* Polling for a mbox command when another one is already active
  6022. * is not allowed in SLI. Also, the driver must have established
  6023. * SLI2 mode to queue and process multiple mbox commands.
  6024. */
  6025. if (flag & MBX_POLL) {
  6026. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6027. /* Mbox command <mbxCommand> cannot issue */
  6028. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6029. "(%d):2529 Mailbox command x%x "
  6030. "cannot issue Data: x%x x%x\n",
  6031. pmbox->vport ? pmbox->vport->vpi : 0,
  6032. pmbox->u.mb.mbxCommand,
  6033. psli->sli_flag, flag);
  6034. goto out_not_finished;
  6035. }
  6036. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  6037. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6038. /* Mbox command <mbxCommand> cannot issue */
  6039. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6040. "(%d):2530 Mailbox command x%x "
  6041. "cannot issue Data: x%x x%x\n",
  6042. pmbox->vport ? pmbox->vport->vpi : 0,
  6043. pmbox->u.mb.mbxCommand,
  6044. psli->sli_flag, flag);
  6045. goto out_not_finished;
  6046. }
  6047. /* Another mailbox command is still being processed, queue this
  6048. * command to be processed later.
  6049. */
  6050. lpfc_mbox_put(phba, pmbox);
  6051. /* Mbox cmd issue - BUSY */
  6052. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6053. "(%d):0308 Mbox cmd issue - BUSY Data: "
  6054. "x%x x%x x%x x%x\n",
  6055. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  6056. mb->mbxCommand, phba->pport->port_state,
  6057. psli->sli_flag, flag);
  6058. psli->slistat.mbox_busy++;
  6059. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6060. if (pmbox->vport) {
  6061. lpfc_debugfs_disc_trc(pmbox->vport,
  6062. LPFC_DISC_TRC_MBOX_VPORT,
  6063. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  6064. (uint32_t)mb->mbxCommand,
  6065. mb->un.varWords[0], mb->un.varWords[1]);
  6066. }
  6067. else {
  6068. lpfc_debugfs_disc_trc(phba->pport,
  6069. LPFC_DISC_TRC_MBOX,
  6070. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  6071. (uint32_t)mb->mbxCommand,
  6072. mb->un.varWords[0], mb->un.varWords[1]);
  6073. }
  6074. return MBX_BUSY;
  6075. }
  6076. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6077. /* If we are not polling, we MUST be in SLI2 mode */
  6078. if (flag != MBX_POLL) {
  6079. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  6080. (mb->mbxCommand != MBX_KILL_BOARD)) {
  6081. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6082. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6083. /* Mbox command <mbxCommand> cannot issue */
  6084. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6085. "(%d):2531 Mailbox command x%x "
  6086. "cannot issue Data: x%x x%x\n",
  6087. pmbox->vport ? pmbox->vport->vpi : 0,
  6088. pmbox->u.mb.mbxCommand,
  6089. psli->sli_flag, flag);
  6090. goto out_not_finished;
  6091. }
  6092. /* timeout active mbox command */
  6093. mod_timer(&psli->mbox_tmo, (jiffies +
  6094. (HZ * lpfc_mbox_tmo_val(phba, pmbox))));
  6095. }
  6096. /* Mailbox cmd <cmd> issue */
  6097. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6098. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  6099. "x%x\n",
  6100. pmbox->vport ? pmbox->vport->vpi : 0,
  6101. mb->mbxCommand, phba->pport->port_state,
  6102. psli->sli_flag, flag);
  6103. if (mb->mbxCommand != MBX_HEARTBEAT) {
  6104. if (pmbox->vport) {
  6105. lpfc_debugfs_disc_trc(pmbox->vport,
  6106. LPFC_DISC_TRC_MBOX_VPORT,
  6107. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6108. (uint32_t)mb->mbxCommand,
  6109. mb->un.varWords[0], mb->un.varWords[1]);
  6110. }
  6111. else {
  6112. lpfc_debugfs_disc_trc(phba->pport,
  6113. LPFC_DISC_TRC_MBOX,
  6114. "MBOX Send: cmd:x%x mb:x%x x%x",
  6115. (uint32_t)mb->mbxCommand,
  6116. mb->un.varWords[0], mb->un.varWords[1]);
  6117. }
  6118. }
  6119. psli->slistat.mbox_cmd++;
  6120. evtctr = psli->slistat.mbox_event;
  6121. /* next set own bit for the adapter and copy over command word */
  6122. mb->mbxOwner = OWN_CHIP;
  6123. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6124. /* Populate mbox extension offset word. */
  6125. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6126. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6127. = (uint8_t *)phba->mbox_ext
  6128. - (uint8_t *)phba->mbox;
  6129. }
  6130. /* Copy the mailbox extension data */
  6131. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6132. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6133. (uint8_t *)phba->mbox_ext,
  6134. pmbox->in_ext_byte_len);
  6135. }
  6136. /* Copy command data to host SLIM area */
  6137. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6138. } else {
  6139. /* Populate mbox extension offset word. */
  6140. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6141. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6142. = MAILBOX_HBA_EXT_OFFSET;
  6143. /* Copy the mailbox extension data */
  6144. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6145. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6146. MAILBOX_HBA_EXT_OFFSET,
  6147. pmbox->context2, pmbox->in_ext_byte_len);
  6148. }
  6149. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6150. /* copy command data into host mbox for cmpl */
  6151. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6152. }
  6153. /* First copy mbox command data to HBA SLIM, skip past first
  6154. word */
  6155. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6156. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  6157. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6158. /* Next copy over first word, with mbxOwner set */
  6159. ldata = *((uint32_t *)mb);
  6160. to_slim = phba->MBslimaddr;
  6161. writel(ldata, to_slim);
  6162. readl(to_slim); /* flush */
  6163. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6164. /* switch over to host mailbox */
  6165. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6166. }
  6167. }
  6168. wmb();
  6169. switch (flag) {
  6170. case MBX_NOWAIT:
  6171. /* Set up reference to mailbox command */
  6172. psli->mbox_active = pmbox;
  6173. /* Interrupt board to do it */
  6174. writel(CA_MBATT, phba->CAregaddr);
  6175. readl(phba->CAregaddr); /* flush */
  6176. /* Don't wait for it to finish, just return */
  6177. break;
  6178. case MBX_POLL:
  6179. /* Set up null reference to mailbox command */
  6180. psli->mbox_active = NULL;
  6181. /* Interrupt board to do it */
  6182. writel(CA_MBATT, phba->CAregaddr);
  6183. readl(phba->CAregaddr); /* flush */
  6184. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6185. /* First read mbox status word */
  6186. word0 = *((uint32_t *)phba->mbox);
  6187. word0 = le32_to_cpu(word0);
  6188. } else {
  6189. /* First read mbox status word */
  6190. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6191. spin_unlock_irqrestore(&phba->hbalock,
  6192. drvr_flag);
  6193. goto out_not_finished;
  6194. }
  6195. }
  6196. /* Read the HBA Host Attention Register */
  6197. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6198. spin_unlock_irqrestore(&phba->hbalock,
  6199. drvr_flag);
  6200. goto out_not_finished;
  6201. }
  6202. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6203. 1000) + jiffies;
  6204. i = 0;
  6205. /* Wait for command to complete */
  6206. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6207. (!(ha_copy & HA_MBATT) &&
  6208. (phba->link_state > LPFC_WARM_START))) {
  6209. if (time_after(jiffies, timeout)) {
  6210. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6211. spin_unlock_irqrestore(&phba->hbalock,
  6212. drvr_flag);
  6213. goto out_not_finished;
  6214. }
  6215. /* Check if we took a mbox interrupt while we were
  6216. polling */
  6217. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6218. && (evtctr != psli->slistat.mbox_event))
  6219. break;
  6220. if (i++ > 10) {
  6221. spin_unlock_irqrestore(&phba->hbalock,
  6222. drvr_flag);
  6223. msleep(1);
  6224. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6225. }
  6226. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6227. /* First copy command data */
  6228. word0 = *((uint32_t *)phba->mbox);
  6229. word0 = le32_to_cpu(word0);
  6230. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6231. MAILBOX_t *slimmb;
  6232. uint32_t slimword0;
  6233. /* Check real SLIM for any errors */
  6234. slimword0 = readl(phba->MBslimaddr);
  6235. slimmb = (MAILBOX_t *) & slimword0;
  6236. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6237. && slimmb->mbxStatus) {
  6238. psli->sli_flag &=
  6239. ~LPFC_SLI_ACTIVE;
  6240. word0 = slimword0;
  6241. }
  6242. }
  6243. } else {
  6244. /* First copy command data */
  6245. word0 = readl(phba->MBslimaddr);
  6246. }
  6247. /* Read the HBA Host Attention Register */
  6248. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6249. spin_unlock_irqrestore(&phba->hbalock,
  6250. drvr_flag);
  6251. goto out_not_finished;
  6252. }
  6253. }
  6254. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6255. /* copy results back to user */
  6256. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  6257. /* Copy the mailbox extension data */
  6258. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6259. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6260. pmbox->context2,
  6261. pmbox->out_ext_byte_len);
  6262. }
  6263. } else {
  6264. /* First copy command data */
  6265. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  6266. MAILBOX_CMD_SIZE);
  6267. /* Copy the mailbox extension data */
  6268. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6269. lpfc_memcpy_from_slim(pmbox->context2,
  6270. phba->MBslimaddr +
  6271. MAILBOX_HBA_EXT_OFFSET,
  6272. pmbox->out_ext_byte_len);
  6273. }
  6274. }
  6275. writel(HA_MBATT, phba->HAregaddr);
  6276. readl(phba->HAregaddr); /* flush */
  6277. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6278. status = mb->mbxStatus;
  6279. }
  6280. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6281. return status;
  6282. out_not_finished:
  6283. if (processing_queue) {
  6284. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6285. lpfc_mbox_cmpl_put(phba, pmbox);
  6286. }
  6287. return MBX_NOT_FINISHED;
  6288. }
  6289. /**
  6290. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6291. * @phba: Pointer to HBA context object.
  6292. *
  6293. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6294. * the driver internal pending mailbox queue. It will then try to wait out the
  6295. * possible outstanding mailbox command before return.
  6296. *
  6297. * Returns:
  6298. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6299. * the outstanding mailbox command timed out.
  6300. **/
  6301. static int
  6302. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6303. {
  6304. struct lpfc_sli *psli = &phba->sli;
  6305. int rc = 0;
  6306. unsigned long timeout = 0;
  6307. /* Mark the asynchronous mailbox command posting as blocked */
  6308. spin_lock_irq(&phba->hbalock);
  6309. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6310. /* Determine how long we might wait for the active mailbox
  6311. * command to be gracefully completed by firmware.
  6312. */
  6313. if (phba->sli.mbox_active)
  6314. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6315. phba->sli.mbox_active) *
  6316. 1000) + jiffies;
  6317. spin_unlock_irq(&phba->hbalock);
  6318. /* Wait for the outstnading mailbox command to complete */
  6319. while (phba->sli.mbox_active) {
  6320. /* Check active mailbox complete status every 2ms */
  6321. msleep(2);
  6322. if (time_after(jiffies, timeout)) {
  6323. /* Timeout, marked the outstanding cmd not complete */
  6324. rc = 1;
  6325. break;
  6326. }
  6327. }
  6328. /* Can not cleanly block async mailbox command, fails it */
  6329. if (rc) {
  6330. spin_lock_irq(&phba->hbalock);
  6331. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6332. spin_unlock_irq(&phba->hbalock);
  6333. }
  6334. return rc;
  6335. }
  6336. /**
  6337. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6338. * @phba: Pointer to HBA context object.
  6339. *
  6340. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6341. * commands from the driver internal pending mailbox queue. It makes sure
  6342. * that there is no outstanding mailbox command before resuming posting
  6343. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6344. * mailbox command, it will try to wait it out before resuming asynchronous
  6345. * mailbox command posting.
  6346. **/
  6347. static void
  6348. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6349. {
  6350. struct lpfc_sli *psli = &phba->sli;
  6351. spin_lock_irq(&phba->hbalock);
  6352. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6353. /* Asynchronous mailbox posting is not blocked, do nothing */
  6354. spin_unlock_irq(&phba->hbalock);
  6355. return;
  6356. }
  6357. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6358. * successful or timeout, after timing-out the outstanding mailbox
  6359. * command shall always be removed, so just unblock posting async
  6360. * mailbox command and resume
  6361. */
  6362. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6363. spin_unlock_irq(&phba->hbalock);
  6364. /* wake up worker thread to post asynchronlous mailbox command */
  6365. lpfc_worker_wake_up(phba);
  6366. }
  6367. /**
  6368. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6369. * @phba: Pointer to HBA context object.
  6370. * @mboxq: Pointer to mailbox object.
  6371. *
  6372. * The function posts a mailbox to the port. The mailbox is expected
  6373. * to be comletely filled in and ready for the port to operate on it.
  6374. * This routine executes a synchronous completion operation on the
  6375. * mailbox by polling for its completion.
  6376. *
  6377. * The caller must not be holding any locks when calling this routine.
  6378. *
  6379. * Returns:
  6380. * MBX_SUCCESS - mailbox posted successfully
  6381. * Any of the MBX error values.
  6382. **/
  6383. static int
  6384. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6385. {
  6386. int rc = MBX_SUCCESS;
  6387. unsigned long iflag;
  6388. uint32_t db_ready;
  6389. uint32_t mcqe_status;
  6390. uint32_t mbx_cmnd;
  6391. unsigned long timeout;
  6392. struct lpfc_sli *psli = &phba->sli;
  6393. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6394. struct lpfc_bmbx_create *mbox_rgn;
  6395. struct dma_address *dma_address;
  6396. struct lpfc_register bmbx_reg;
  6397. /*
  6398. * Only one mailbox can be active to the bootstrap mailbox region
  6399. * at a time and there is no queueing provided.
  6400. */
  6401. spin_lock_irqsave(&phba->hbalock, iflag);
  6402. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6403. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6404. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6405. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6406. "cannot issue Data: x%x x%x\n",
  6407. mboxq->vport ? mboxq->vport->vpi : 0,
  6408. mboxq->u.mb.mbxCommand,
  6409. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6410. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6411. psli->sli_flag, MBX_POLL);
  6412. return MBXERR_ERROR;
  6413. }
  6414. /* The server grabs the token and owns it until release */
  6415. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6416. phba->sli.mbox_active = mboxq;
  6417. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6418. /*
  6419. * Initialize the bootstrap memory region to avoid stale data areas
  6420. * in the mailbox post. Then copy the caller's mailbox contents to
  6421. * the bmbx mailbox region.
  6422. */
  6423. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6424. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6425. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6426. sizeof(struct lpfc_mqe));
  6427. /* Post the high mailbox dma address to the port and wait for ready. */
  6428. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6429. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6430. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6431. * 1000) + jiffies;
  6432. do {
  6433. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6434. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6435. if (!db_ready)
  6436. msleep(2);
  6437. if (time_after(jiffies, timeout)) {
  6438. rc = MBXERR_ERROR;
  6439. goto exit;
  6440. }
  6441. } while (!db_ready);
  6442. /* Post the low mailbox dma address to the port. */
  6443. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6444. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6445. * 1000) + jiffies;
  6446. do {
  6447. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6448. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6449. if (!db_ready)
  6450. msleep(2);
  6451. if (time_after(jiffies, timeout)) {
  6452. rc = MBXERR_ERROR;
  6453. goto exit;
  6454. }
  6455. } while (!db_ready);
  6456. /*
  6457. * Read the CQ to ensure the mailbox has completed.
  6458. * If so, update the mailbox status so that the upper layers
  6459. * can complete the request normally.
  6460. */
  6461. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6462. sizeof(struct lpfc_mqe));
  6463. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6464. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6465. sizeof(struct lpfc_mcqe));
  6466. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6467. /*
  6468. * When the CQE status indicates a failure and the mailbox status
  6469. * indicates success then copy the CQE status into the mailbox status
  6470. * (and prefix it with x4000).
  6471. */
  6472. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6473. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6474. bf_set(lpfc_mqe_status, mb,
  6475. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6476. rc = MBXERR_ERROR;
  6477. } else
  6478. lpfc_sli4_swap_str(phba, mboxq);
  6479. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6480. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6481. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6482. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6483. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6484. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6485. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6486. bf_get(lpfc_mqe_status, mb),
  6487. mb->un.mb_words[0], mb->un.mb_words[1],
  6488. mb->un.mb_words[2], mb->un.mb_words[3],
  6489. mb->un.mb_words[4], mb->un.mb_words[5],
  6490. mb->un.mb_words[6], mb->un.mb_words[7],
  6491. mb->un.mb_words[8], mb->un.mb_words[9],
  6492. mb->un.mb_words[10], mb->un.mb_words[11],
  6493. mb->un.mb_words[12], mboxq->mcqe.word0,
  6494. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6495. mboxq->mcqe.trailer);
  6496. exit:
  6497. /* We are holding the token, no needed for lock when release */
  6498. spin_lock_irqsave(&phba->hbalock, iflag);
  6499. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6500. phba->sli.mbox_active = NULL;
  6501. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6502. return rc;
  6503. }
  6504. /**
  6505. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6506. * @phba: Pointer to HBA context object.
  6507. * @pmbox: Pointer to mailbox object.
  6508. * @flag: Flag indicating how the mailbox need to be processed.
  6509. *
  6510. * This function is called by discovery code and HBA management code to submit
  6511. * a mailbox command to firmware with SLI-4 interface spec.
  6512. *
  6513. * Return codes the caller owns the mailbox command after the return of the
  6514. * function.
  6515. **/
  6516. static int
  6517. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6518. uint32_t flag)
  6519. {
  6520. struct lpfc_sli *psli = &phba->sli;
  6521. unsigned long iflags;
  6522. int rc;
  6523. /* dump from issue mailbox command if setup */
  6524. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6525. rc = lpfc_mbox_dev_check(phba);
  6526. if (unlikely(rc)) {
  6527. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6528. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6529. "cannot issue Data: x%x x%x\n",
  6530. mboxq->vport ? mboxq->vport->vpi : 0,
  6531. mboxq->u.mb.mbxCommand,
  6532. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6533. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6534. psli->sli_flag, flag);
  6535. goto out_not_finished;
  6536. }
  6537. /* Detect polling mode and jump to a handler */
  6538. if (!phba->sli4_hba.intr_enable) {
  6539. if (flag == MBX_POLL)
  6540. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6541. else
  6542. rc = -EIO;
  6543. if (rc != MBX_SUCCESS)
  6544. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6545. "(%d):2541 Mailbox command x%x "
  6546. "(x%x/x%x) failure: "
  6547. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6548. "Data: x%x x%x\n,",
  6549. mboxq->vport ? mboxq->vport->vpi : 0,
  6550. mboxq->u.mb.mbxCommand,
  6551. lpfc_sli_config_mbox_subsys_get(phba,
  6552. mboxq),
  6553. lpfc_sli_config_mbox_opcode_get(phba,
  6554. mboxq),
  6555. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6556. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6557. bf_get(lpfc_mcqe_ext_status,
  6558. &mboxq->mcqe),
  6559. psli->sli_flag, flag);
  6560. return rc;
  6561. } else if (flag == MBX_POLL) {
  6562. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6563. "(%d):2542 Try to issue mailbox command "
  6564. "x%x (x%x/x%x) synchronously ahead of async"
  6565. "mailbox command queue: x%x x%x\n",
  6566. mboxq->vport ? mboxq->vport->vpi : 0,
  6567. mboxq->u.mb.mbxCommand,
  6568. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6569. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6570. psli->sli_flag, flag);
  6571. /* Try to block the asynchronous mailbox posting */
  6572. rc = lpfc_sli4_async_mbox_block(phba);
  6573. if (!rc) {
  6574. /* Successfully blocked, now issue sync mbox cmd */
  6575. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6576. if (rc != MBX_SUCCESS)
  6577. lpfc_printf_log(phba, KERN_WARNING,
  6578. LOG_MBOX | LOG_SLI,
  6579. "(%d):2597 Sync Mailbox command "
  6580. "x%x (x%x/x%x) failure: "
  6581. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  6582. "Data: x%x x%x\n,",
  6583. mboxq->vport ? mboxq->vport->vpi : 0,
  6584. mboxq->u.mb.mbxCommand,
  6585. lpfc_sli_config_mbox_subsys_get(phba,
  6586. mboxq),
  6587. lpfc_sli_config_mbox_opcode_get(phba,
  6588. mboxq),
  6589. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  6590. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  6591. bf_get(lpfc_mcqe_ext_status,
  6592. &mboxq->mcqe),
  6593. psli->sli_flag, flag);
  6594. /* Unblock the async mailbox posting afterward */
  6595. lpfc_sli4_async_mbox_unblock(phba);
  6596. }
  6597. return rc;
  6598. }
  6599. /* Now, interrupt mode asynchrous mailbox command */
  6600. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6601. if (rc) {
  6602. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6603. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6604. "cannot issue Data: x%x x%x\n",
  6605. mboxq->vport ? mboxq->vport->vpi : 0,
  6606. mboxq->u.mb.mbxCommand,
  6607. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6608. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6609. psli->sli_flag, flag);
  6610. goto out_not_finished;
  6611. }
  6612. /* Put the mailbox command to the driver internal FIFO */
  6613. psli->slistat.mbox_busy++;
  6614. spin_lock_irqsave(&phba->hbalock, iflags);
  6615. lpfc_mbox_put(phba, mboxq);
  6616. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6617. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6618. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6619. "x%x (x%x/x%x) x%x x%x x%x\n",
  6620. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6621. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6622. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6623. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6624. phba->pport->port_state,
  6625. psli->sli_flag, MBX_NOWAIT);
  6626. /* Wake up worker thread to transport mailbox command from head */
  6627. lpfc_worker_wake_up(phba);
  6628. return MBX_BUSY;
  6629. out_not_finished:
  6630. return MBX_NOT_FINISHED;
  6631. }
  6632. /**
  6633. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6634. * @phba: Pointer to HBA context object.
  6635. *
  6636. * This function is called by worker thread to send a mailbox command to
  6637. * SLI4 HBA firmware.
  6638. *
  6639. **/
  6640. int
  6641. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6642. {
  6643. struct lpfc_sli *psli = &phba->sli;
  6644. LPFC_MBOXQ_t *mboxq;
  6645. int rc = MBX_SUCCESS;
  6646. unsigned long iflags;
  6647. struct lpfc_mqe *mqe;
  6648. uint32_t mbx_cmnd;
  6649. /* Check interrupt mode before post async mailbox command */
  6650. if (unlikely(!phba->sli4_hba.intr_enable))
  6651. return MBX_NOT_FINISHED;
  6652. /* Check for mailbox command service token */
  6653. spin_lock_irqsave(&phba->hbalock, iflags);
  6654. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6655. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6656. return MBX_NOT_FINISHED;
  6657. }
  6658. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6659. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6660. return MBX_NOT_FINISHED;
  6661. }
  6662. if (unlikely(phba->sli.mbox_active)) {
  6663. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6664. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6665. "0384 There is pending active mailbox cmd\n");
  6666. return MBX_NOT_FINISHED;
  6667. }
  6668. /* Take the mailbox command service token */
  6669. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6670. /* Get the next mailbox command from head of queue */
  6671. mboxq = lpfc_mbox_get(phba);
  6672. /* If no more mailbox command waiting for post, we're done */
  6673. if (!mboxq) {
  6674. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6675. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6676. return MBX_SUCCESS;
  6677. }
  6678. phba->sli.mbox_active = mboxq;
  6679. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6680. /* Check device readiness for posting mailbox command */
  6681. rc = lpfc_mbox_dev_check(phba);
  6682. if (unlikely(rc))
  6683. /* Driver clean routine will clean up pending mailbox */
  6684. goto out_not_finished;
  6685. /* Prepare the mbox command to be posted */
  6686. mqe = &mboxq->u.mqe;
  6687. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6688. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6689. mod_timer(&psli->mbox_tmo, (jiffies +
  6690. (HZ * lpfc_mbox_tmo_val(phba, mboxq))));
  6691. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6692. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6693. "x%x x%x\n",
  6694. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6695. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6696. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6697. phba->pport->port_state, psli->sli_flag);
  6698. if (mbx_cmnd != MBX_HEARTBEAT) {
  6699. if (mboxq->vport) {
  6700. lpfc_debugfs_disc_trc(mboxq->vport,
  6701. LPFC_DISC_TRC_MBOX_VPORT,
  6702. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6703. mbx_cmnd, mqe->un.mb_words[0],
  6704. mqe->un.mb_words[1]);
  6705. } else {
  6706. lpfc_debugfs_disc_trc(phba->pport,
  6707. LPFC_DISC_TRC_MBOX,
  6708. "MBOX Send: cmd:x%x mb:x%x x%x",
  6709. mbx_cmnd, mqe->un.mb_words[0],
  6710. mqe->un.mb_words[1]);
  6711. }
  6712. }
  6713. psli->slistat.mbox_cmd++;
  6714. /* Post the mailbox command to the port */
  6715. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6716. if (rc != MBX_SUCCESS) {
  6717. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6718. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6719. "cannot issue Data: x%x x%x\n",
  6720. mboxq->vport ? mboxq->vport->vpi : 0,
  6721. mboxq->u.mb.mbxCommand,
  6722. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6723. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6724. psli->sli_flag, MBX_NOWAIT);
  6725. goto out_not_finished;
  6726. }
  6727. return rc;
  6728. out_not_finished:
  6729. spin_lock_irqsave(&phba->hbalock, iflags);
  6730. if (phba->sli.mbox_active) {
  6731. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6732. __lpfc_mbox_cmpl_put(phba, mboxq);
  6733. /* Release the token */
  6734. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6735. phba->sli.mbox_active = NULL;
  6736. }
  6737. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6738. return MBX_NOT_FINISHED;
  6739. }
  6740. /**
  6741. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6742. * @phba: Pointer to HBA context object.
  6743. * @pmbox: Pointer to mailbox object.
  6744. * @flag: Flag indicating how the mailbox need to be processed.
  6745. *
  6746. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6747. * the API jump table function pointer from the lpfc_hba struct.
  6748. *
  6749. * Return codes the caller owns the mailbox command after the return of the
  6750. * function.
  6751. **/
  6752. int
  6753. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6754. {
  6755. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6756. }
  6757. /**
  6758. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6759. * @phba: The hba struct for which this call is being executed.
  6760. * @dev_grp: The HBA PCI-Device group number.
  6761. *
  6762. * This routine sets up the mbox interface API function jump table in @phba
  6763. * struct.
  6764. * Returns: 0 - success, -ENODEV - failure.
  6765. **/
  6766. int
  6767. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6768. {
  6769. switch (dev_grp) {
  6770. case LPFC_PCI_DEV_LP:
  6771. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6772. phba->lpfc_sli_handle_slow_ring_event =
  6773. lpfc_sli_handle_slow_ring_event_s3;
  6774. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6775. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6776. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6777. break;
  6778. case LPFC_PCI_DEV_OC:
  6779. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6780. phba->lpfc_sli_handle_slow_ring_event =
  6781. lpfc_sli_handle_slow_ring_event_s4;
  6782. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6783. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6784. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6785. break;
  6786. default:
  6787. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6788. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6789. dev_grp);
  6790. return -ENODEV;
  6791. break;
  6792. }
  6793. return 0;
  6794. }
  6795. /**
  6796. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6797. * @phba: Pointer to HBA context object.
  6798. * @pring: Pointer to driver SLI ring object.
  6799. * @piocb: Pointer to address of newly added command iocb.
  6800. *
  6801. * This function is called with hbalock held to add a command
  6802. * iocb to the txq when SLI layer cannot submit the command iocb
  6803. * to the ring.
  6804. **/
  6805. void
  6806. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6807. struct lpfc_iocbq *piocb)
  6808. {
  6809. /* Insert the caller's iocb in the txq tail for later processing. */
  6810. list_add_tail(&piocb->list, &pring->txq);
  6811. pring->txq_cnt++;
  6812. }
  6813. /**
  6814. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6815. * @phba: Pointer to HBA context object.
  6816. * @pring: Pointer to driver SLI ring object.
  6817. * @piocb: Pointer to address of newly added command iocb.
  6818. *
  6819. * This function is called with hbalock held before a new
  6820. * iocb is submitted to the firmware. This function checks
  6821. * txq to flush the iocbs in txq to Firmware before
  6822. * submitting new iocbs to the Firmware.
  6823. * If there are iocbs in the txq which need to be submitted
  6824. * to firmware, lpfc_sli_next_iocb returns the first element
  6825. * of the txq after dequeuing it from txq.
  6826. * If there is no iocb in the txq then the function will return
  6827. * *piocb and *piocb is set to NULL. Caller needs to check
  6828. * *piocb to find if there are more commands in the txq.
  6829. **/
  6830. static struct lpfc_iocbq *
  6831. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6832. struct lpfc_iocbq **piocb)
  6833. {
  6834. struct lpfc_iocbq * nextiocb;
  6835. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6836. if (!nextiocb) {
  6837. nextiocb = *piocb;
  6838. *piocb = NULL;
  6839. }
  6840. return nextiocb;
  6841. }
  6842. /**
  6843. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6844. * @phba: Pointer to HBA context object.
  6845. * @ring_number: SLI ring number to issue iocb on.
  6846. * @piocb: Pointer to command iocb.
  6847. * @flag: Flag indicating if this command can be put into txq.
  6848. *
  6849. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6850. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6851. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6852. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6853. * this function allows only iocbs for posting buffers. This function finds
  6854. * next available slot in the command ring and posts the command to the
  6855. * available slot and writes the port attention register to request HBA start
  6856. * processing new iocb. If there is no slot available in the ring and
  6857. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6858. * the function returns IOCB_BUSY.
  6859. *
  6860. * This function is called with hbalock held. The function will return success
  6861. * after it successfully submit the iocb to firmware or after adding to the
  6862. * txq.
  6863. **/
  6864. static int
  6865. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6866. struct lpfc_iocbq *piocb, uint32_t flag)
  6867. {
  6868. struct lpfc_iocbq *nextiocb;
  6869. IOCB_t *iocb;
  6870. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6871. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6872. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6873. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6874. lpfc_printf_log(phba, KERN_ERR,
  6875. LOG_SLI | LOG_VPORT,
  6876. "1807 IOCB x%x failed. No vport\n",
  6877. piocb->iocb.ulpCommand);
  6878. dump_stack();
  6879. return IOCB_ERROR;
  6880. }
  6881. /* If the PCI channel is in offline state, do not post iocbs. */
  6882. if (unlikely(pci_channel_offline(phba->pcidev)))
  6883. return IOCB_ERROR;
  6884. /* If HBA has a deferred error attention, fail the iocb. */
  6885. if (unlikely(phba->hba_flag & DEFER_ERATT))
  6886. return IOCB_ERROR;
  6887. /*
  6888. * We should never get an IOCB if we are in a < LINK_DOWN state
  6889. */
  6890. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  6891. return IOCB_ERROR;
  6892. /*
  6893. * Check to see if we are blocking IOCB processing because of a
  6894. * outstanding event.
  6895. */
  6896. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  6897. goto iocb_busy;
  6898. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  6899. /*
  6900. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  6901. * can be issued if the link is not up.
  6902. */
  6903. switch (piocb->iocb.ulpCommand) {
  6904. case CMD_GEN_REQUEST64_CR:
  6905. case CMD_GEN_REQUEST64_CX:
  6906. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  6907. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  6908. FC_RCTL_DD_UNSOL_CMD) ||
  6909. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  6910. MENLO_TRANSPORT_TYPE))
  6911. goto iocb_busy;
  6912. break;
  6913. case CMD_QUE_RING_BUF_CN:
  6914. case CMD_QUE_RING_BUF64_CN:
  6915. /*
  6916. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  6917. * completion, iocb_cmpl MUST be 0.
  6918. */
  6919. if (piocb->iocb_cmpl)
  6920. piocb->iocb_cmpl = NULL;
  6921. /*FALLTHROUGH*/
  6922. case CMD_CREATE_XRI_CR:
  6923. case CMD_CLOSE_XRI_CN:
  6924. case CMD_CLOSE_XRI_CX:
  6925. break;
  6926. default:
  6927. goto iocb_busy;
  6928. }
  6929. /*
  6930. * For FCP commands, we must be in a state where we can process link
  6931. * attention events.
  6932. */
  6933. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  6934. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  6935. goto iocb_busy;
  6936. }
  6937. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  6938. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  6939. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  6940. if (iocb)
  6941. lpfc_sli_update_ring(phba, pring);
  6942. else
  6943. lpfc_sli_update_full_ring(phba, pring);
  6944. if (!piocb)
  6945. return IOCB_SUCCESS;
  6946. goto out_busy;
  6947. iocb_busy:
  6948. pring->stats.iocb_cmd_delay++;
  6949. out_busy:
  6950. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6951. __lpfc_sli_ringtx_put(phba, pring, piocb);
  6952. return IOCB_SUCCESS;
  6953. }
  6954. return IOCB_BUSY;
  6955. }
  6956. /**
  6957. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  6958. * @phba: Pointer to HBA context object.
  6959. * @piocb: Pointer to command iocb.
  6960. * @sglq: Pointer to the scatter gather queue object.
  6961. *
  6962. * This routine converts the bpl or bde that is in the IOCB
  6963. * to a sgl list for the sli4 hardware. The physical address
  6964. * of the bpl/bde is converted back to a virtual address.
  6965. * If the IOCB contains a BPL then the list of BDE's is
  6966. * converted to sli4_sge's. If the IOCB contains a single
  6967. * BDE then it is converted to a single sli_sge.
  6968. * The IOCB is still in cpu endianess so the contents of
  6969. * the bpl can be used without byte swapping.
  6970. *
  6971. * Returns valid XRI = Success, NO_XRI = Failure.
  6972. **/
  6973. static uint16_t
  6974. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  6975. struct lpfc_sglq *sglq)
  6976. {
  6977. uint16_t xritag = NO_XRI;
  6978. struct ulp_bde64 *bpl = NULL;
  6979. struct ulp_bde64 bde;
  6980. struct sli4_sge *sgl = NULL;
  6981. struct lpfc_dmabuf *dmabuf;
  6982. IOCB_t *icmd;
  6983. int numBdes = 0;
  6984. int i = 0;
  6985. uint32_t offset = 0; /* accumulated offset in the sg request list */
  6986. int inbound = 0; /* number of sg reply entries inbound from firmware */
  6987. if (!piocbq || !sglq)
  6988. return xritag;
  6989. sgl = (struct sli4_sge *)sglq->sgl;
  6990. icmd = &piocbq->iocb;
  6991. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  6992. return sglq->sli4_xritag;
  6993. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  6994. numBdes = icmd->un.genreq64.bdl.bdeSize /
  6995. sizeof(struct ulp_bde64);
  6996. /* The addrHigh and addrLow fields within the IOCB
  6997. * have not been byteswapped yet so there is no
  6998. * need to swap them back.
  6999. */
  7000. if (piocbq->context3)
  7001. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  7002. else
  7003. return xritag;
  7004. bpl = (struct ulp_bde64 *)dmabuf->virt;
  7005. if (!bpl)
  7006. return xritag;
  7007. for (i = 0; i < numBdes; i++) {
  7008. /* Should already be byte swapped. */
  7009. sgl->addr_hi = bpl->addrHigh;
  7010. sgl->addr_lo = bpl->addrLow;
  7011. sgl->word2 = le32_to_cpu(sgl->word2);
  7012. if ((i+1) == numBdes)
  7013. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7014. else
  7015. bf_set(lpfc_sli4_sge_last, sgl, 0);
  7016. /* swap the size field back to the cpu so we
  7017. * can assign it to the sgl.
  7018. */
  7019. bde.tus.w = le32_to_cpu(bpl->tus.w);
  7020. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  7021. /* The offsets in the sgl need to be accumulated
  7022. * separately for the request and reply lists.
  7023. * The request is always first, the reply follows.
  7024. */
  7025. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  7026. /* add up the reply sg entries */
  7027. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  7028. inbound++;
  7029. /* first inbound? reset the offset */
  7030. if (inbound == 1)
  7031. offset = 0;
  7032. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  7033. bf_set(lpfc_sli4_sge_type, sgl,
  7034. LPFC_SGE_TYPE_DATA);
  7035. offset += bde.tus.f.bdeSize;
  7036. }
  7037. sgl->word2 = cpu_to_le32(sgl->word2);
  7038. bpl++;
  7039. sgl++;
  7040. }
  7041. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  7042. /* The addrHigh and addrLow fields of the BDE have not
  7043. * been byteswapped yet so they need to be swapped
  7044. * before putting them in the sgl.
  7045. */
  7046. sgl->addr_hi =
  7047. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  7048. sgl->addr_lo =
  7049. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  7050. sgl->word2 = le32_to_cpu(sgl->word2);
  7051. bf_set(lpfc_sli4_sge_last, sgl, 1);
  7052. sgl->word2 = cpu_to_le32(sgl->word2);
  7053. sgl->sge_len =
  7054. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  7055. }
  7056. return sglq->sli4_xritag;
  7057. }
  7058. /**
  7059. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  7060. * @phba: Pointer to HBA context object.
  7061. *
  7062. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  7063. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  7064. * held.
  7065. *
  7066. * Return: index into SLI4 fast-path FCP queue index.
  7067. **/
  7068. static uint32_t
  7069. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  7070. {
  7071. ++phba->fcp_qidx;
  7072. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  7073. phba->fcp_qidx = 0;
  7074. return phba->fcp_qidx;
  7075. }
  7076. /**
  7077. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  7078. * @phba: Pointer to HBA context object.
  7079. * @piocb: Pointer to command iocb.
  7080. * @wqe: Pointer to the work queue entry.
  7081. *
  7082. * This routine converts the iocb command to its Work Queue Entry
  7083. * equivalent. The wqe pointer should not have any fields set when
  7084. * this routine is called because it will memcpy over them.
  7085. * This routine does not set the CQ_ID or the WQEC bits in the
  7086. * wqe.
  7087. *
  7088. * Returns: 0 = Success, IOCB_ERROR = Failure.
  7089. **/
  7090. static int
  7091. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  7092. union lpfc_wqe *wqe)
  7093. {
  7094. uint32_t xmit_len = 0, total_len = 0;
  7095. uint8_t ct = 0;
  7096. uint32_t fip;
  7097. uint32_t abort_tag;
  7098. uint8_t command_type = ELS_COMMAND_NON_FIP;
  7099. uint8_t cmnd;
  7100. uint16_t xritag;
  7101. uint16_t abrt_iotag;
  7102. struct lpfc_iocbq *abrtiocbq;
  7103. struct ulp_bde64 *bpl = NULL;
  7104. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  7105. int numBdes, i;
  7106. struct ulp_bde64 bde;
  7107. struct lpfc_nodelist *ndlp;
  7108. uint32_t *pcmd;
  7109. uint32_t if_type;
  7110. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  7111. /* The fcp commands will set command type */
  7112. if (iocbq->iocb_flag & LPFC_IO_FCP)
  7113. command_type = FCP_COMMAND;
  7114. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  7115. command_type = ELS_COMMAND_FIP;
  7116. else
  7117. command_type = ELS_COMMAND_NON_FIP;
  7118. /* Some of the fields are in the right position already */
  7119. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  7120. abort_tag = (uint32_t) iocbq->iotag;
  7121. xritag = iocbq->sli4_xritag;
  7122. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  7123. /* words0-2 bpl convert bde */
  7124. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  7125. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7126. sizeof(struct ulp_bde64);
  7127. bpl = (struct ulp_bde64 *)
  7128. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  7129. if (!bpl)
  7130. return IOCB_ERROR;
  7131. /* Should already be byte swapped. */
  7132. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7133. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7134. /* swap the size field back to the cpu so we
  7135. * can assign it to the sgl.
  7136. */
  7137. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7138. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7139. total_len = 0;
  7140. for (i = 0; i < numBdes; i++) {
  7141. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7142. total_len += bde.tus.f.bdeSize;
  7143. }
  7144. } else
  7145. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7146. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7147. cmnd = iocbq->iocb.ulpCommand;
  7148. switch (iocbq->iocb.ulpCommand) {
  7149. case CMD_ELS_REQUEST64_CR:
  7150. if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
  7151. ndlp = iocbq->context_un.ndlp;
  7152. else
  7153. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7154. if (!iocbq->iocb.ulpLe) {
  7155. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7156. "2007 Only Limited Edition cmd Format"
  7157. " supported 0x%x\n",
  7158. iocbq->iocb.ulpCommand);
  7159. return IOCB_ERROR;
  7160. }
  7161. wqe->els_req.payload_len = xmit_len;
  7162. /* Els_reguest64 has a TMO */
  7163. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7164. iocbq->iocb.ulpTimeout);
  7165. /* Need a VF for word 4 set the vf bit*/
  7166. bf_set(els_req64_vf, &wqe->els_req, 0);
  7167. /* And a VFID for word 12 */
  7168. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7169. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7170. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7171. iocbq->iocb.ulpContext);
  7172. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7173. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7174. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7175. if (command_type == ELS_COMMAND_FIP)
  7176. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7177. >> LPFC_FIP_ELS_ID_SHIFT);
  7178. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7179. iocbq->context2)->virt);
  7180. if_type = bf_get(lpfc_sli_intf_if_type,
  7181. &phba->sli4_hba.sli_intf);
  7182. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7183. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7184. *pcmd == ELS_CMD_SCR ||
  7185. *pcmd == ELS_CMD_FDISC ||
  7186. *pcmd == ELS_CMD_LOGO ||
  7187. *pcmd == ELS_CMD_PLOGI)) {
  7188. bf_set(els_req64_sp, &wqe->els_req, 1);
  7189. bf_set(els_req64_sid, &wqe->els_req,
  7190. iocbq->vport->fc_myDID);
  7191. if ((*pcmd == ELS_CMD_FLOGI) &&
  7192. !(phba->fc_topology ==
  7193. LPFC_TOPOLOGY_LOOP))
  7194. bf_set(els_req64_sid, &wqe->els_req, 0);
  7195. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7196. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7197. phba->vpi_ids[iocbq->vport->vpi]);
  7198. } else if (pcmd && iocbq->context1) {
  7199. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7200. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7201. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7202. }
  7203. }
  7204. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7205. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7206. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7207. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7208. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7209. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7210. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7211. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7212. break;
  7213. case CMD_XMIT_SEQUENCE64_CX:
  7214. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7215. iocbq->iocb.un.ulpWord[3]);
  7216. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7217. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7218. /* The entire sequence is transmitted for this IOCB */
  7219. xmit_len = total_len;
  7220. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7221. if (phba->link_flag & LS_LOOPBACK_MODE)
  7222. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7223. case CMD_XMIT_SEQUENCE64_CR:
  7224. /* word3 iocb=io_tag32 wqe=reserved */
  7225. wqe->xmit_sequence.rsvd3 = 0;
  7226. /* word4 relative_offset memcpy */
  7227. /* word5 r_ctl/df_ctl memcpy */
  7228. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7229. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7230. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7231. LPFC_WQE_IOD_WRITE);
  7232. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7233. LPFC_WQE_LENLOC_WORD12);
  7234. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7235. wqe->xmit_sequence.xmit_len = xmit_len;
  7236. command_type = OTHER_COMMAND;
  7237. break;
  7238. case CMD_XMIT_BCAST64_CN:
  7239. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7240. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7241. /* word4 iocb=rsvd wqe=rsvd */
  7242. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7243. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7244. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7245. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7246. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7247. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7248. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7249. LPFC_WQE_LENLOC_WORD3);
  7250. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7251. break;
  7252. case CMD_FCP_IWRITE64_CR:
  7253. command_type = FCP_COMMAND_DATA_OUT;
  7254. /* word3 iocb=iotag wqe=payload_offset_len */
  7255. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7256. wqe->fcp_iwrite.payload_offset_len =
  7257. xmit_len + sizeof(struct fcp_rsp);
  7258. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7259. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7260. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7261. iocbq->iocb.ulpFCP2Rcvy);
  7262. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7263. /* Always open the exchange */
  7264. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7265. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7266. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7267. LPFC_WQE_LENLOC_WORD4);
  7268. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7269. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7270. if (iocbq->iocb_flag & LPFC_IO_DIF) {
  7271. iocbq->iocb_flag &= ~LPFC_IO_DIF;
  7272. bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
  7273. }
  7274. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7275. break;
  7276. case CMD_FCP_IREAD64_CR:
  7277. /* word3 iocb=iotag wqe=payload_offset_len */
  7278. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7279. wqe->fcp_iread.payload_offset_len =
  7280. xmit_len + sizeof(struct fcp_rsp);
  7281. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7282. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7283. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7284. iocbq->iocb.ulpFCP2Rcvy);
  7285. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7286. /* Always open the exchange */
  7287. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7288. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7289. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7290. LPFC_WQE_LENLOC_WORD4);
  7291. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7292. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7293. if (iocbq->iocb_flag & LPFC_IO_DIF) {
  7294. iocbq->iocb_flag &= ~LPFC_IO_DIF;
  7295. bf_set(wqe_dif, &wqe->generic.wqe_com, 1);
  7296. }
  7297. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7298. break;
  7299. case CMD_FCP_ICMND64_CR:
  7300. /* word3 iocb=IO_TAG wqe=reserved */
  7301. wqe->fcp_icmd.rsrvd3 = 0;
  7302. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7303. /* Always open the exchange */
  7304. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7305. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7306. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7307. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7308. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7309. LPFC_WQE_LENLOC_NONE);
  7310. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7311. break;
  7312. case CMD_GEN_REQUEST64_CR:
  7313. /* For this command calculate the xmit length of the
  7314. * request bde.
  7315. */
  7316. xmit_len = 0;
  7317. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7318. sizeof(struct ulp_bde64);
  7319. for (i = 0; i < numBdes; i++) {
  7320. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7321. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7322. break;
  7323. xmit_len += bde.tus.f.bdeSize;
  7324. }
  7325. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7326. wqe->gen_req.request_payload_len = xmit_len;
  7327. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7328. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7329. /* word6 context tag copied in memcpy */
  7330. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7331. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7332. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7333. "2015 Invalid CT %x command 0x%x\n",
  7334. ct, iocbq->iocb.ulpCommand);
  7335. return IOCB_ERROR;
  7336. }
  7337. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7338. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7339. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7340. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7341. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7342. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7343. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7344. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7345. command_type = OTHER_COMMAND;
  7346. break;
  7347. case CMD_XMIT_ELS_RSP64_CX:
  7348. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7349. /* words0-2 BDE memcpy */
  7350. /* word3 iocb=iotag32 wqe=response_payload_len */
  7351. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7352. /* word4 */
  7353. wqe->xmit_els_rsp.word4 = 0;
  7354. /* word5 iocb=rsvd wge=did */
  7355. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7356. iocbq->iocb.un.xseq64.xmit_els_remoteID);
  7357. if_type = bf_get(lpfc_sli_intf_if_type,
  7358. &phba->sli4_hba.sli_intf);
  7359. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7360. if (iocbq->vport->fc_flag & FC_PT2PT) {
  7361. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7362. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7363. iocbq->vport->fc_myDID);
  7364. if (iocbq->vport->fc_myDID == Fabric_DID) {
  7365. bf_set(wqe_els_did,
  7366. &wqe->xmit_els_rsp.wqe_dest, 0);
  7367. }
  7368. }
  7369. }
  7370. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7371. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7372. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7373. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7374. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7375. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7376. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7377. phba->vpi_ids[iocbq->vport->vpi]);
  7378. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7379. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7380. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7381. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7382. LPFC_WQE_LENLOC_WORD3);
  7383. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7384. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7385. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7386. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7387. iocbq->context2)->virt);
  7388. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7389. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  7390. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  7391. iocbq->vport->fc_myDID);
  7392. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  7393. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7394. phba->vpi_ids[phba->pport->vpi]);
  7395. }
  7396. command_type = OTHER_COMMAND;
  7397. break;
  7398. case CMD_CLOSE_XRI_CN:
  7399. case CMD_ABORT_XRI_CN:
  7400. case CMD_ABORT_XRI_CX:
  7401. /* words 0-2 memcpy should be 0 rserved */
  7402. /* port will send abts */
  7403. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7404. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7405. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7406. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7407. } else
  7408. fip = 0;
  7409. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7410. /*
  7411. * The link is down, or the command was ELS_FIP
  7412. * so the fw does not need to send abts
  7413. * on the wire.
  7414. */
  7415. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7416. else
  7417. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7418. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7419. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7420. wqe->abort_cmd.rsrvd5 = 0;
  7421. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7422. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7423. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7424. /*
  7425. * The abort handler will send us CMD_ABORT_XRI_CN or
  7426. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7427. */
  7428. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7429. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7430. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7431. LPFC_WQE_LENLOC_NONE);
  7432. cmnd = CMD_ABORT_XRI_CX;
  7433. command_type = OTHER_COMMAND;
  7434. xritag = 0;
  7435. break;
  7436. case CMD_XMIT_BLS_RSP64_CX:
  7437. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7438. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7439. * we re-construct this WQE here based on information in
  7440. * iocbq from scratch.
  7441. */
  7442. memset(wqe, 0, sizeof(union lpfc_wqe));
  7443. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7444. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7445. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7446. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7447. LPFC_ABTS_UNSOL_INT) {
  7448. /* ABTS sent by initiator to CT exchange, the
  7449. * RX_ID field will be filled with the newly
  7450. * allocated responder XRI.
  7451. */
  7452. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7453. iocbq->sli4_xritag);
  7454. } else {
  7455. /* ABTS sent by responder to CT exchange, the
  7456. * RX_ID field will be filled with the responder
  7457. * RX_ID from ABTS.
  7458. */
  7459. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7460. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7461. }
  7462. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7463. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7464. /* Use CT=VPI */
  7465. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7466. ndlp->nlp_DID);
  7467. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7468. iocbq->iocb.ulpContext);
  7469. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7470. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7471. phba->vpi_ids[phba->pport->vpi]);
  7472. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7473. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7474. LPFC_WQE_LENLOC_NONE);
  7475. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7476. command_type = OTHER_COMMAND;
  7477. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7478. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7479. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7480. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7481. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7482. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7483. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7484. }
  7485. break;
  7486. case CMD_XRI_ABORTED_CX:
  7487. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7488. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7489. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7490. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7491. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7492. default:
  7493. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7494. "2014 Invalid command 0x%x\n",
  7495. iocbq->iocb.ulpCommand);
  7496. return IOCB_ERROR;
  7497. break;
  7498. }
  7499. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7500. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7501. wqe->generic.wqe_com.abort_tag = abort_tag;
  7502. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7503. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7504. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7505. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7506. return 0;
  7507. }
  7508. /**
  7509. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7510. * @phba: Pointer to HBA context object.
  7511. * @ring_number: SLI ring number to issue iocb on.
  7512. * @piocb: Pointer to command iocb.
  7513. * @flag: Flag indicating if this command can be put into txq.
  7514. *
  7515. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7516. * an iocb command to an HBA with SLI-4 interface spec.
  7517. *
  7518. * This function is called with hbalock held. The function will return success
  7519. * after it successfully submit the iocb to firmware or after adding to the
  7520. * txq.
  7521. **/
  7522. static int
  7523. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7524. struct lpfc_iocbq *piocb, uint32_t flag)
  7525. {
  7526. struct lpfc_sglq *sglq;
  7527. union lpfc_wqe wqe;
  7528. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7529. if (piocb->sli4_xritag == NO_XRI) {
  7530. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7531. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7532. sglq = NULL;
  7533. else {
  7534. if (pring->txq_cnt) {
  7535. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7536. __lpfc_sli_ringtx_put(phba,
  7537. pring, piocb);
  7538. return IOCB_SUCCESS;
  7539. } else {
  7540. return IOCB_BUSY;
  7541. }
  7542. } else {
  7543. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7544. if (!sglq) {
  7545. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7546. __lpfc_sli_ringtx_put(phba,
  7547. pring,
  7548. piocb);
  7549. return IOCB_SUCCESS;
  7550. } else
  7551. return IOCB_BUSY;
  7552. }
  7553. }
  7554. }
  7555. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7556. /* These IO's already have an XRI and a mapped sgl. */
  7557. sglq = NULL;
  7558. } else {
  7559. /*
  7560. * This is a continuation of a commandi,(CX) so this
  7561. * sglq is on the active list
  7562. */
  7563. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  7564. if (!sglq)
  7565. return IOCB_ERROR;
  7566. }
  7567. if (sglq) {
  7568. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7569. piocb->sli4_xritag = sglq->sli4_xritag;
  7570. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7571. return IOCB_ERROR;
  7572. }
  7573. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7574. return IOCB_ERROR;
  7575. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7576. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7577. /*
  7578. * For FCP command IOCB, get a new WQ index to distribute
  7579. * WQE across the WQsr. On the other hand, for abort IOCB,
  7580. * it carries the same WQ index to the original command
  7581. * IOCB.
  7582. */
  7583. if (piocb->iocb_flag & LPFC_IO_FCP)
  7584. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7585. if (unlikely(!phba->sli4_hba.fcp_wq))
  7586. return IOCB_ERROR;
  7587. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7588. &wqe))
  7589. return IOCB_ERROR;
  7590. } else {
  7591. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7592. return IOCB_ERROR;
  7593. }
  7594. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7595. return 0;
  7596. }
  7597. /**
  7598. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7599. *
  7600. * This routine wraps the actual lockless version for issusing IOCB function
  7601. * pointer from the lpfc_hba struct.
  7602. *
  7603. * Return codes:
  7604. * IOCB_ERROR - Error
  7605. * IOCB_SUCCESS - Success
  7606. * IOCB_BUSY - Busy
  7607. **/
  7608. int
  7609. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7610. struct lpfc_iocbq *piocb, uint32_t flag)
  7611. {
  7612. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7613. }
  7614. /**
  7615. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7616. * @phba: The hba struct for which this call is being executed.
  7617. * @dev_grp: The HBA PCI-Device group number.
  7618. *
  7619. * This routine sets up the SLI interface API function jump table in @phba
  7620. * struct.
  7621. * Returns: 0 - success, -ENODEV - failure.
  7622. **/
  7623. int
  7624. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7625. {
  7626. switch (dev_grp) {
  7627. case LPFC_PCI_DEV_LP:
  7628. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7629. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7630. break;
  7631. case LPFC_PCI_DEV_OC:
  7632. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7633. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7634. break;
  7635. default:
  7636. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7637. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7638. dev_grp);
  7639. return -ENODEV;
  7640. break;
  7641. }
  7642. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7643. return 0;
  7644. }
  7645. /**
  7646. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7647. * @phba: Pointer to HBA context object.
  7648. * @pring: Pointer to driver SLI ring object.
  7649. * @piocb: Pointer to command iocb.
  7650. * @flag: Flag indicating if this command can be put into txq.
  7651. *
  7652. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7653. * function. This function gets the hbalock and calls
  7654. * __lpfc_sli_issue_iocb function and will return the error returned
  7655. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7656. * functions which do not hold hbalock.
  7657. **/
  7658. int
  7659. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7660. struct lpfc_iocbq *piocb, uint32_t flag)
  7661. {
  7662. unsigned long iflags;
  7663. int rc;
  7664. spin_lock_irqsave(&phba->hbalock, iflags);
  7665. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7666. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7667. return rc;
  7668. }
  7669. /**
  7670. * lpfc_extra_ring_setup - Extra ring setup function
  7671. * @phba: Pointer to HBA context object.
  7672. *
  7673. * This function is called while driver attaches with the
  7674. * HBA to setup the extra ring. The extra ring is used
  7675. * only when driver needs to support target mode functionality
  7676. * or IP over FC functionalities.
  7677. *
  7678. * This function is called with no lock held.
  7679. **/
  7680. static int
  7681. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7682. {
  7683. struct lpfc_sli *psli;
  7684. struct lpfc_sli_ring *pring;
  7685. psli = &phba->sli;
  7686. /* Adjust cmd/rsp ring iocb entries more evenly */
  7687. /* Take some away from the FCP ring */
  7688. pring = &psli->ring[psli->fcp_ring];
  7689. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7690. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7691. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7692. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7693. /* and give them to the extra ring */
  7694. pring = &psli->ring[psli->extra_ring];
  7695. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7696. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7697. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7698. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7699. /* Setup default profile for this ring */
  7700. pring->iotag_max = 4096;
  7701. pring->num_mask = 1;
  7702. pring->prt[0].profile = 0; /* Mask 0 */
  7703. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7704. pring->prt[0].type = phba->cfg_multi_ring_type;
  7705. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7706. return 0;
  7707. }
  7708. /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
  7709. * @vport: pointer to virtual port object.
  7710. * @ndlp: nodelist pointer for the impacted rport.
  7711. *
  7712. * The driver calls this routine in response to a XRI ABORT CQE
  7713. * event from the port. In this event, the driver is required to
  7714. * recover its login to the rport even though its login may be valid
  7715. * from the driver's perspective. The failed ABTS notice from the
  7716. * port indicates the rport is not responding.
  7717. */
  7718. static void
  7719. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  7720. struct lpfc_nodelist *ndlp)
  7721. {
  7722. struct Scsi_Host *shost;
  7723. struct lpfc_hba *phba;
  7724. unsigned long flags = 0;
  7725. shost = lpfc_shost_from_vport(vport);
  7726. phba = vport->phba;
  7727. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  7728. lpfc_printf_log(phba, KERN_INFO,
  7729. LOG_SLI, "3093 No rport recovery needed. "
  7730. "rport in state 0x%x\n",
  7731. ndlp->nlp_state);
  7732. return;
  7733. }
  7734. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7735. "3094 Start rport recovery on shost id 0x%x "
  7736. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  7737. "flags 0x%x\n",
  7738. shost->host_no, ndlp->nlp_DID,
  7739. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  7740. ndlp->nlp_flag);
  7741. /*
  7742. * The rport is not responding. Don't attempt ADISC recovery.
  7743. * Remove the FCP-2 flag to force a PLOGI.
  7744. */
  7745. spin_lock_irqsave(shost->host_lock, flags);
  7746. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  7747. spin_unlock_irqrestore(shost->host_lock, flags);
  7748. lpfc_disc_state_machine(vport, ndlp, NULL,
  7749. NLP_EVT_DEVICE_RECOVERY);
  7750. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  7751. spin_lock_irqsave(shost->host_lock, flags);
  7752. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  7753. spin_unlock_irqrestore(shost->host_lock, flags);
  7754. lpfc_disc_start(vport);
  7755. }
  7756. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7757. * @phba: Pointer to HBA context object.
  7758. * @iocbq: Pointer to iocb object.
  7759. *
  7760. * The async_event handler calls this routine when it receives
  7761. * an ASYNC_STATUS_CN event from the port. The port generates
  7762. * this event when an Abort Sequence request to an rport fails
  7763. * twice in succession. The abort could be originated by the
  7764. * driver or by the port. The ABTS could have been for an ELS
  7765. * or FCP IO. The port only generates this event when an ABTS
  7766. * fails to complete after one retry.
  7767. */
  7768. static void
  7769. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7770. struct lpfc_iocbq *iocbq)
  7771. {
  7772. struct lpfc_nodelist *ndlp = NULL;
  7773. uint16_t rpi = 0, vpi = 0;
  7774. struct lpfc_vport *vport = NULL;
  7775. /* The rpi in the ulpContext is vport-sensitive. */
  7776. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7777. rpi = iocbq->iocb.ulpContext;
  7778. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7779. "3092 Port generated ABTS async event "
  7780. "on vpi %d rpi %d status 0x%x\n",
  7781. vpi, rpi, iocbq->iocb.ulpStatus);
  7782. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7783. if (!vport)
  7784. goto err_exit;
  7785. ndlp = lpfc_findnode_rpi(vport, rpi);
  7786. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7787. goto err_exit;
  7788. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7789. lpfc_sli_abts_recover_port(vport, ndlp);
  7790. return;
  7791. err_exit:
  7792. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7793. "3095 Event Context not found, no "
  7794. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7795. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7796. vpi, rpi);
  7797. }
  7798. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7799. * @phba: pointer to HBA context object.
  7800. * @ndlp: nodelist pointer for the impacted rport.
  7801. * @axri: pointer to the wcqe containing the failed exchange.
  7802. *
  7803. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7804. * port. The port generates this event when an abort exchange request to an
  7805. * rport fails twice in succession with no reply. The abort could be originated
  7806. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7807. */
  7808. void
  7809. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7810. struct lpfc_nodelist *ndlp,
  7811. struct sli4_wcqe_xri_aborted *axri)
  7812. {
  7813. struct lpfc_vport *vport;
  7814. uint32_t ext_status = 0;
  7815. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  7816. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7817. "3115 Node Context not found, driver "
  7818. "ignoring abts err event\n");
  7819. return;
  7820. }
  7821. vport = ndlp->vport;
  7822. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7823. "3116 Port generated FCP XRI ABORT event on "
  7824. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  7825. ndlp->vport->vpi, ndlp->nlp_rpi,
  7826. bf_get(lpfc_wcqe_xa_xri, axri),
  7827. bf_get(lpfc_wcqe_xa_status, axri),
  7828. axri->parameter);
  7829. /*
  7830. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  7831. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  7832. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  7833. */
  7834. ext_status = axri->parameter & WCQE_PARAM_MASK;
  7835. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  7836. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  7837. lpfc_sli_abts_recover_port(vport, ndlp);
  7838. }
  7839. /**
  7840. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7841. * @phba: Pointer to HBA context object.
  7842. * @pring: Pointer to driver SLI ring object.
  7843. * @iocbq: Pointer to iocb object.
  7844. *
  7845. * This function is called by the slow ring event handler
  7846. * function when there is an ASYNC event iocb in the ring.
  7847. * This function is called with no lock held.
  7848. * Currently this function handles only temperature related
  7849. * ASYNC events. The function decodes the temperature sensor
  7850. * event message and posts events for the management applications.
  7851. **/
  7852. static void
  7853. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7854. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7855. {
  7856. IOCB_t *icmd;
  7857. uint16_t evt_code;
  7858. struct temp_event temp_event_data;
  7859. struct Scsi_Host *shost;
  7860. uint32_t *iocb_w;
  7861. icmd = &iocbq->iocb;
  7862. evt_code = icmd->un.asyncstat.evt_code;
  7863. switch (evt_code) {
  7864. case ASYNC_TEMP_WARN:
  7865. case ASYNC_TEMP_SAFE:
  7866. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7867. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7868. if (evt_code == ASYNC_TEMP_WARN) {
  7869. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7870. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7871. "0347 Adapter is very hot, please take "
  7872. "corrective action. temperature : %d Celsius\n",
  7873. (uint32_t) icmd->ulpContext);
  7874. } else {
  7875. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7876. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7877. "0340 Adapter temperature is OK now. "
  7878. "temperature : %d Celsius\n",
  7879. (uint32_t) icmd->ulpContext);
  7880. }
  7881. /* Send temperature change event to applications */
  7882. shost = lpfc_shost_from_vport(phba->pport);
  7883. fc_host_post_vendor_event(shost, fc_get_event_number(),
  7884. sizeof(temp_event_data), (char *) &temp_event_data,
  7885. LPFC_NL_VENDOR_ID);
  7886. break;
  7887. case ASYNC_STATUS_CN:
  7888. lpfc_sli_abts_err_handler(phba, iocbq);
  7889. break;
  7890. default:
  7891. iocb_w = (uint32_t *) icmd;
  7892. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7893. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  7894. " evt_code 0x%x\n"
  7895. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  7896. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  7897. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  7898. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  7899. pring->ringno, icmd->un.asyncstat.evt_code,
  7900. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  7901. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  7902. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  7903. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  7904. break;
  7905. }
  7906. }
  7907. /**
  7908. * lpfc_sli_setup - SLI ring setup function
  7909. * @phba: Pointer to HBA context object.
  7910. *
  7911. * lpfc_sli_setup sets up rings of the SLI interface with
  7912. * number of iocbs per ring and iotags. This function is
  7913. * called while driver attach to the HBA and before the
  7914. * interrupts are enabled. So there is no need for locking.
  7915. *
  7916. * This function always returns 0.
  7917. **/
  7918. int
  7919. lpfc_sli_setup(struct lpfc_hba *phba)
  7920. {
  7921. int i, totiocbsize = 0;
  7922. struct lpfc_sli *psli = &phba->sli;
  7923. struct lpfc_sli_ring *pring;
  7924. psli->num_rings = MAX_CONFIGURED_RINGS;
  7925. psli->sli_flag = 0;
  7926. psli->fcp_ring = LPFC_FCP_RING;
  7927. psli->next_ring = LPFC_FCP_NEXT_RING;
  7928. psli->extra_ring = LPFC_EXTRA_RING;
  7929. psli->iocbq_lookup = NULL;
  7930. psli->iocbq_lookup_len = 0;
  7931. psli->last_iotag = 0;
  7932. for (i = 0; i < psli->num_rings; i++) {
  7933. pring = &psli->ring[i];
  7934. switch (i) {
  7935. case LPFC_FCP_RING: /* ring 0 - FCP */
  7936. /* numCiocb and numRiocb are used in config_port */
  7937. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  7938. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  7939. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7940. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7941. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7942. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7943. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7944. SLI3_IOCB_CMD_SIZE :
  7945. SLI2_IOCB_CMD_SIZE;
  7946. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7947. SLI3_IOCB_RSP_SIZE :
  7948. SLI2_IOCB_RSP_SIZE;
  7949. pring->iotag_ctr = 0;
  7950. pring->iotag_max =
  7951. (phba->cfg_hba_queue_depth * 2);
  7952. pring->fast_iotag = pring->iotag_max;
  7953. pring->num_mask = 0;
  7954. break;
  7955. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  7956. /* numCiocb and numRiocb are used in config_port */
  7957. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  7958. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  7959. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7960. SLI3_IOCB_CMD_SIZE :
  7961. SLI2_IOCB_CMD_SIZE;
  7962. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7963. SLI3_IOCB_RSP_SIZE :
  7964. SLI2_IOCB_RSP_SIZE;
  7965. pring->iotag_max = phba->cfg_hba_queue_depth;
  7966. pring->num_mask = 0;
  7967. break;
  7968. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  7969. /* numCiocb and numRiocb are used in config_port */
  7970. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  7971. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  7972. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7973. SLI3_IOCB_CMD_SIZE :
  7974. SLI2_IOCB_CMD_SIZE;
  7975. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7976. SLI3_IOCB_RSP_SIZE :
  7977. SLI2_IOCB_RSP_SIZE;
  7978. pring->fast_iotag = 0;
  7979. pring->iotag_ctr = 0;
  7980. pring->iotag_max = 4096;
  7981. pring->lpfc_sli_rcv_async_status =
  7982. lpfc_sli_async_event_handler;
  7983. pring->num_mask = LPFC_MAX_RING_MASK;
  7984. pring->prt[0].profile = 0; /* Mask 0 */
  7985. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  7986. pring->prt[0].type = FC_TYPE_ELS;
  7987. pring->prt[0].lpfc_sli_rcv_unsol_event =
  7988. lpfc_els_unsol_event;
  7989. pring->prt[1].profile = 0; /* Mask 1 */
  7990. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  7991. pring->prt[1].type = FC_TYPE_ELS;
  7992. pring->prt[1].lpfc_sli_rcv_unsol_event =
  7993. lpfc_els_unsol_event;
  7994. pring->prt[2].profile = 0; /* Mask 2 */
  7995. /* NameServer Inquiry */
  7996. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  7997. /* NameServer */
  7998. pring->prt[2].type = FC_TYPE_CT;
  7999. pring->prt[2].lpfc_sli_rcv_unsol_event =
  8000. lpfc_ct_unsol_event;
  8001. pring->prt[3].profile = 0; /* Mask 3 */
  8002. /* NameServer response */
  8003. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  8004. /* NameServer */
  8005. pring->prt[3].type = FC_TYPE_CT;
  8006. pring->prt[3].lpfc_sli_rcv_unsol_event =
  8007. lpfc_ct_unsol_event;
  8008. /* abort unsolicited sequence */
  8009. pring->prt[4].profile = 0; /* Mask 4 */
  8010. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  8011. pring->prt[4].type = FC_TYPE_BLS;
  8012. pring->prt[4].lpfc_sli_rcv_unsol_event =
  8013. lpfc_sli4_ct_abort_unsol_event;
  8014. break;
  8015. }
  8016. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  8017. (pring->numRiocb * pring->sizeRiocb);
  8018. }
  8019. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  8020. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  8021. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  8022. "SLI2 SLIM Data: x%x x%lx\n",
  8023. phba->brd_no, totiocbsize,
  8024. (unsigned long) MAX_SLIM_IOCB_SIZE);
  8025. }
  8026. if (phba->cfg_multi_ring_support == 2)
  8027. lpfc_extra_ring_setup(phba);
  8028. return 0;
  8029. }
  8030. /**
  8031. * lpfc_sli_queue_setup - Queue initialization function
  8032. * @phba: Pointer to HBA context object.
  8033. *
  8034. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  8035. * ring. This function also initializes ring indices of each ring.
  8036. * This function is called during the initialization of the SLI
  8037. * interface of an HBA.
  8038. * This function is called with no lock held and always returns
  8039. * 1.
  8040. **/
  8041. int
  8042. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  8043. {
  8044. struct lpfc_sli *psli;
  8045. struct lpfc_sli_ring *pring;
  8046. int i;
  8047. psli = &phba->sli;
  8048. spin_lock_irq(&phba->hbalock);
  8049. INIT_LIST_HEAD(&psli->mboxq);
  8050. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  8051. /* Initialize list headers for txq and txcmplq as double linked lists */
  8052. for (i = 0; i < psli->num_rings; i++) {
  8053. pring = &psli->ring[i];
  8054. pring->ringno = i;
  8055. pring->next_cmdidx = 0;
  8056. pring->local_getidx = 0;
  8057. pring->cmdidx = 0;
  8058. INIT_LIST_HEAD(&pring->txq);
  8059. INIT_LIST_HEAD(&pring->txcmplq);
  8060. INIT_LIST_HEAD(&pring->iocb_continueq);
  8061. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  8062. INIT_LIST_HEAD(&pring->postbufq);
  8063. }
  8064. spin_unlock_irq(&phba->hbalock);
  8065. return 1;
  8066. }
  8067. /**
  8068. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  8069. * @phba: Pointer to HBA context object.
  8070. *
  8071. * This routine flushes the mailbox command subsystem. It will unconditionally
  8072. * flush all the mailbox commands in the three possible stages in the mailbox
  8073. * command sub-system: pending mailbox command queue; the outstanding mailbox
  8074. * command; and completed mailbox command queue. It is caller's responsibility
  8075. * to make sure that the driver is in the proper state to flush the mailbox
  8076. * command sub-system. Namely, the posting of mailbox commands into the
  8077. * pending mailbox command queue from the various clients must be stopped;
  8078. * either the HBA is in a state that it will never works on the outstanding
  8079. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  8080. * mailbox command has been completed.
  8081. **/
  8082. static void
  8083. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  8084. {
  8085. LIST_HEAD(completions);
  8086. struct lpfc_sli *psli = &phba->sli;
  8087. LPFC_MBOXQ_t *pmb;
  8088. unsigned long iflag;
  8089. /* Flush all the mailbox commands in the mbox system */
  8090. spin_lock_irqsave(&phba->hbalock, iflag);
  8091. /* The pending mailbox command queue */
  8092. list_splice_init(&phba->sli.mboxq, &completions);
  8093. /* The outstanding active mailbox command */
  8094. if (psli->mbox_active) {
  8095. list_add_tail(&psli->mbox_active->list, &completions);
  8096. psli->mbox_active = NULL;
  8097. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8098. }
  8099. /* The completed mailbox command queue */
  8100. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  8101. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8102. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  8103. while (!list_empty(&completions)) {
  8104. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  8105. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8106. if (pmb->mbox_cmpl)
  8107. pmb->mbox_cmpl(phba, pmb);
  8108. }
  8109. }
  8110. /**
  8111. * lpfc_sli_host_down - Vport cleanup function
  8112. * @vport: Pointer to virtual port object.
  8113. *
  8114. * lpfc_sli_host_down is called to clean up the resources
  8115. * associated with a vport before destroying virtual
  8116. * port data structures.
  8117. * This function does following operations:
  8118. * - Free discovery resources associated with this virtual
  8119. * port.
  8120. * - Free iocbs associated with this virtual port in
  8121. * the txq.
  8122. * - Send abort for all iocb commands associated with this
  8123. * vport in txcmplq.
  8124. *
  8125. * This function is called with no lock held and always returns 1.
  8126. **/
  8127. int
  8128. lpfc_sli_host_down(struct lpfc_vport *vport)
  8129. {
  8130. LIST_HEAD(completions);
  8131. struct lpfc_hba *phba = vport->phba;
  8132. struct lpfc_sli *psli = &phba->sli;
  8133. struct lpfc_sli_ring *pring;
  8134. struct lpfc_iocbq *iocb, *next_iocb;
  8135. int i;
  8136. unsigned long flags = 0;
  8137. uint16_t prev_pring_flag;
  8138. lpfc_cleanup_discovery_resources(vport);
  8139. spin_lock_irqsave(&phba->hbalock, flags);
  8140. for (i = 0; i < psli->num_rings; i++) {
  8141. pring = &psli->ring[i];
  8142. prev_pring_flag = pring->flag;
  8143. /* Only slow rings */
  8144. if (pring->ringno == LPFC_ELS_RING) {
  8145. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8146. /* Set the lpfc data pending flag */
  8147. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8148. }
  8149. /*
  8150. * Error everything on the txq since these iocbs have not been
  8151. * given to the FW yet.
  8152. */
  8153. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  8154. if (iocb->vport != vport)
  8155. continue;
  8156. list_move_tail(&iocb->list, &completions);
  8157. pring->txq_cnt--;
  8158. }
  8159. /* Next issue ABTS for everything on the txcmplq */
  8160. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  8161. list) {
  8162. if (iocb->vport != vport)
  8163. continue;
  8164. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  8165. }
  8166. pring->flag = prev_pring_flag;
  8167. }
  8168. spin_unlock_irqrestore(&phba->hbalock, flags);
  8169. /* Cancel all the IOCBs from the completions list */
  8170. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8171. IOERR_SLI_DOWN);
  8172. return 1;
  8173. }
  8174. /**
  8175. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8176. * @phba: Pointer to HBA context object.
  8177. *
  8178. * This function cleans up all iocb, buffers, mailbox commands
  8179. * while shutting down the HBA. This function is called with no
  8180. * lock held and always returns 1.
  8181. * This function does the following to cleanup driver resources:
  8182. * - Free discovery resources for each virtual port
  8183. * - Cleanup any pending fabric iocbs
  8184. * - Iterate through the iocb txq and free each entry
  8185. * in the list.
  8186. * - Free up any buffer posted to the HBA
  8187. * - Free mailbox commands in the mailbox queue.
  8188. **/
  8189. int
  8190. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8191. {
  8192. LIST_HEAD(completions);
  8193. struct lpfc_sli *psli = &phba->sli;
  8194. struct lpfc_sli_ring *pring;
  8195. struct lpfc_dmabuf *buf_ptr;
  8196. unsigned long flags = 0;
  8197. int i;
  8198. /* Shutdown the mailbox command sub-system */
  8199. lpfc_sli_mbox_sys_shutdown(phba);
  8200. lpfc_hba_down_prep(phba);
  8201. lpfc_fabric_abort_hba(phba);
  8202. spin_lock_irqsave(&phba->hbalock, flags);
  8203. for (i = 0; i < psli->num_rings; i++) {
  8204. pring = &psli->ring[i];
  8205. /* Only slow rings */
  8206. if (pring->ringno == LPFC_ELS_RING) {
  8207. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8208. /* Set the lpfc data pending flag */
  8209. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8210. }
  8211. /*
  8212. * Error everything on the txq since these iocbs have not been
  8213. * given to the FW yet.
  8214. */
  8215. list_splice_init(&pring->txq, &completions);
  8216. pring->txq_cnt = 0;
  8217. }
  8218. spin_unlock_irqrestore(&phba->hbalock, flags);
  8219. /* Cancel all the IOCBs from the completions list */
  8220. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8221. IOERR_SLI_DOWN);
  8222. spin_lock_irqsave(&phba->hbalock, flags);
  8223. list_splice_init(&phba->elsbuf, &completions);
  8224. phba->elsbuf_cnt = 0;
  8225. phba->elsbuf_prev_cnt = 0;
  8226. spin_unlock_irqrestore(&phba->hbalock, flags);
  8227. while (!list_empty(&completions)) {
  8228. list_remove_head(&completions, buf_ptr,
  8229. struct lpfc_dmabuf, list);
  8230. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8231. kfree(buf_ptr);
  8232. }
  8233. /* Return any active mbox cmds */
  8234. del_timer_sync(&psli->mbox_tmo);
  8235. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8236. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8237. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8238. return 1;
  8239. }
  8240. /**
  8241. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8242. * @srcp: Source memory pointer.
  8243. * @destp: Destination memory pointer.
  8244. * @cnt: Number of words required to be copied.
  8245. *
  8246. * This function is used for copying data between driver memory
  8247. * and the SLI memory. This function also changes the endianness
  8248. * of each word if native endianness is different from SLI
  8249. * endianness. This function can be called with or without
  8250. * lock.
  8251. **/
  8252. void
  8253. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8254. {
  8255. uint32_t *src = srcp;
  8256. uint32_t *dest = destp;
  8257. uint32_t ldata;
  8258. int i;
  8259. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8260. ldata = *src;
  8261. ldata = le32_to_cpu(ldata);
  8262. *dest = ldata;
  8263. src++;
  8264. dest++;
  8265. }
  8266. }
  8267. /**
  8268. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8269. * @srcp: Source memory pointer.
  8270. * @destp: Destination memory pointer.
  8271. * @cnt: Number of words required to be copied.
  8272. *
  8273. * This function is used for copying data between a data structure
  8274. * with big endian representation to local endianness.
  8275. * This function can be called with or without lock.
  8276. **/
  8277. void
  8278. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8279. {
  8280. uint32_t *src = srcp;
  8281. uint32_t *dest = destp;
  8282. uint32_t ldata;
  8283. int i;
  8284. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8285. ldata = *src;
  8286. ldata = be32_to_cpu(ldata);
  8287. *dest = ldata;
  8288. src++;
  8289. dest++;
  8290. }
  8291. }
  8292. /**
  8293. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8294. * @phba: Pointer to HBA context object.
  8295. * @pring: Pointer to driver SLI ring object.
  8296. * @mp: Pointer to driver buffer object.
  8297. *
  8298. * This function is called with no lock held.
  8299. * It always return zero after adding the buffer to the postbufq
  8300. * buffer list.
  8301. **/
  8302. int
  8303. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8304. struct lpfc_dmabuf *mp)
  8305. {
  8306. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8307. later */
  8308. spin_lock_irq(&phba->hbalock);
  8309. list_add_tail(&mp->list, &pring->postbufq);
  8310. pring->postbufq_cnt++;
  8311. spin_unlock_irq(&phba->hbalock);
  8312. return 0;
  8313. }
  8314. /**
  8315. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8316. * @phba: Pointer to HBA context object.
  8317. *
  8318. * When HBQ is enabled, buffers are searched based on tags. This function
  8319. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8320. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8321. * does not conflict with tags of buffer posted for unsolicited events.
  8322. * The function returns the allocated tag. The function is called with
  8323. * no locks held.
  8324. **/
  8325. uint32_t
  8326. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8327. {
  8328. spin_lock_irq(&phba->hbalock);
  8329. phba->buffer_tag_count++;
  8330. /*
  8331. * Always set the QUE_BUFTAG_BIT to distiguish between
  8332. * a tag assigned by HBQ.
  8333. */
  8334. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8335. spin_unlock_irq(&phba->hbalock);
  8336. return phba->buffer_tag_count;
  8337. }
  8338. /**
  8339. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8340. * @phba: Pointer to HBA context object.
  8341. * @pring: Pointer to driver SLI ring object.
  8342. * @tag: Buffer tag.
  8343. *
  8344. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8345. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8346. * iocb is posted to the response ring with the tag of the buffer.
  8347. * This function searches the pring->postbufq list using the tag
  8348. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8349. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8350. * buffer is returned to the caller else NULL is returned.
  8351. * This function is called with no lock held.
  8352. **/
  8353. struct lpfc_dmabuf *
  8354. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8355. uint32_t tag)
  8356. {
  8357. struct lpfc_dmabuf *mp, *next_mp;
  8358. struct list_head *slp = &pring->postbufq;
  8359. /* Search postbufq, from the beginning, looking for a match on tag */
  8360. spin_lock_irq(&phba->hbalock);
  8361. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8362. if (mp->buffer_tag == tag) {
  8363. list_del_init(&mp->list);
  8364. pring->postbufq_cnt--;
  8365. spin_unlock_irq(&phba->hbalock);
  8366. return mp;
  8367. }
  8368. }
  8369. spin_unlock_irq(&phba->hbalock);
  8370. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8371. "0402 Cannot find virtual addr for buffer tag on "
  8372. "ring %d Data x%lx x%p x%p x%x\n",
  8373. pring->ringno, (unsigned long) tag,
  8374. slp->next, slp->prev, pring->postbufq_cnt);
  8375. return NULL;
  8376. }
  8377. /**
  8378. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8379. * @phba: Pointer to HBA context object.
  8380. * @pring: Pointer to driver SLI ring object.
  8381. * @phys: DMA address of the buffer.
  8382. *
  8383. * This function searches the buffer list using the dma_address
  8384. * of unsolicited event to find the driver's lpfc_dmabuf object
  8385. * corresponding to the dma_address. The function returns the
  8386. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8387. * This function is called by the ct and els unsolicited event
  8388. * handlers to get the buffer associated with the unsolicited
  8389. * event.
  8390. *
  8391. * This function is called with no lock held.
  8392. **/
  8393. struct lpfc_dmabuf *
  8394. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8395. dma_addr_t phys)
  8396. {
  8397. struct lpfc_dmabuf *mp, *next_mp;
  8398. struct list_head *slp = &pring->postbufq;
  8399. /* Search postbufq, from the beginning, looking for a match on phys */
  8400. spin_lock_irq(&phba->hbalock);
  8401. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8402. if (mp->phys == phys) {
  8403. list_del_init(&mp->list);
  8404. pring->postbufq_cnt--;
  8405. spin_unlock_irq(&phba->hbalock);
  8406. return mp;
  8407. }
  8408. }
  8409. spin_unlock_irq(&phba->hbalock);
  8410. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8411. "0410 Cannot find virtual addr for mapped buf on "
  8412. "ring %d Data x%llx x%p x%p x%x\n",
  8413. pring->ringno, (unsigned long long)phys,
  8414. slp->next, slp->prev, pring->postbufq_cnt);
  8415. return NULL;
  8416. }
  8417. /**
  8418. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8419. * @phba: Pointer to HBA context object.
  8420. * @cmdiocb: Pointer to driver command iocb object.
  8421. * @rspiocb: Pointer to driver response iocb object.
  8422. *
  8423. * This function is the completion handler for the abort iocbs for
  8424. * ELS commands. This function is called from the ELS ring event
  8425. * handler with no lock held. This function frees memory resources
  8426. * associated with the abort iocb.
  8427. **/
  8428. static void
  8429. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8430. struct lpfc_iocbq *rspiocb)
  8431. {
  8432. IOCB_t *irsp = &rspiocb->iocb;
  8433. uint16_t abort_iotag, abort_context;
  8434. struct lpfc_iocbq *abort_iocb = NULL;
  8435. if (irsp->ulpStatus) {
  8436. /*
  8437. * Assume that the port already completed and returned, or
  8438. * will return the iocb. Just Log the message.
  8439. */
  8440. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8441. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8442. spin_lock_irq(&phba->hbalock);
  8443. if (phba->sli_rev < LPFC_SLI_REV4) {
  8444. if (abort_iotag != 0 &&
  8445. abort_iotag <= phba->sli.last_iotag)
  8446. abort_iocb =
  8447. phba->sli.iocbq_lookup[abort_iotag];
  8448. } else
  8449. /* For sli4 the abort_tag is the XRI,
  8450. * so the abort routine puts the iotag of the iocb
  8451. * being aborted in the context field of the abort
  8452. * IOCB.
  8453. */
  8454. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8455. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8456. "0327 Cannot abort els iocb %p "
  8457. "with tag %x context %x, abort status %x, "
  8458. "abort code %x\n",
  8459. abort_iocb, abort_iotag, abort_context,
  8460. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8461. spin_unlock_irq(&phba->hbalock);
  8462. }
  8463. lpfc_sli_release_iocbq(phba, cmdiocb);
  8464. return;
  8465. }
  8466. /**
  8467. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8468. * @phba: Pointer to HBA context object.
  8469. * @cmdiocb: Pointer to driver command iocb object.
  8470. * @rspiocb: Pointer to driver response iocb object.
  8471. *
  8472. * The function is called from SLI ring event handler with no
  8473. * lock held. This function is the completion handler for ELS commands
  8474. * which are aborted. The function frees memory resources used for
  8475. * the aborted ELS commands.
  8476. **/
  8477. static void
  8478. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8479. struct lpfc_iocbq *rspiocb)
  8480. {
  8481. IOCB_t *irsp = &rspiocb->iocb;
  8482. /* ELS cmd tag <ulpIoTag> completes */
  8483. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8484. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8485. "x%x x%x x%x\n",
  8486. irsp->ulpIoTag, irsp->ulpStatus,
  8487. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8488. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8489. lpfc_ct_free_iocb(phba, cmdiocb);
  8490. else
  8491. lpfc_els_free_iocb(phba, cmdiocb);
  8492. return;
  8493. }
  8494. /**
  8495. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8496. * @phba: Pointer to HBA context object.
  8497. * @pring: Pointer to driver SLI ring object.
  8498. * @cmdiocb: Pointer to driver command iocb object.
  8499. *
  8500. * This function issues an abort iocb for the provided command iocb down to
  8501. * the port. Other than the case the outstanding command iocb is an abort
  8502. * request, this function issues abort out unconditionally. This function is
  8503. * called with hbalock held. The function returns 0 when it fails due to
  8504. * memory allocation failure or when the command iocb is an abort request.
  8505. **/
  8506. static int
  8507. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8508. struct lpfc_iocbq *cmdiocb)
  8509. {
  8510. struct lpfc_vport *vport = cmdiocb->vport;
  8511. struct lpfc_iocbq *abtsiocbp;
  8512. IOCB_t *icmd = NULL;
  8513. IOCB_t *iabt = NULL;
  8514. int retval;
  8515. /*
  8516. * There are certain command types we don't want to abort. And we
  8517. * don't want to abort commands that are already in the process of
  8518. * being aborted.
  8519. */
  8520. icmd = &cmdiocb->iocb;
  8521. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8522. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8523. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8524. return 0;
  8525. /* issue ABTS for this IOCB based on iotag */
  8526. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8527. if (abtsiocbp == NULL)
  8528. return 0;
  8529. /* This signals the response to set the correct status
  8530. * before calling the completion handler
  8531. */
  8532. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8533. iabt = &abtsiocbp->iocb;
  8534. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8535. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8536. if (phba->sli_rev == LPFC_SLI_REV4) {
  8537. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8538. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8539. }
  8540. else
  8541. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8542. iabt->ulpLe = 1;
  8543. iabt->ulpClass = icmd->ulpClass;
  8544. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8545. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8546. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8547. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8548. if (phba->link_state >= LPFC_LINK_UP)
  8549. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8550. else
  8551. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8552. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8553. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8554. "0339 Abort xri x%x, original iotag x%x, "
  8555. "abort cmd iotag x%x\n",
  8556. iabt->un.acxri.abortIoTag,
  8557. iabt->un.acxri.abortContextTag,
  8558. abtsiocbp->iotag);
  8559. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  8560. if (retval)
  8561. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8562. /*
  8563. * Caller to this routine should check for IOCB_ERROR
  8564. * and handle it properly. This routine no longer removes
  8565. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8566. */
  8567. return retval;
  8568. }
  8569. /**
  8570. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8571. * @phba: Pointer to HBA context object.
  8572. * @pring: Pointer to driver SLI ring object.
  8573. * @cmdiocb: Pointer to driver command iocb object.
  8574. *
  8575. * This function issues an abort iocb for the provided command iocb. In case
  8576. * of unloading, the abort iocb will not be issued to commands on the ELS
  8577. * ring. Instead, the callback function shall be changed to those commands
  8578. * so that nothing happens when them finishes. This function is called with
  8579. * hbalock held. The function returns 0 when the command iocb is an abort
  8580. * request.
  8581. **/
  8582. int
  8583. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8584. struct lpfc_iocbq *cmdiocb)
  8585. {
  8586. struct lpfc_vport *vport = cmdiocb->vport;
  8587. int retval = IOCB_ERROR;
  8588. IOCB_t *icmd = NULL;
  8589. /*
  8590. * There are certain command types we don't want to abort. And we
  8591. * don't want to abort commands that are already in the process of
  8592. * being aborted.
  8593. */
  8594. icmd = &cmdiocb->iocb;
  8595. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8596. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8597. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8598. return 0;
  8599. /*
  8600. * If we're unloading, don't abort iocb on the ELS ring, but change
  8601. * the callback so that nothing happens when it finishes.
  8602. */
  8603. if ((vport->load_flag & FC_UNLOADING) &&
  8604. (pring->ringno == LPFC_ELS_RING)) {
  8605. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8606. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8607. else
  8608. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8609. goto abort_iotag_exit;
  8610. }
  8611. /* Now, we try to issue the abort to the cmdiocb out */
  8612. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8613. abort_iotag_exit:
  8614. /*
  8615. * Caller to this routine should check for IOCB_ERROR
  8616. * and handle it properly. This routine no longer removes
  8617. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8618. */
  8619. return retval;
  8620. }
  8621. /**
  8622. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8623. * @phba: Pointer to HBA context object.
  8624. * @pring: Pointer to driver SLI ring object.
  8625. *
  8626. * This function aborts all iocbs in the given ring and frees all the iocb
  8627. * objects in txq. This function issues abort iocbs unconditionally for all
  8628. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8629. * to complete before the return of this function. The caller is not required
  8630. * to hold any locks.
  8631. **/
  8632. static void
  8633. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8634. {
  8635. LIST_HEAD(completions);
  8636. struct lpfc_iocbq *iocb, *next_iocb;
  8637. if (pring->ringno == LPFC_ELS_RING)
  8638. lpfc_fabric_abort_hba(phba);
  8639. spin_lock_irq(&phba->hbalock);
  8640. /* Take off all the iocbs on txq for cancelling */
  8641. list_splice_init(&pring->txq, &completions);
  8642. pring->txq_cnt = 0;
  8643. /* Next issue ABTS for everything on the txcmplq */
  8644. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8645. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8646. spin_unlock_irq(&phba->hbalock);
  8647. /* Cancel all the IOCBs from the completions list */
  8648. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8649. IOERR_SLI_ABORTED);
  8650. }
  8651. /**
  8652. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8653. * @phba: pointer to lpfc HBA data structure.
  8654. *
  8655. * This routine will abort all pending and outstanding iocbs to an HBA.
  8656. **/
  8657. void
  8658. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8659. {
  8660. struct lpfc_sli *psli = &phba->sli;
  8661. struct lpfc_sli_ring *pring;
  8662. int i;
  8663. for (i = 0; i < psli->num_rings; i++) {
  8664. pring = &psli->ring[i];
  8665. lpfc_sli_iocb_ring_abort(phba, pring);
  8666. }
  8667. }
  8668. /**
  8669. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8670. * @iocbq: Pointer to driver iocb object.
  8671. * @vport: Pointer to driver virtual port object.
  8672. * @tgt_id: SCSI ID of the target.
  8673. * @lun_id: LUN ID of the scsi device.
  8674. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8675. *
  8676. * This function acts as an iocb filter for functions which abort or count
  8677. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8678. * 0 if the filtering criteria is met for the given iocb and will return
  8679. * 1 if the filtering criteria is not met.
  8680. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8681. * given iocb is for the SCSI device specified by vport, tgt_id and
  8682. * lun_id parameter.
  8683. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8684. * given iocb is for the SCSI target specified by vport and tgt_id
  8685. * parameters.
  8686. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8687. * given iocb is for the SCSI host associated with the given vport.
  8688. * This function is called with no locks held.
  8689. **/
  8690. static int
  8691. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8692. uint16_t tgt_id, uint64_t lun_id,
  8693. lpfc_ctx_cmd ctx_cmd)
  8694. {
  8695. struct lpfc_scsi_buf *lpfc_cmd;
  8696. int rc = 1;
  8697. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8698. return rc;
  8699. if (iocbq->vport != vport)
  8700. return rc;
  8701. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8702. if (lpfc_cmd->pCmd == NULL)
  8703. return rc;
  8704. switch (ctx_cmd) {
  8705. case LPFC_CTX_LUN:
  8706. if ((lpfc_cmd->rdata->pnode) &&
  8707. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8708. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8709. rc = 0;
  8710. break;
  8711. case LPFC_CTX_TGT:
  8712. if ((lpfc_cmd->rdata->pnode) &&
  8713. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8714. rc = 0;
  8715. break;
  8716. case LPFC_CTX_HOST:
  8717. rc = 0;
  8718. break;
  8719. default:
  8720. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8721. __func__, ctx_cmd);
  8722. break;
  8723. }
  8724. return rc;
  8725. }
  8726. /**
  8727. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8728. * @vport: Pointer to virtual port.
  8729. * @tgt_id: SCSI ID of the target.
  8730. * @lun_id: LUN ID of the scsi device.
  8731. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8732. *
  8733. * This function returns number of FCP commands pending for the vport.
  8734. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8735. * commands pending on the vport associated with SCSI device specified
  8736. * by tgt_id and lun_id parameters.
  8737. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8738. * commands pending on the vport associated with SCSI target specified
  8739. * by tgt_id parameter.
  8740. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8741. * commands pending on the vport.
  8742. * This function returns the number of iocbs which satisfy the filter.
  8743. * This function is called without any lock held.
  8744. **/
  8745. int
  8746. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8747. lpfc_ctx_cmd ctx_cmd)
  8748. {
  8749. struct lpfc_hba *phba = vport->phba;
  8750. struct lpfc_iocbq *iocbq;
  8751. int sum, i;
  8752. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8753. iocbq = phba->sli.iocbq_lookup[i];
  8754. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8755. ctx_cmd) == 0)
  8756. sum++;
  8757. }
  8758. return sum;
  8759. }
  8760. /**
  8761. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8762. * @phba: Pointer to HBA context object
  8763. * @cmdiocb: Pointer to command iocb object.
  8764. * @rspiocb: Pointer to response iocb object.
  8765. *
  8766. * This function is called when an aborted FCP iocb completes. This
  8767. * function is called by the ring event handler with no lock held.
  8768. * This function frees the iocb.
  8769. **/
  8770. void
  8771. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8772. struct lpfc_iocbq *rspiocb)
  8773. {
  8774. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8775. "3096 ABORT_XRI_CN completing on xri x%x "
  8776. "original iotag x%x, abort cmd iotag x%x "
  8777. "status 0x%x, reason 0x%x\n",
  8778. cmdiocb->iocb.un.acxri.abortContextTag,
  8779. cmdiocb->iocb.un.acxri.abortIoTag,
  8780. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8781. rspiocb->iocb.un.ulpWord[4]);
  8782. lpfc_sli_release_iocbq(phba, cmdiocb);
  8783. return;
  8784. }
  8785. /**
  8786. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8787. * @vport: Pointer to virtual port.
  8788. * @pring: Pointer to driver SLI ring object.
  8789. * @tgt_id: SCSI ID of the target.
  8790. * @lun_id: LUN ID of the scsi device.
  8791. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8792. *
  8793. * This function sends an abort command for every SCSI command
  8794. * associated with the given virtual port pending on the ring
  8795. * filtered by lpfc_sli_validate_fcp_iocb function.
  8796. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8797. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8798. * parameters
  8799. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8800. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8801. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8802. * FCP iocbs associated with virtual port.
  8803. * This function returns number of iocbs it failed to abort.
  8804. * This function is called with no locks held.
  8805. **/
  8806. int
  8807. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8808. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8809. {
  8810. struct lpfc_hba *phba = vport->phba;
  8811. struct lpfc_iocbq *iocbq;
  8812. struct lpfc_iocbq *abtsiocb;
  8813. IOCB_t *cmd = NULL;
  8814. int errcnt = 0, ret_val = 0;
  8815. int i;
  8816. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8817. iocbq = phba->sli.iocbq_lookup[i];
  8818. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8819. abort_cmd) != 0)
  8820. continue;
  8821. /* issue ABTS for this IOCB based on iotag */
  8822. abtsiocb = lpfc_sli_get_iocbq(phba);
  8823. if (abtsiocb == NULL) {
  8824. errcnt++;
  8825. continue;
  8826. }
  8827. cmd = &iocbq->iocb;
  8828. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8829. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8830. if (phba->sli_rev == LPFC_SLI_REV4)
  8831. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8832. else
  8833. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8834. abtsiocb->iocb.ulpLe = 1;
  8835. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8836. abtsiocb->vport = phba->pport;
  8837. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8838. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8839. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8840. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8841. if (lpfc_is_link_up(phba))
  8842. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8843. else
  8844. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8845. /* Setup callback routine and issue the command. */
  8846. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8847. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8848. abtsiocb, 0);
  8849. if (ret_val == IOCB_ERROR) {
  8850. lpfc_sli_release_iocbq(phba, abtsiocb);
  8851. errcnt++;
  8852. continue;
  8853. }
  8854. }
  8855. return errcnt;
  8856. }
  8857. /**
  8858. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8859. * @phba: Pointer to HBA context object.
  8860. * @cmdiocbq: Pointer to command iocb.
  8861. * @rspiocbq: Pointer to response iocb.
  8862. *
  8863. * This function is the completion handler for iocbs issued using
  8864. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8865. * ring event handler function without any lock held. This function
  8866. * can be called from both worker thread context and interrupt
  8867. * context. This function also can be called from other thread which
  8868. * cleans up the SLI layer objects.
  8869. * This function copy the contents of the response iocb to the
  8870. * response iocb memory object provided by the caller of
  8871. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  8872. * sleeps for the iocb completion.
  8873. **/
  8874. static void
  8875. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  8876. struct lpfc_iocbq *cmdiocbq,
  8877. struct lpfc_iocbq *rspiocbq)
  8878. {
  8879. wait_queue_head_t *pdone_q;
  8880. unsigned long iflags;
  8881. struct lpfc_scsi_buf *lpfc_cmd;
  8882. spin_lock_irqsave(&phba->hbalock, iflags);
  8883. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  8884. if (cmdiocbq->context2 && rspiocbq)
  8885. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  8886. &rspiocbq->iocb, sizeof(IOCB_t));
  8887. /* Set the exchange busy flag for task management commands */
  8888. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  8889. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  8890. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  8891. cur_iocbq);
  8892. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  8893. }
  8894. pdone_q = cmdiocbq->context_un.wait_queue;
  8895. if (pdone_q)
  8896. wake_up(pdone_q);
  8897. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8898. return;
  8899. }
  8900. /**
  8901. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  8902. * @phba: Pointer to HBA context object..
  8903. * @piocbq: Pointer to command iocb.
  8904. * @flag: Flag to test.
  8905. *
  8906. * This routine grabs the hbalock and then test the iocb_flag to
  8907. * see if the passed in flag is set.
  8908. * Returns:
  8909. * 1 if flag is set.
  8910. * 0 if flag is not set.
  8911. **/
  8912. static int
  8913. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  8914. struct lpfc_iocbq *piocbq, uint32_t flag)
  8915. {
  8916. unsigned long iflags;
  8917. int ret;
  8918. spin_lock_irqsave(&phba->hbalock, iflags);
  8919. ret = piocbq->iocb_flag & flag;
  8920. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8921. return ret;
  8922. }
  8923. /**
  8924. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  8925. * @phba: Pointer to HBA context object..
  8926. * @pring: Pointer to sli ring.
  8927. * @piocb: Pointer to command iocb.
  8928. * @prspiocbq: Pointer to response iocb.
  8929. * @timeout: Timeout in number of seconds.
  8930. *
  8931. * This function issues the iocb to firmware and waits for the
  8932. * iocb to complete. If the iocb command is not
  8933. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  8934. * Caller should not free the iocb resources if this function
  8935. * returns IOCB_TIMEDOUT.
  8936. * The function waits for the iocb completion using an
  8937. * non-interruptible wait.
  8938. * This function will sleep while waiting for iocb completion.
  8939. * So, this function should not be called from any context which
  8940. * does not allow sleeping. Due to the same reason, this function
  8941. * cannot be called with interrupt disabled.
  8942. * This function assumes that the iocb completions occur while
  8943. * this function sleep. So, this function cannot be called from
  8944. * the thread which process iocb completion for this ring.
  8945. * This function clears the iocb_flag of the iocb object before
  8946. * issuing the iocb and the iocb completion handler sets this
  8947. * flag and wakes this thread when the iocb completes.
  8948. * The contents of the response iocb will be copied to prspiocbq
  8949. * by the completion handler when the command completes.
  8950. * This function returns IOCB_SUCCESS when success.
  8951. * This function is called with no lock held.
  8952. **/
  8953. int
  8954. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  8955. uint32_t ring_number,
  8956. struct lpfc_iocbq *piocb,
  8957. struct lpfc_iocbq *prspiocbq,
  8958. uint32_t timeout)
  8959. {
  8960. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  8961. long timeleft, timeout_req = 0;
  8962. int retval = IOCB_SUCCESS;
  8963. uint32_t creg_val;
  8964. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8965. /*
  8966. * If the caller has provided a response iocbq buffer, then context2
  8967. * is NULL or its an error.
  8968. */
  8969. if (prspiocbq) {
  8970. if (piocb->context2)
  8971. return IOCB_ERROR;
  8972. piocb->context2 = prspiocbq;
  8973. }
  8974. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  8975. piocb->context_un.wait_queue = &done_q;
  8976. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  8977. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  8978. if (lpfc_readl(phba->HCregaddr, &creg_val))
  8979. return IOCB_ERROR;
  8980. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  8981. writel(creg_val, phba->HCregaddr);
  8982. readl(phba->HCregaddr); /* flush */
  8983. }
  8984. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  8985. SLI_IOCB_RET_IOCB);
  8986. if (retval == IOCB_SUCCESS) {
  8987. timeout_req = timeout * HZ;
  8988. timeleft = wait_event_timeout(done_q,
  8989. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  8990. timeout_req);
  8991. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  8992. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8993. "0331 IOCB wake signaled\n");
  8994. } else if (timeleft == 0) {
  8995. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8996. "0338 IOCB wait timeout error - no "
  8997. "wake response Data x%x\n", timeout);
  8998. retval = IOCB_TIMEDOUT;
  8999. } else {
  9000. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9001. "0330 IOCB wake NOT set, "
  9002. "Data x%x x%lx\n",
  9003. timeout, (timeleft / jiffies));
  9004. retval = IOCB_TIMEDOUT;
  9005. }
  9006. } else if (retval == IOCB_BUSY) {
  9007. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9008. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  9009. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  9010. return retval;
  9011. } else {
  9012. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9013. "0332 IOCB wait issue failed, Data x%x\n",
  9014. retval);
  9015. retval = IOCB_ERROR;
  9016. }
  9017. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  9018. if (lpfc_readl(phba->HCregaddr, &creg_val))
  9019. return IOCB_ERROR;
  9020. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  9021. writel(creg_val, phba->HCregaddr);
  9022. readl(phba->HCregaddr); /* flush */
  9023. }
  9024. if (prspiocbq)
  9025. piocb->context2 = NULL;
  9026. piocb->context_un.wait_queue = NULL;
  9027. piocb->iocb_cmpl = NULL;
  9028. return retval;
  9029. }
  9030. /**
  9031. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  9032. * @phba: Pointer to HBA context object.
  9033. * @pmboxq: Pointer to driver mailbox object.
  9034. * @timeout: Timeout in number of seconds.
  9035. *
  9036. * This function issues the mailbox to firmware and waits for the
  9037. * mailbox command to complete. If the mailbox command is not
  9038. * completed within timeout seconds, it returns MBX_TIMEOUT.
  9039. * The function waits for the mailbox completion using an
  9040. * interruptible wait. If the thread is woken up due to a
  9041. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  9042. * should not free the mailbox resources, if this function returns
  9043. * MBX_TIMEOUT.
  9044. * This function will sleep while waiting for mailbox completion.
  9045. * So, this function should not be called from any context which
  9046. * does not allow sleeping. Due to the same reason, this function
  9047. * cannot be called with interrupt disabled.
  9048. * This function assumes that the mailbox completion occurs while
  9049. * this function sleep. So, this function cannot be called from
  9050. * the worker thread which processes mailbox completion.
  9051. * This function is called in the context of HBA management
  9052. * applications.
  9053. * This function returns MBX_SUCCESS when successful.
  9054. * This function is called with no lock held.
  9055. **/
  9056. int
  9057. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  9058. uint32_t timeout)
  9059. {
  9060. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  9061. int retval;
  9062. unsigned long flag;
  9063. /* The caller must leave context1 empty. */
  9064. if (pmboxq->context1)
  9065. return MBX_NOT_FINISHED;
  9066. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  9067. /* setup wake call as IOCB callback */
  9068. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  9069. /* setup context field to pass wait_queue pointer to wake function */
  9070. pmboxq->context1 = &done_q;
  9071. /* now issue the command */
  9072. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  9073. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  9074. wait_event_interruptible_timeout(done_q,
  9075. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  9076. timeout * HZ);
  9077. spin_lock_irqsave(&phba->hbalock, flag);
  9078. pmboxq->context1 = NULL;
  9079. /*
  9080. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  9081. * else do not free the resources.
  9082. */
  9083. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  9084. retval = MBX_SUCCESS;
  9085. lpfc_sli4_swap_str(phba, pmboxq);
  9086. } else {
  9087. retval = MBX_TIMEOUT;
  9088. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9089. }
  9090. spin_unlock_irqrestore(&phba->hbalock, flag);
  9091. }
  9092. return retval;
  9093. }
  9094. /**
  9095. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  9096. * @phba: Pointer to HBA context.
  9097. *
  9098. * This function is called to shutdown the driver's mailbox sub-system.
  9099. * It first marks the mailbox sub-system is in a block state to prevent
  9100. * the asynchronous mailbox command from issued off the pending mailbox
  9101. * command queue. If the mailbox command sub-system shutdown is due to
  9102. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  9103. * the mailbox sub-system flush routine to forcefully bring down the
  9104. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  9105. * as with offline or HBA function reset), this routine will wait for the
  9106. * outstanding mailbox command to complete before invoking the mailbox
  9107. * sub-system flush routine to gracefully bring down mailbox sub-system.
  9108. **/
  9109. void
  9110. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  9111. {
  9112. struct lpfc_sli *psli = &phba->sli;
  9113. unsigned long timeout;
  9114. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  9115. spin_lock_irq(&phba->hbalock);
  9116. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  9117. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  9118. /* Determine how long we might wait for the active mailbox
  9119. * command to be gracefully completed by firmware.
  9120. */
  9121. if (phba->sli.mbox_active)
  9122. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  9123. phba->sli.mbox_active) *
  9124. 1000) + jiffies;
  9125. spin_unlock_irq(&phba->hbalock);
  9126. while (phba->sli.mbox_active) {
  9127. /* Check active mailbox complete status every 2ms */
  9128. msleep(2);
  9129. if (time_after(jiffies, timeout))
  9130. /* Timeout, let the mailbox flush routine to
  9131. * forcefully release active mailbox command
  9132. */
  9133. break;
  9134. }
  9135. } else
  9136. spin_unlock_irq(&phba->hbalock);
  9137. lpfc_sli_mbox_sys_flush(phba);
  9138. }
  9139. /**
  9140. * lpfc_sli_eratt_read - read sli-3 error attention events
  9141. * @phba: Pointer to HBA context.
  9142. *
  9143. * This function is called to read the SLI3 device error attention registers
  9144. * for possible error attention events. The caller must hold the hostlock
  9145. * with spin_lock_irq().
  9146. *
  9147. * This function returns 1 when there is Error Attention in the Host Attention
  9148. * Register and returns 0 otherwise.
  9149. **/
  9150. static int
  9151. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  9152. {
  9153. uint32_t ha_copy;
  9154. /* Read chip Host Attention (HA) register */
  9155. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9156. goto unplug_err;
  9157. if (ha_copy & HA_ERATT) {
  9158. /* Read host status register to retrieve error event */
  9159. if (lpfc_sli_read_hs(phba))
  9160. goto unplug_err;
  9161. /* Check if there is a deferred error condition is active */
  9162. if ((HS_FFER1 & phba->work_hs) &&
  9163. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9164. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  9165. phba->hba_flag |= DEFER_ERATT;
  9166. /* Clear all interrupt enable conditions */
  9167. writel(0, phba->HCregaddr);
  9168. readl(phba->HCregaddr);
  9169. }
  9170. /* Set the driver HA work bitmap */
  9171. phba->work_ha |= HA_ERATT;
  9172. /* Indicate polling handles this ERATT */
  9173. phba->hba_flag |= HBA_ERATT_HANDLED;
  9174. return 1;
  9175. }
  9176. return 0;
  9177. unplug_err:
  9178. /* Set the driver HS work bitmap */
  9179. phba->work_hs |= UNPLUG_ERR;
  9180. /* Set the driver HA work bitmap */
  9181. phba->work_ha |= HA_ERATT;
  9182. /* Indicate polling handles this ERATT */
  9183. phba->hba_flag |= HBA_ERATT_HANDLED;
  9184. return 1;
  9185. }
  9186. /**
  9187. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9188. * @phba: Pointer to HBA context.
  9189. *
  9190. * This function is called to read the SLI4 device error attention registers
  9191. * for possible error attention events. The caller must hold the hostlock
  9192. * with spin_lock_irq().
  9193. *
  9194. * This function returns 1 when there is Error Attention in the Host Attention
  9195. * Register and returns 0 otherwise.
  9196. **/
  9197. static int
  9198. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9199. {
  9200. uint32_t uerr_sta_hi, uerr_sta_lo;
  9201. uint32_t if_type, portsmphr;
  9202. struct lpfc_register portstat_reg;
  9203. /*
  9204. * For now, use the SLI4 device internal unrecoverable error
  9205. * registers for error attention. This can be changed later.
  9206. */
  9207. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9208. switch (if_type) {
  9209. case LPFC_SLI_INTF_IF_TYPE_0:
  9210. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9211. &uerr_sta_lo) ||
  9212. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9213. &uerr_sta_hi)) {
  9214. phba->work_hs |= UNPLUG_ERR;
  9215. phba->work_ha |= HA_ERATT;
  9216. phba->hba_flag |= HBA_ERATT_HANDLED;
  9217. return 1;
  9218. }
  9219. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9220. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9221. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9222. "1423 HBA Unrecoverable error: "
  9223. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9224. "ue_mask_lo_reg=0x%x, "
  9225. "ue_mask_hi_reg=0x%x\n",
  9226. uerr_sta_lo, uerr_sta_hi,
  9227. phba->sli4_hba.ue_mask_lo,
  9228. phba->sli4_hba.ue_mask_hi);
  9229. phba->work_status[0] = uerr_sta_lo;
  9230. phba->work_status[1] = uerr_sta_hi;
  9231. phba->work_ha |= HA_ERATT;
  9232. phba->hba_flag |= HBA_ERATT_HANDLED;
  9233. return 1;
  9234. }
  9235. break;
  9236. case LPFC_SLI_INTF_IF_TYPE_2:
  9237. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9238. &portstat_reg.word0) ||
  9239. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9240. &portsmphr)){
  9241. phba->work_hs |= UNPLUG_ERR;
  9242. phba->work_ha |= HA_ERATT;
  9243. phba->hba_flag |= HBA_ERATT_HANDLED;
  9244. return 1;
  9245. }
  9246. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9247. phba->work_status[0] =
  9248. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9249. phba->work_status[1] =
  9250. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9251. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9252. "2885 Port Status Event: "
  9253. "port status reg 0x%x, "
  9254. "port smphr reg 0x%x, "
  9255. "error 1=0x%x, error 2=0x%x\n",
  9256. portstat_reg.word0,
  9257. portsmphr,
  9258. phba->work_status[0],
  9259. phba->work_status[1]);
  9260. phba->work_ha |= HA_ERATT;
  9261. phba->hba_flag |= HBA_ERATT_HANDLED;
  9262. return 1;
  9263. }
  9264. break;
  9265. case LPFC_SLI_INTF_IF_TYPE_1:
  9266. default:
  9267. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9268. "2886 HBA Error Attention on unsupported "
  9269. "if type %d.", if_type);
  9270. return 1;
  9271. }
  9272. return 0;
  9273. }
  9274. /**
  9275. * lpfc_sli_check_eratt - check error attention events
  9276. * @phba: Pointer to HBA context.
  9277. *
  9278. * This function is called from timer soft interrupt context to check HBA's
  9279. * error attention register bit for error attention events.
  9280. *
  9281. * This function returns 1 when there is Error Attention in the Host Attention
  9282. * Register and returns 0 otherwise.
  9283. **/
  9284. int
  9285. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9286. {
  9287. uint32_t ha_copy;
  9288. /* If somebody is waiting to handle an eratt, don't process it
  9289. * here. The brdkill function will do this.
  9290. */
  9291. if (phba->link_flag & LS_IGNORE_ERATT)
  9292. return 0;
  9293. /* Check if interrupt handler handles this ERATT */
  9294. spin_lock_irq(&phba->hbalock);
  9295. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9296. /* Interrupt handler has handled ERATT */
  9297. spin_unlock_irq(&phba->hbalock);
  9298. return 0;
  9299. }
  9300. /*
  9301. * If there is deferred error attention, do not check for error
  9302. * attention
  9303. */
  9304. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9305. spin_unlock_irq(&phba->hbalock);
  9306. return 0;
  9307. }
  9308. /* If PCI channel is offline, don't process it */
  9309. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9310. spin_unlock_irq(&phba->hbalock);
  9311. return 0;
  9312. }
  9313. switch (phba->sli_rev) {
  9314. case LPFC_SLI_REV2:
  9315. case LPFC_SLI_REV3:
  9316. /* Read chip Host Attention (HA) register */
  9317. ha_copy = lpfc_sli_eratt_read(phba);
  9318. break;
  9319. case LPFC_SLI_REV4:
  9320. /* Read device Uncoverable Error (UERR) registers */
  9321. ha_copy = lpfc_sli4_eratt_read(phba);
  9322. break;
  9323. default:
  9324. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9325. "0299 Invalid SLI revision (%d)\n",
  9326. phba->sli_rev);
  9327. ha_copy = 0;
  9328. break;
  9329. }
  9330. spin_unlock_irq(&phba->hbalock);
  9331. return ha_copy;
  9332. }
  9333. /**
  9334. * lpfc_intr_state_check - Check device state for interrupt handling
  9335. * @phba: Pointer to HBA context.
  9336. *
  9337. * This inline routine checks whether a device or its PCI slot is in a state
  9338. * that the interrupt should be handled.
  9339. *
  9340. * This function returns 0 if the device or the PCI slot is in a state that
  9341. * interrupt should be handled, otherwise -EIO.
  9342. */
  9343. static inline int
  9344. lpfc_intr_state_check(struct lpfc_hba *phba)
  9345. {
  9346. /* If the pci channel is offline, ignore all the interrupts */
  9347. if (unlikely(pci_channel_offline(phba->pcidev)))
  9348. return -EIO;
  9349. /* Update device level interrupt statistics */
  9350. phba->sli.slistat.sli_intr++;
  9351. /* Ignore all interrupts during initialization. */
  9352. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9353. return -EIO;
  9354. return 0;
  9355. }
  9356. /**
  9357. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9358. * @irq: Interrupt number.
  9359. * @dev_id: The device context pointer.
  9360. *
  9361. * This function is directly called from the PCI layer as an interrupt
  9362. * service routine when device with SLI-3 interface spec is enabled with
  9363. * MSI-X multi-message interrupt mode and there are slow-path events in
  9364. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9365. * interrupt mode, this function is called as part of the device-level
  9366. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9367. * is undergoing initialization, the interrupt handler will not process
  9368. * the interrupt. The link attention and ELS ring attention events are
  9369. * handled by the worker thread. The interrupt handler signals the worker
  9370. * thread and returns for these events. This function is called without
  9371. * any lock held. It gets the hbalock to access and update SLI data
  9372. * structures.
  9373. *
  9374. * This function returns IRQ_HANDLED when interrupt is handled else it
  9375. * returns IRQ_NONE.
  9376. **/
  9377. irqreturn_t
  9378. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9379. {
  9380. struct lpfc_hba *phba;
  9381. uint32_t ha_copy, hc_copy;
  9382. uint32_t work_ha_copy;
  9383. unsigned long status;
  9384. unsigned long iflag;
  9385. uint32_t control;
  9386. MAILBOX_t *mbox, *pmbox;
  9387. struct lpfc_vport *vport;
  9388. struct lpfc_nodelist *ndlp;
  9389. struct lpfc_dmabuf *mp;
  9390. LPFC_MBOXQ_t *pmb;
  9391. int rc;
  9392. /*
  9393. * Get the driver's phba structure from the dev_id and
  9394. * assume the HBA is not interrupting.
  9395. */
  9396. phba = (struct lpfc_hba *)dev_id;
  9397. if (unlikely(!phba))
  9398. return IRQ_NONE;
  9399. /*
  9400. * Stuff needs to be attented to when this function is invoked as an
  9401. * individual interrupt handler in MSI-X multi-message interrupt mode
  9402. */
  9403. if (phba->intr_type == MSIX) {
  9404. /* Check device state for handling interrupt */
  9405. if (lpfc_intr_state_check(phba))
  9406. return IRQ_NONE;
  9407. /* Need to read HA REG for slow-path events */
  9408. spin_lock_irqsave(&phba->hbalock, iflag);
  9409. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9410. goto unplug_error;
  9411. /* If somebody is waiting to handle an eratt don't process it
  9412. * here. The brdkill function will do this.
  9413. */
  9414. if (phba->link_flag & LS_IGNORE_ERATT)
  9415. ha_copy &= ~HA_ERATT;
  9416. /* Check the need for handling ERATT in interrupt handler */
  9417. if (ha_copy & HA_ERATT) {
  9418. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9419. /* ERATT polling has handled ERATT */
  9420. ha_copy &= ~HA_ERATT;
  9421. else
  9422. /* Indicate interrupt handler handles ERATT */
  9423. phba->hba_flag |= HBA_ERATT_HANDLED;
  9424. }
  9425. /*
  9426. * If there is deferred error attention, do not check for any
  9427. * interrupt.
  9428. */
  9429. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9430. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9431. return IRQ_NONE;
  9432. }
  9433. /* Clear up only attention source related to slow-path */
  9434. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9435. goto unplug_error;
  9436. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9437. HC_LAINT_ENA | HC_ERINT_ENA),
  9438. phba->HCregaddr);
  9439. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9440. phba->HAregaddr);
  9441. writel(hc_copy, phba->HCregaddr);
  9442. readl(phba->HAregaddr); /* flush */
  9443. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9444. } else
  9445. ha_copy = phba->ha_copy;
  9446. work_ha_copy = ha_copy & phba->work_ha_mask;
  9447. if (work_ha_copy) {
  9448. if (work_ha_copy & HA_LATT) {
  9449. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9450. /*
  9451. * Turn off Link Attention interrupts
  9452. * until CLEAR_LA done
  9453. */
  9454. spin_lock_irqsave(&phba->hbalock, iflag);
  9455. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9456. if (lpfc_readl(phba->HCregaddr, &control))
  9457. goto unplug_error;
  9458. control &= ~HC_LAINT_ENA;
  9459. writel(control, phba->HCregaddr);
  9460. readl(phba->HCregaddr); /* flush */
  9461. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9462. }
  9463. else
  9464. work_ha_copy &= ~HA_LATT;
  9465. }
  9466. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9467. /*
  9468. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9469. * the only slow ring.
  9470. */
  9471. status = (work_ha_copy &
  9472. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9473. status >>= (4*LPFC_ELS_RING);
  9474. if (status & HA_RXMASK) {
  9475. spin_lock_irqsave(&phba->hbalock, iflag);
  9476. if (lpfc_readl(phba->HCregaddr, &control))
  9477. goto unplug_error;
  9478. lpfc_debugfs_slow_ring_trc(phba,
  9479. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9480. control, status,
  9481. (uint32_t)phba->sli.slistat.sli_intr);
  9482. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9483. lpfc_debugfs_slow_ring_trc(phba,
  9484. "ISR Disable ring:"
  9485. "pwork:x%x hawork:x%x wait:x%x",
  9486. phba->work_ha, work_ha_copy,
  9487. (uint32_t)((unsigned long)
  9488. &phba->work_waitq));
  9489. control &=
  9490. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9491. writel(control, phba->HCregaddr);
  9492. readl(phba->HCregaddr); /* flush */
  9493. }
  9494. else {
  9495. lpfc_debugfs_slow_ring_trc(phba,
  9496. "ISR slow ring: pwork:"
  9497. "x%x hawork:x%x wait:x%x",
  9498. phba->work_ha, work_ha_copy,
  9499. (uint32_t)((unsigned long)
  9500. &phba->work_waitq));
  9501. }
  9502. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9503. }
  9504. }
  9505. spin_lock_irqsave(&phba->hbalock, iflag);
  9506. if (work_ha_copy & HA_ERATT) {
  9507. if (lpfc_sli_read_hs(phba))
  9508. goto unplug_error;
  9509. /*
  9510. * Check if there is a deferred error condition
  9511. * is active
  9512. */
  9513. if ((HS_FFER1 & phba->work_hs) &&
  9514. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9515. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9516. phba->work_hs)) {
  9517. phba->hba_flag |= DEFER_ERATT;
  9518. /* Clear all interrupt enable conditions */
  9519. writel(0, phba->HCregaddr);
  9520. readl(phba->HCregaddr);
  9521. }
  9522. }
  9523. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9524. pmb = phba->sli.mbox_active;
  9525. pmbox = &pmb->u.mb;
  9526. mbox = phba->mbox;
  9527. vport = pmb->vport;
  9528. /* First check out the status word */
  9529. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9530. if (pmbox->mbxOwner != OWN_HOST) {
  9531. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9532. /*
  9533. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9534. * mbxStatus <status>
  9535. */
  9536. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9537. LOG_SLI,
  9538. "(%d):0304 Stray Mailbox "
  9539. "Interrupt mbxCommand x%x "
  9540. "mbxStatus x%x\n",
  9541. (vport ? vport->vpi : 0),
  9542. pmbox->mbxCommand,
  9543. pmbox->mbxStatus);
  9544. /* clear mailbox attention bit */
  9545. work_ha_copy &= ~HA_MBATT;
  9546. } else {
  9547. phba->sli.mbox_active = NULL;
  9548. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9549. phba->last_completion_time = jiffies;
  9550. del_timer(&phba->sli.mbox_tmo);
  9551. if (pmb->mbox_cmpl) {
  9552. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9553. MAILBOX_CMD_SIZE);
  9554. if (pmb->out_ext_byte_len &&
  9555. pmb->context2)
  9556. lpfc_sli_pcimem_bcopy(
  9557. phba->mbox_ext,
  9558. pmb->context2,
  9559. pmb->out_ext_byte_len);
  9560. }
  9561. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9562. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9563. lpfc_debugfs_disc_trc(vport,
  9564. LPFC_DISC_TRC_MBOX_VPORT,
  9565. "MBOX dflt rpi: : "
  9566. "status:x%x rpi:x%x",
  9567. (uint32_t)pmbox->mbxStatus,
  9568. pmbox->un.varWords[0], 0);
  9569. if (!pmbox->mbxStatus) {
  9570. mp = (struct lpfc_dmabuf *)
  9571. (pmb->context1);
  9572. ndlp = (struct lpfc_nodelist *)
  9573. pmb->context2;
  9574. /* Reg_LOGIN of dflt RPI was
  9575. * successful. new lets get
  9576. * rid of the RPI using the
  9577. * same mbox buffer.
  9578. */
  9579. lpfc_unreg_login(phba,
  9580. vport->vpi,
  9581. pmbox->un.varWords[0],
  9582. pmb);
  9583. pmb->mbox_cmpl =
  9584. lpfc_mbx_cmpl_dflt_rpi;
  9585. pmb->context1 = mp;
  9586. pmb->context2 = ndlp;
  9587. pmb->vport = vport;
  9588. rc = lpfc_sli_issue_mbox(phba,
  9589. pmb,
  9590. MBX_NOWAIT);
  9591. if (rc != MBX_BUSY)
  9592. lpfc_printf_log(phba,
  9593. KERN_ERR,
  9594. LOG_MBOX | LOG_SLI,
  9595. "0350 rc should have"
  9596. "been MBX_BUSY\n");
  9597. if (rc != MBX_NOT_FINISHED)
  9598. goto send_current_mbox;
  9599. }
  9600. }
  9601. spin_lock_irqsave(
  9602. &phba->pport->work_port_lock,
  9603. iflag);
  9604. phba->pport->work_port_events &=
  9605. ~WORKER_MBOX_TMO;
  9606. spin_unlock_irqrestore(
  9607. &phba->pport->work_port_lock,
  9608. iflag);
  9609. lpfc_mbox_cmpl_put(phba, pmb);
  9610. }
  9611. } else
  9612. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9613. if ((work_ha_copy & HA_MBATT) &&
  9614. (phba->sli.mbox_active == NULL)) {
  9615. send_current_mbox:
  9616. /* Process next mailbox command if there is one */
  9617. do {
  9618. rc = lpfc_sli_issue_mbox(phba, NULL,
  9619. MBX_NOWAIT);
  9620. } while (rc == MBX_NOT_FINISHED);
  9621. if (rc != MBX_SUCCESS)
  9622. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9623. LOG_SLI, "0349 rc should be "
  9624. "MBX_SUCCESS\n");
  9625. }
  9626. spin_lock_irqsave(&phba->hbalock, iflag);
  9627. phba->work_ha |= work_ha_copy;
  9628. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9629. lpfc_worker_wake_up(phba);
  9630. }
  9631. return IRQ_HANDLED;
  9632. unplug_error:
  9633. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9634. return IRQ_HANDLED;
  9635. } /* lpfc_sli_sp_intr_handler */
  9636. /**
  9637. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9638. * @irq: Interrupt number.
  9639. * @dev_id: The device context pointer.
  9640. *
  9641. * This function is directly called from the PCI layer as an interrupt
  9642. * service routine when device with SLI-3 interface spec is enabled with
  9643. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9644. * ring event in the HBA. However, when the device is enabled with either
  9645. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9646. * device-level interrupt handler. When the PCI slot is in error recovery
  9647. * or the HBA is undergoing initialization, the interrupt handler will not
  9648. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9649. * the intrrupt context. This function is called without any lock held.
  9650. * It gets the hbalock to access and update SLI data structures.
  9651. *
  9652. * This function returns IRQ_HANDLED when interrupt is handled else it
  9653. * returns IRQ_NONE.
  9654. **/
  9655. irqreturn_t
  9656. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9657. {
  9658. struct lpfc_hba *phba;
  9659. uint32_t ha_copy;
  9660. unsigned long status;
  9661. unsigned long iflag;
  9662. /* Get the driver's phba structure from the dev_id and
  9663. * assume the HBA is not interrupting.
  9664. */
  9665. phba = (struct lpfc_hba *) dev_id;
  9666. if (unlikely(!phba))
  9667. return IRQ_NONE;
  9668. /*
  9669. * Stuff needs to be attented to when this function is invoked as an
  9670. * individual interrupt handler in MSI-X multi-message interrupt mode
  9671. */
  9672. if (phba->intr_type == MSIX) {
  9673. /* Check device state for handling interrupt */
  9674. if (lpfc_intr_state_check(phba))
  9675. return IRQ_NONE;
  9676. /* Need to read HA REG for FCP ring and other ring events */
  9677. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9678. return IRQ_HANDLED;
  9679. /* Clear up only attention source related to fast-path */
  9680. spin_lock_irqsave(&phba->hbalock, iflag);
  9681. /*
  9682. * If there is deferred error attention, do not check for
  9683. * any interrupt.
  9684. */
  9685. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9686. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9687. return IRQ_NONE;
  9688. }
  9689. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9690. phba->HAregaddr);
  9691. readl(phba->HAregaddr); /* flush */
  9692. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9693. } else
  9694. ha_copy = phba->ha_copy;
  9695. /*
  9696. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9697. */
  9698. ha_copy &= ~(phba->work_ha_mask);
  9699. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9700. status >>= (4*LPFC_FCP_RING);
  9701. if (status & HA_RXMASK)
  9702. lpfc_sli_handle_fast_ring_event(phba,
  9703. &phba->sli.ring[LPFC_FCP_RING],
  9704. status);
  9705. if (phba->cfg_multi_ring_support == 2) {
  9706. /*
  9707. * Process all events on extra ring. Take the optimized path
  9708. * for extra ring IO.
  9709. */
  9710. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9711. status >>= (4*LPFC_EXTRA_RING);
  9712. if (status & HA_RXMASK) {
  9713. lpfc_sli_handle_fast_ring_event(phba,
  9714. &phba->sli.ring[LPFC_EXTRA_RING],
  9715. status);
  9716. }
  9717. }
  9718. return IRQ_HANDLED;
  9719. } /* lpfc_sli_fp_intr_handler */
  9720. /**
  9721. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9722. * @irq: Interrupt number.
  9723. * @dev_id: The device context pointer.
  9724. *
  9725. * This function is the HBA device-level interrupt handler to device with
  9726. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9727. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9728. * requires driver attention. This function invokes the slow-path interrupt
  9729. * attention handling function and fast-path interrupt attention handling
  9730. * function in turn to process the relevant HBA attention events. This
  9731. * function is called without any lock held. It gets the hbalock to access
  9732. * and update SLI data structures.
  9733. *
  9734. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9735. * returns IRQ_NONE.
  9736. **/
  9737. irqreturn_t
  9738. lpfc_sli_intr_handler(int irq, void *dev_id)
  9739. {
  9740. struct lpfc_hba *phba;
  9741. irqreturn_t sp_irq_rc, fp_irq_rc;
  9742. unsigned long status1, status2;
  9743. uint32_t hc_copy;
  9744. /*
  9745. * Get the driver's phba structure from the dev_id and
  9746. * assume the HBA is not interrupting.
  9747. */
  9748. phba = (struct lpfc_hba *) dev_id;
  9749. if (unlikely(!phba))
  9750. return IRQ_NONE;
  9751. /* Check device state for handling interrupt */
  9752. if (lpfc_intr_state_check(phba))
  9753. return IRQ_NONE;
  9754. spin_lock(&phba->hbalock);
  9755. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9756. spin_unlock(&phba->hbalock);
  9757. return IRQ_HANDLED;
  9758. }
  9759. if (unlikely(!phba->ha_copy)) {
  9760. spin_unlock(&phba->hbalock);
  9761. return IRQ_NONE;
  9762. } else if (phba->ha_copy & HA_ERATT) {
  9763. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9764. /* ERATT polling has handled ERATT */
  9765. phba->ha_copy &= ~HA_ERATT;
  9766. else
  9767. /* Indicate interrupt handler handles ERATT */
  9768. phba->hba_flag |= HBA_ERATT_HANDLED;
  9769. }
  9770. /*
  9771. * If there is deferred error attention, do not check for any interrupt.
  9772. */
  9773. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9774. spin_unlock(&phba->hbalock);
  9775. return IRQ_NONE;
  9776. }
  9777. /* Clear attention sources except link and error attentions */
  9778. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9779. spin_unlock(&phba->hbalock);
  9780. return IRQ_HANDLED;
  9781. }
  9782. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9783. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9784. phba->HCregaddr);
  9785. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9786. writel(hc_copy, phba->HCregaddr);
  9787. readl(phba->HAregaddr); /* flush */
  9788. spin_unlock(&phba->hbalock);
  9789. /*
  9790. * Invokes slow-path host attention interrupt handling as appropriate.
  9791. */
  9792. /* status of events with mailbox and link attention */
  9793. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9794. /* status of events with ELS ring */
  9795. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9796. status2 >>= (4*LPFC_ELS_RING);
  9797. if (status1 || (status2 & HA_RXMASK))
  9798. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9799. else
  9800. sp_irq_rc = IRQ_NONE;
  9801. /*
  9802. * Invoke fast-path host attention interrupt handling as appropriate.
  9803. */
  9804. /* status of events with FCP ring */
  9805. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9806. status1 >>= (4*LPFC_FCP_RING);
  9807. /* status of events with extra ring */
  9808. if (phba->cfg_multi_ring_support == 2) {
  9809. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9810. status2 >>= (4*LPFC_EXTRA_RING);
  9811. } else
  9812. status2 = 0;
  9813. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9814. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9815. else
  9816. fp_irq_rc = IRQ_NONE;
  9817. /* Return device-level interrupt handling status */
  9818. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9819. } /* lpfc_sli_intr_handler */
  9820. /**
  9821. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9822. * @phba: pointer to lpfc hba data structure.
  9823. *
  9824. * This routine is invoked by the worker thread to process all the pending
  9825. * SLI4 FCP abort XRI events.
  9826. **/
  9827. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9828. {
  9829. struct lpfc_cq_event *cq_event;
  9830. /* First, declare the fcp xri abort event has been handled */
  9831. spin_lock_irq(&phba->hbalock);
  9832. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9833. spin_unlock_irq(&phba->hbalock);
  9834. /* Now, handle all the fcp xri abort events */
  9835. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9836. /* Get the first event from the head of the event queue */
  9837. spin_lock_irq(&phba->hbalock);
  9838. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9839. cq_event, struct lpfc_cq_event, list);
  9840. spin_unlock_irq(&phba->hbalock);
  9841. /* Notify aborted XRI for FCP work queue */
  9842. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9843. /* Free the event processed back to the free pool */
  9844. lpfc_sli4_cq_event_release(phba, cq_event);
  9845. }
  9846. }
  9847. /**
  9848. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9849. * @phba: pointer to lpfc hba data structure.
  9850. *
  9851. * This routine is invoked by the worker thread to process all the pending
  9852. * SLI4 els abort xri events.
  9853. **/
  9854. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  9855. {
  9856. struct lpfc_cq_event *cq_event;
  9857. /* First, declare the els xri abort event has been handled */
  9858. spin_lock_irq(&phba->hbalock);
  9859. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  9860. spin_unlock_irq(&phba->hbalock);
  9861. /* Now, handle all the els xri abort events */
  9862. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  9863. /* Get the first event from the head of the event queue */
  9864. spin_lock_irq(&phba->hbalock);
  9865. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  9866. cq_event, struct lpfc_cq_event, list);
  9867. spin_unlock_irq(&phba->hbalock);
  9868. /* Notify aborted XRI for ELS work queue */
  9869. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9870. /* Free the event processed back to the free pool */
  9871. lpfc_sli4_cq_event_release(phba, cq_event);
  9872. }
  9873. }
  9874. /**
  9875. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  9876. * @phba: pointer to lpfc hba data structure
  9877. * @pIocbIn: pointer to the rspiocbq
  9878. * @pIocbOut: pointer to the cmdiocbq
  9879. * @wcqe: pointer to the complete wcqe
  9880. *
  9881. * This routine transfers the fields of a command iocbq to a response iocbq
  9882. * by copying all the IOCB fields from command iocbq and transferring the
  9883. * completion status information from the complete wcqe.
  9884. **/
  9885. static void
  9886. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  9887. struct lpfc_iocbq *pIocbIn,
  9888. struct lpfc_iocbq *pIocbOut,
  9889. struct lpfc_wcqe_complete *wcqe)
  9890. {
  9891. unsigned long iflags;
  9892. uint32_t status;
  9893. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  9894. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  9895. sizeof(struct lpfc_iocbq) - offset);
  9896. /* Map WCQE parameters into irspiocb parameters */
  9897. status = bf_get(lpfc_wcqe_c_status, wcqe);
  9898. pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
  9899. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  9900. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  9901. pIocbIn->iocb.un.fcpi.fcpi_parm =
  9902. pIocbOut->iocb.un.fcpi.fcpi_parm -
  9903. wcqe->total_data_placed;
  9904. else
  9905. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9906. else {
  9907. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9908. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  9909. }
  9910. /* Convert BG errors for completion status */
  9911. if (status == CQE_STATUS_DI_ERROR) {
  9912. pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  9913. if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
  9914. pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
  9915. else
  9916. pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
  9917. pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
  9918. if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
  9919. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9920. BGS_GUARD_ERR_MASK;
  9921. if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
  9922. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9923. BGS_APPTAG_ERR_MASK;
  9924. if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
  9925. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9926. BGS_REFTAG_ERR_MASK;
  9927. /* Check to see if there was any good data before the error */
  9928. if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
  9929. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9930. BGS_HI_WATER_MARK_PRESENT_MASK;
  9931. pIocbIn->iocb.unsli3.sli3_bg.bghm =
  9932. wcqe->total_data_placed;
  9933. }
  9934. /*
  9935. * Set ALL the error bits to indicate we don't know what
  9936. * type of error it is.
  9937. */
  9938. if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
  9939. pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
  9940. (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
  9941. BGS_GUARD_ERR_MASK);
  9942. }
  9943. /* Pick up HBA exchange busy condition */
  9944. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  9945. spin_lock_irqsave(&phba->hbalock, iflags);
  9946. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  9947. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9948. }
  9949. }
  9950. /**
  9951. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  9952. * @phba: Pointer to HBA context object.
  9953. * @wcqe: Pointer to work-queue completion queue entry.
  9954. *
  9955. * This routine handles an ELS work-queue completion event and construct
  9956. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  9957. * discovery engine to handle.
  9958. *
  9959. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  9960. **/
  9961. static struct lpfc_iocbq *
  9962. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  9963. struct lpfc_iocbq *irspiocbq)
  9964. {
  9965. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9966. struct lpfc_iocbq *cmdiocbq;
  9967. struct lpfc_wcqe_complete *wcqe;
  9968. unsigned long iflags;
  9969. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  9970. spin_lock_irqsave(&phba->hbalock, iflags);
  9971. pring->stats.iocb_event++;
  9972. /* Look up the ELS command IOCB and create pseudo response IOCB */
  9973. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  9974. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9975. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9976. if (unlikely(!cmdiocbq)) {
  9977. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9978. "0386 ELS complete with no corresponding "
  9979. "cmdiocb: iotag (%d)\n",
  9980. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9981. lpfc_sli_release_iocbq(phba, irspiocbq);
  9982. return NULL;
  9983. }
  9984. /* Fake the irspiocbq and copy necessary response information */
  9985. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  9986. return irspiocbq;
  9987. }
  9988. /**
  9989. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  9990. * @phba: Pointer to HBA context object.
  9991. * @cqe: Pointer to mailbox completion queue entry.
  9992. *
  9993. * This routine process a mailbox completion queue entry with asynchrous
  9994. * event.
  9995. *
  9996. * Return: true if work posted to worker thread, otherwise false.
  9997. **/
  9998. static bool
  9999. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10000. {
  10001. struct lpfc_cq_event *cq_event;
  10002. unsigned long iflags;
  10003. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10004. "0392 Async Event: word0:x%x, word1:x%x, "
  10005. "word2:x%x, word3:x%x\n", mcqe->word0,
  10006. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  10007. /* Allocate a new internal CQ_EVENT entry */
  10008. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10009. if (!cq_event) {
  10010. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10011. "0394 Failed to allocate CQ_EVENT entry\n");
  10012. return false;
  10013. }
  10014. /* Move the CQE into an asynchronous event entry */
  10015. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  10016. spin_lock_irqsave(&phba->hbalock, iflags);
  10017. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  10018. /* Set the async event flag */
  10019. phba->hba_flag |= ASYNC_EVENT;
  10020. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10021. return true;
  10022. }
  10023. /**
  10024. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  10025. * @phba: Pointer to HBA context object.
  10026. * @cqe: Pointer to mailbox completion queue entry.
  10027. *
  10028. * This routine process a mailbox completion queue entry with mailbox
  10029. * completion event.
  10030. *
  10031. * Return: true if work posted to worker thread, otherwise false.
  10032. **/
  10033. static bool
  10034. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  10035. {
  10036. uint32_t mcqe_status;
  10037. MAILBOX_t *mbox, *pmbox;
  10038. struct lpfc_mqe *mqe;
  10039. struct lpfc_vport *vport;
  10040. struct lpfc_nodelist *ndlp;
  10041. struct lpfc_dmabuf *mp;
  10042. unsigned long iflags;
  10043. LPFC_MBOXQ_t *pmb;
  10044. bool workposted = false;
  10045. int rc;
  10046. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  10047. if (!bf_get(lpfc_trailer_completed, mcqe))
  10048. goto out_no_mqe_complete;
  10049. /* Get the reference to the active mbox command */
  10050. spin_lock_irqsave(&phba->hbalock, iflags);
  10051. pmb = phba->sli.mbox_active;
  10052. if (unlikely(!pmb)) {
  10053. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  10054. "1832 No pending MBOX command to handle\n");
  10055. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10056. goto out_no_mqe_complete;
  10057. }
  10058. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10059. mqe = &pmb->u.mqe;
  10060. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  10061. mbox = phba->mbox;
  10062. vport = pmb->vport;
  10063. /* Reset heartbeat timer */
  10064. phba->last_completion_time = jiffies;
  10065. del_timer(&phba->sli.mbox_tmo);
  10066. /* Move mbox data to caller's mailbox region, do endian swapping */
  10067. if (pmb->mbox_cmpl && mbox)
  10068. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  10069. /*
  10070. * For mcqe errors, conditionally move a modified error code to
  10071. * the mbox so that the error will not be missed.
  10072. */
  10073. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  10074. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  10075. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  10076. bf_set(lpfc_mqe_status, mqe,
  10077. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  10078. }
  10079. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  10080. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  10081. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  10082. "MBOX dflt rpi: status:x%x rpi:x%x",
  10083. mcqe_status,
  10084. pmbox->un.varWords[0], 0);
  10085. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  10086. mp = (struct lpfc_dmabuf *)(pmb->context1);
  10087. ndlp = (struct lpfc_nodelist *)pmb->context2;
  10088. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  10089. * RID of the PPI using the same mbox buffer.
  10090. */
  10091. lpfc_unreg_login(phba, vport->vpi,
  10092. pmbox->un.varWords[0], pmb);
  10093. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  10094. pmb->context1 = mp;
  10095. pmb->context2 = ndlp;
  10096. pmb->vport = vport;
  10097. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  10098. if (rc != MBX_BUSY)
  10099. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  10100. LOG_SLI, "0385 rc should "
  10101. "have been MBX_BUSY\n");
  10102. if (rc != MBX_NOT_FINISHED)
  10103. goto send_current_mbox;
  10104. }
  10105. }
  10106. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10107. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10108. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10109. /* There is mailbox completion work to do */
  10110. spin_lock_irqsave(&phba->hbalock, iflags);
  10111. __lpfc_mbox_cmpl_put(phba, pmb);
  10112. phba->work_ha |= HA_MBATT;
  10113. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10114. workposted = true;
  10115. send_current_mbox:
  10116. spin_lock_irqsave(&phba->hbalock, iflags);
  10117. /* Release the mailbox command posting token */
  10118. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10119. /* Setting active mailbox pointer need to be in sync to flag clear */
  10120. phba->sli.mbox_active = NULL;
  10121. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10122. /* Wake up worker thread to post the next pending mailbox command */
  10123. lpfc_worker_wake_up(phba);
  10124. out_no_mqe_complete:
  10125. if (bf_get(lpfc_trailer_consumed, mcqe))
  10126. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  10127. return workposted;
  10128. }
  10129. /**
  10130. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  10131. * @phba: Pointer to HBA context object.
  10132. * @cqe: Pointer to mailbox completion queue entry.
  10133. *
  10134. * This routine process a mailbox completion queue entry, it invokes the
  10135. * proper mailbox complete handling or asynchrous event handling routine
  10136. * according to the MCQE's async bit.
  10137. *
  10138. * Return: true if work posted to worker thread, otherwise false.
  10139. **/
  10140. static bool
  10141. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  10142. {
  10143. struct lpfc_mcqe mcqe;
  10144. bool workposted;
  10145. /* Copy the mailbox MCQE and convert endian order as needed */
  10146. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  10147. /* Invoke the proper event handling routine */
  10148. if (!bf_get(lpfc_trailer_async, &mcqe))
  10149. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  10150. else
  10151. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  10152. return workposted;
  10153. }
  10154. /**
  10155. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  10156. * @phba: Pointer to HBA context object.
  10157. * @wcqe: Pointer to work-queue completion queue entry.
  10158. *
  10159. * This routine handles an ELS work-queue completion event.
  10160. *
  10161. * Return: true if work posted to worker thread, otherwise false.
  10162. **/
  10163. static bool
  10164. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  10165. struct lpfc_wcqe_complete *wcqe)
  10166. {
  10167. struct lpfc_iocbq *irspiocbq;
  10168. unsigned long iflags;
  10169. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  10170. /* Get an irspiocbq for later ELS response processing use */
  10171. irspiocbq = lpfc_sli_get_iocbq(phba);
  10172. if (!irspiocbq) {
  10173. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10174. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  10175. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  10176. pring->txq_cnt, phba->iocb_cnt,
  10177. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  10178. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  10179. return false;
  10180. }
  10181. /* Save off the slow-path queue event for work thread to process */
  10182. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  10183. spin_lock_irqsave(&phba->hbalock, iflags);
  10184. list_add_tail(&irspiocbq->cq_event.list,
  10185. &phba->sli4_hba.sp_queue_event);
  10186. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10187. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10188. return true;
  10189. }
  10190. /**
  10191. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  10192. * @phba: Pointer to HBA context object.
  10193. * @wcqe: Pointer to work-queue completion queue entry.
  10194. *
  10195. * This routine handles slow-path WQ entry comsumed event by invoking the
  10196. * proper WQ release routine to the slow-path WQ.
  10197. **/
  10198. static void
  10199. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  10200. struct lpfc_wcqe_release *wcqe)
  10201. {
  10202. /* sanity check on queue memory */
  10203. if (unlikely(!phba->sli4_hba.els_wq))
  10204. return;
  10205. /* Check for the slow-path ELS work queue */
  10206. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10207. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10208. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10209. else
  10210. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10211. "2579 Slow-path wqe consume event carries "
  10212. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10213. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10214. phba->sli4_hba.els_wq->queue_id);
  10215. }
  10216. /**
  10217. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10218. * @phba: Pointer to HBA context object.
  10219. * @cq: Pointer to a WQ completion queue.
  10220. * @wcqe: Pointer to work-queue completion queue entry.
  10221. *
  10222. * This routine handles an XRI abort event.
  10223. *
  10224. * Return: true if work posted to worker thread, otherwise false.
  10225. **/
  10226. static bool
  10227. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10228. struct lpfc_queue *cq,
  10229. struct sli4_wcqe_xri_aborted *wcqe)
  10230. {
  10231. bool workposted = false;
  10232. struct lpfc_cq_event *cq_event;
  10233. unsigned long iflags;
  10234. /* Allocate a new internal CQ_EVENT entry */
  10235. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10236. if (!cq_event) {
  10237. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10238. "0602 Failed to allocate CQ_EVENT entry\n");
  10239. return false;
  10240. }
  10241. /* Move the CQE into the proper xri abort event list */
  10242. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10243. switch (cq->subtype) {
  10244. case LPFC_FCP:
  10245. spin_lock_irqsave(&phba->hbalock, iflags);
  10246. list_add_tail(&cq_event->list,
  10247. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10248. /* Set the fcp xri abort event flag */
  10249. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10250. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10251. workposted = true;
  10252. break;
  10253. case LPFC_ELS:
  10254. spin_lock_irqsave(&phba->hbalock, iflags);
  10255. list_add_tail(&cq_event->list,
  10256. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10257. /* Set the els xri abort event flag */
  10258. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10259. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10260. workposted = true;
  10261. break;
  10262. default:
  10263. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10264. "0603 Invalid work queue CQE subtype (x%x)\n",
  10265. cq->subtype);
  10266. workposted = false;
  10267. break;
  10268. }
  10269. return workposted;
  10270. }
  10271. /**
  10272. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10273. * @phba: Pointer to HBA context object.
  10274. * @rcqe: Pointer to receive-queue completion queue entry.
  10275. *
  10276. * This routine process a receive-queue completion queue entry.
  10277. *
  10278. * Return: true if work posted to worker thread, otherwise false.
  10279. **/
  10280. static bool
  10281. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10282. {
  10283. bool workposted = false;
  10284. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10285. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10286. struct hbq_dmabuf *dma_buf;
  10287. uint32_t status, rq_id;
  10288. unsigned long iflags;
  10289. /* sanity check on queue memory */
  10290. if (unlikely(!hrq) || unlikely(!drq))
  10291. return workposted;
  10292. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10293. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10294. else
  10295. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10296. if (rq_id != hrq->queue_id)
  10297. goto out;
  10298. status = bf_get(lpfc_rcqe_status, rcqe);
  10299. switch (status) {
  10300. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10301. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10302. "2537 Receive Frame Truncated!!\n");
  10303. case FC_STATUS_RQ_SUCCESS:
  10304. lpfc_sli4_rq_release(hrq, drq);
  10305. spin_lock_irqsave(&phba->hbalock, iflags);
  10306. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10307. if (!dma_buf) {
  10308. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10309. goto out;
  10310. }
  10311. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10312. /* save off the frame for the word thread to process */
  10313. list_add_tail(&dma_buf->cq_event.list,
  10314. &phba->sli4_hba.sp_queue_event);
  10315. /* Frame received */
  10316. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10317. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10318. workposted = true;
  10319. break;
  10320. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10321. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10322. /* Post more buffers if possible */
  10323. spin_lock_irqsave(&phba->hbalock, iflags);
  10324. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10325. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10326. workposted = true;
  10327. break;
  10328. }
  10329. out:
  10330. return workposted;
  10331. }
  10332. /**
  10333. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10334. * @phba: Pointer to HBA context object.
  10335. * @cq: Pointer to the completion queue.
  10336. * @wcqe: Pointer to a completion queue entry.
  10337. *
  10338. * This routine process a slow-path work-queue or receive queue completion queue
  10339. * entry.
  10340. *
  10341. * Return: true if work posted to worker thread, otherwise false.
  10342. **/
  10343. static bool
  10344. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10345. struct lpfc_cqe *cqe)
  10346. {
  10347. struct lpfc_cqe cqevt;
  10348. bool workposted = false;
  10349. /* Copy the work queue CQE and convert endian order if needed */
  10350. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10351. /* Check and process for different type of WCQE and dispatch */
  10352. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10353. case CQE_CODE_COMPL_WQE:
  10354. /* Process the WQ/RQ complete event */
  10355. phba->last_completion_time = jiffies;
  10356. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  10357. (struct lpfc_wcqe_complete *)&cqevt);
  10358. break;
  10359. case CQE_CODE_RELEASE_WQE:
  10360. /* Process the WQ release event */
  10361. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10362. (struct lpfc_wcqe_release *)&cqevt);
  10363. break;
  10364. case CQE_CODE_XRI_ABORTED:
  10365. /* Process the WQ XRI abort event */
  10366. phba->last_completion_time = jiffies;
  10367. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10368. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10369. break;
  10370. case CQE_CODE_RECEIVE:
  10371. case CQE_CODE_RECEIVE_V1:
  10372. /* Process the RQ event */
  10373. phba->last_completion_time = jiffies;
  10374. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10375. (struct lpfc_rcqe *)&cqevt);
  10376. break;
  10377. default:
  10378. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10379. "0388 Not a valid WCQE code: x%x\n",
  10380. bf_get(lpfc_cqe_code, &cqevt));
  10381. break;
  10382. }
  10383. return workposted;
  10384. }
  10385. /**
  10386. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10387. * @phba: Pointer to HBA context object.
  10388. * @eqe: Pointer to fast-path event queue entry.
  10389. *
  10390. * This routine process a event queue entry from the slow-path event queue.
  10391. * It will check the MajorCode and MinorCode to determine this is for a
  10392. * completion event on a completion queue, if not, an error shall be logged
  10393. * and just return. Otherwise, it will get to the corresponding completion
  10394. * queue and process all the entries on that completion queue, rearm the
  10395. * completion queue, and then return.
  10396. *
  10397. **/
  10398. static void
  10399. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  10400. {
  10401. struct lpfc_queue *cq = NULL, *childq, *speq;
  10402. struct lpfc_cqe *cqe;
  10403. bool workposted = false;
  10404. int ecount = 0;
  10405. uint16_t cqid;
  10406. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  10407. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10408. "0359 Not a valid slow-path completion "
  10409. "event: majorcode=x%x, minorcode=x%x\n",
  10410. bf_get_le32(lpfc_eqe_major_code, eqe),
  10411. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10412. return;
  10413. }
  10414. /* Get the reference to the corresponding CQ */
  10415. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10416. /* Search for completion queue pointer matching this cqid */
  10417. speq = phba->sli4_hba.sp_eq;
  10418. /* sanity check on queue memory */
  10419. if (unlikely(!speq))
  10420. return;
  10421. list_for_each_entry(childq, &speq->child_list, list) {
  10422. if (childq->queue_id == cqid) {
  10423. cq = childq;
  10424. break;
  10425. }
  10426. }
  10427. if (unlikely(!cq)) {
  10428. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10429. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10430. "0365 Slow-path CQ identifier "
  10431. "(%d) does not exist\n", cqid);
  10432. return;
  10433. }
  10434. /* Process all the entries to the CQ */
  10435. switch (cq->type) {
  10436. case LPFC_MCQ:
  10437. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10438. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10439. if (!(++ecount % cq->entry_repost))
  10440. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10441. }
  10442. break;
  10443. case LPFC_WCQ:
  10444. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10445. if (cq->subtype == LPFC_FCP)
  10446. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10447. cqe);
  10448. else
  10449. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10450. cqe);
  10451. if (!(++ecount % cq->entry_repost))
  10452. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10453. }
  10454. break;
  10455. default:
  10456. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10457. "0370 Invalid completion queue type (%d)\n",
  10458. cq->type);
  10459. return;
  10460. }
  10461. /* Catch the no cq entry condition, log an error */
  10462. if (unlikely(ecount == 0))
  10463. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10464. "0371 No entry from the CQ: identifier "
  10465. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10466. /* In any case, flash and re-arm the RCQ */
  10467. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10468. /* wake up worker thread if there are works to be done */
  10469. if (workposted)
  10470. lpfc_worker_wake_up(phba);
  10471. }
  10472. /**
  10473. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10474. * @eqe: Pointer to fast-path completion queue entry.
  10475. *
  10476. * This routine process a fast-path work queue completion entry from fast-path
  10477. * event queue for FCP command response completion.
  10478. **/
  10479. static void
  10480. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  10481. struct lpfc_wcqe_complete *wcqe)
  10482. {
  10483. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  10484. struct lpfc_iocbq *cmdiocbq;
  10485. struct lpfc_iocbq irspiocbq;
  10486. unsigned long iflags;
  10487. spin_lock_irqsave(&phba->hbalock, iflags);
  10488. pring->stats.iocb_event++;
  10489. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10490. /* Check for response status */
  10491. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10492. /* If resource errors reported from HBA, reduce queue
  10493. * depth of the SCSI device.
  10494. */
  10495. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10496. IOSTAT_LOCAL_REJECT) &&
  10497. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  10498. phba->lpfc_rampdown_queue_depth(phba);
  10499. }
  10500. /* Log the error status */
  10501. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10502. "0373 FCP complete error: status=x%x, "
  10503. "hw_status=x%x, total_data_specified=%d, "
  10504. "parameter=x%x, word3=x%x\n",
  10505. bf_get(lpfc_wcqe_c_status, wcqe),
  10506. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10507. wcqe->total_data_placed, wcqe->parameter,
  10508. wcqe->word3);
  10509. }
  10510. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10511. spin_lock_irqsave(&phba->hbalock, iflags);
  10512. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10513. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10514. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10515. if (unlikely(!cmdiocbq)) {
  10516. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10517. "0374 FCP complete with no corresponding "
  10518. "cmdiocb: iotag (%d)\n",
  10519. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10520. return;
  10521. }
  10522. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10523. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10524. "0375 FCP cmdiocb not callback function "
  10525. "iotag: (%d)\n",
  10526. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10527. return;
  10528. }
  10529. /* Fake the irspiocb and copy necessary response information */
  10530. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10531. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10532. spin_lock_irqsave(&phba->hbalock, iflags);
  10533. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10534. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10535. }
  10536. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10537. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10538. }
  10539. /**
  10540. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10541. * @phba: Pointer to HBA context object.
  10542. * @cq: Pointer to completion queue.
  10543. * @wcqe: Pointer to work-queue completion queue entry.
  10544. *
  10545. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10546. * proper WQ release routine to the slow-path WQ.
  10547. **/
  10548. static void
  10549. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10550. struct lpfc_wcqe_release *wcqe)
  10551. {
  10552. struct lpfc_queue *childwq;
  10553. bool wqid_matched = false;
  10554. uint16_t fcp_wqid;
  10555. /* Check for fast-path FCP work queue release */
  10556. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10557. list_for_each_entry(childwq, &cq->child_list, list) {
  10558. if (childwq->queue_id == fcp_wqid) {
  10559. lpfc_sli4_wq_release(childwq,
  10560. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10561. wqid_matched = true;
  10562. break;
  10563. }
  10564. }
  10565. /* Report warning log message if no match found */
  10566. if (wqid_matched != true)
  10567. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10568. "2580 Fast-path wqe consume event carries "
  10569. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10570. }
  10571. /**
  10572. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10573. * @cq: Pointer to the completion queue.
  10574. * @eqe: Pointer to fast-path completion queue entry.
  10575. *
  10576. * This routine process a fast-path work queue completion entry from fast-path
  10577. * event queue for FCP command response completion.
  10578. **/
  10579. static int
  10580. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10581. struct lpfc_cqe *cqe)
  10582. {
  10583. struct lpfc_wcqe_release wcqe;
  10584. bool workposted = false;
  10585. /* Copy the work queue CQE and convert endian order if needed */
  10586. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10587. /* Check and process for different type of WCQE and dispatch */
  10588. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10589. case CQE_CODE_COMPL_WQE:
  10590. /* Process the WQ complete event */
  10591. phba->last_completion_time = jiffies;
  10592. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  10593. (struct lpfc_wcqe_complete *)&wcqe);
  10594. break;
  10595. case CQE_CODE_RELEASE_WQE:
  10596. /* Process the WQ release event */
  10597. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10598. (struct lpfc_wcqe_release *)&wcqe);
  10599. break;
  10600. case CQE_CODE_XRI_ABORTED:
  10601. /* Process the WQ XRI abort event */
  10602. phba->last_completion_time = jiffies;
  10603. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10604. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10605. break;
  10606. default:
  10607. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10608. "0144 Not a valid WCQE code: x%x\n",
  10609. bf_get(lpfc_wcqe_c_code, &wcqe));
  10610. break;
  10611. }
  10612. return workposted;
  10613. }
  10614. /**
  10615. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  10616. * @phba: Pointer to HBA context object.
  10617. * @eqe: Pointer to fast-path event queue entry.
  10618. *
  10619. * This routine process a event queue entry from the fast-path event queue.
  10620. * It will check the MajorCode and MinorCode to determine this is for a
  10621. * completion event on a completion queue, if not, an error shall be logged
  10622. * and just return. Otherwise, it will get to the corresponding completion
  10623. * queue and process all the entries on the completion queue, rearm the
  10624. * completion queue, and then return.
  10625. **/
  10626. static void
  10627. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10628. uint32_t fcp_cqidx)
  10629. {
  10630. struct lpfc_queue *cq;
  10631. struct lpfc_cqe *cqe;
  10632. bool workposted = false;
  10633. uint16_t cqid;
  10634. int ecount = 0;
  10635. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10636. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10637. "0366 Not a valid fast-path completion "
  10638. "event: majorcode=x%x, minorcode=x%x\n",
  10639. bf_get_le32(lpfc_eqe_major_code, eqe),
  10640. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10641. return;
  10642. }
  10643. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  10644. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10645. "3146 Fast-path completion queues "
  10646. "does not exist\n");
  10647. return;
  10648. }
  10649. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  10650. if (unlikely(!cq)) {
  10651. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10652. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10653. "0367 Fast-path completion queue "
  10654. "(%d) does not exist\n", fcp_cqidx);
  10655. return;
  10656. }
  10657. /* Get the reference to the corresponding CQ */
  10658. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10659. if (unlikely(cqid != cq->queue_id)) {
  10660. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10661. "0368 Miss-matched fast-path completion "
  10662. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10663. cqid, cq->queue_id);
  10664. return;
  10665. }
  10666. /* Process all the entries to the CQ */
  10667. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10668. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10669. if (!(++ecount % cq->entry_repost))
  10670. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10671. }
  10672. /* Catch the no cq entry condition */
  10673. if (unlikely(ecount == 0))
  10674. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10675. "0369 No entry from fast-path completion "
  10676. "queue fcpcqid=%d\n", cq->queue_id);
  10677. /* In any case, flash and re-arm the CQ */
  10678. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10679. /* wake up worker thread if there are works to be done */
  10680. if (workposted)
  10681. lpfc_worker_wake_up(phba);
  10682. }
  10683. static void
  10684. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10685. {
  10686. struct lpfc_eqe *eqe;
  10687. /* walk all the EQ entries and drop on the floor */
  10688. while ((eqe = lpfc_sli4_eq_get(eq)))
  10689. ;
  10690. /* Clear and re-arm the EQ */
  10691. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10692. }
  10693. /**
  10694. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  10695. * @irq: Interrupt number.
  10696. * @dev_id: The device context pointer.
  10697. *
  10698. * This function is directly called from the PCI layer as an interrupt
  10699. * service routine when device with SLI-4 interface spec is enabled with
  10700. * MSI-X multi-message interrupt mode and there are slow-path events in
  10701. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  10702. * interrupt mode, this function is called as part of the device-level
  10703. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  10704. * undergoing initialization, the interrupt handler will not process the
  10705. * interrupt. The link attention and ELS ring attention events are handled
  10706. * by the worker thread. The interrupt handler signals the worker thread
  10707. * and returns for these events. This function is called without any lock
  10708. * held. It gets the hbalock to access and update SLI data structures.
  10709. *
  10710. * This function returns IRQ_HANDLED when interrupt is handled else it
  10711. * returns IRQ_NONE.
  10712. **/
  10713. irqreturn_t
  10714. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  10715. {
  10716. struct lpfc_hba *phba;
  10717. struct lpfc_queue *speq;
  10718. struct lpfc_eqe *eqe;
  10719. unsigned long iflag;
  10720. int ecount = 0;
  10721. /*
  10722. * Get the driver's phba structure from the dev_id
  10723. */
  10724. phba = (struct lpfc_hba *)dev_id;
  10725. if (unlikely(!phba))
  10726. return IRQ_NONE;
  10727. /* Get to the EQ struct associated with this vector */
  10728. speq = phba->sli4_hba.sp_eq;
  10729. if (unlikely(!speq))
  10730. return IRQ_NONE;
  10731. /* Check device state for handling interrupt */
  10732. if (unlikely(lpfc_intr_state_check(phba))) {
  10733. /* Check again for link_state with lock held */
  10734. spin_lock_irqsave(&phba->hbalock, iflag);
  10735. if (phba->link_state < LPFC_LINK_DOWN)
  10736. /* Flush, clear interrupt, and rearm the EQ */
  10737. lpfc_sli4_eq_flush(phba, speq);
  10738. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10739. return IRQ_NONE;
  10740. }
  10741. /*
  10742. * Process all the event on FCP slow-path EQ
  10743. */
  10744. while ((eqe = lpfc_sli4_eq_get(speq))) {
  10745. lpfc_sli4_sp_handle_eqe(phba, eqe);
  10746. if (!(++ecount % speq->entry_repost))
  10747. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  10748. }
  10749. /* Always clear and re-arm the slow-path EQ */
  10750. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  10751. /* Catch the no cq entry condition */
  10752. if (unlikely(ecount == 0)) {
  10753. if (phba->intr_type == MSIX)
  10754. /* MSI-X treated interrupt served as no EQ share INT */
  10755. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10756. "0357 MSI-X interrupt with no EQE\n");
  10757. else
  10758. /* Non MSI-X treated on interrupt as EQ share INT */
  10759. return IRQ_NONE;
  10760. }
  10761. return IRQ_HANDLED;
  10762. } /* lpfc_sli4_sp_intr_handler */
  10763. /**
  10764. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  10765. * @irq: Interrupt number.
  10766. * @dev_id: The device context pointer.
  10767. *
  10768. * This function is directly called from the PCI layer as an interrupt
  10769. * service routine when device with SLI-4 interface spec is enabled with
  10770. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10771. * ring event in the HBA. However, when the device is enabled with either
  10772. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10773. * device-level interrupt handler. When the PCI slot is in error recovery
  10774. * or the HBA is undergoing initialization, the interrupt handler will not
  10775. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10776. * the intrrupt context. This function is called without any lock held.
  10777. * It gets the hbalock to access and update SLI data structures. Note that,
  10778. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10779. * equal to that of FCP CQ index.
  10780. *
  10781. * This function returns IRQ_HANDLED when interrupt is handled else it
  10782. * returns IRQ_NONE.
  10783. **/
  10784. irqreturn_t
  10785. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  10786. {
  10787. struct lpfc_hba *phba;
  10788. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10789. struct lpfc_queue *fpeq;
  10790. struct lpfc_eqe *eqe;
  10791. unsigned long iflag;
  10792. int ecount = 0;
  10793. uint32_t fcp_eqidx;
  10794. /* Get the driver's phba structure from the dev_id */
  10795. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10796. phba = fcp_eq_hdl->phba;
  10797. fcp_eqidx = fcp_eq_hdl->idx;
  10798. if (unlikely(!phba))
  10799. return IRQ_NONE;
  10800. if (unlikely(!phba->sli4_hba.fp_eq))
  10801. return IRQ_NONE;
  10802. /* Get to the EQ struct associated with this vector */
  10803. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  10804. if (unlikely(!fpeq))
  10805. return IRQ_NONE;
  10806. /* Check device state for handling interrupt */
  10807. if (unlikely(lpfc_intr_state_check(phba))) {
  10808. /* Check again for link_state with lock held */
  10809. spin_lock_irqsave(&phba->hbalock, iflag);
  10810. if (phba->link_state < LPFC_LINK_DOWN)
  10811. /* Flush, clear interrupt, and rearm the EQ */
  10812. lpfc_sli4_eq_flush(phba, fpeq);
  10813. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10814. return IRQ_NONE;
  10815. }
  10816. /*
  10817. * Process all the event on FCP fast-path EQ
  10818. */
  10819. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10820. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  10821. if (!(++ecount % fpeq->entry_repost))
  10822. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10823. }
  10824. /* Always clear and re-arm the fast-path EQ */
  10825. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  10826. if (unlikely(ecount == 0)) {
  10827. if (phba->intr_type == MSIX)
  10828. /* MSI-X treated interrupt served as no EQ share INT */
  10829. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10830. "0358 MSI-X interrupt with no EQE\n");
  10831. else
  10832. /* Non MSI-X treated on interrupt as EQ share INT */
  10833. return IRQ_NONE;
  10834. }
  10835. return IRQ_HANDLED;
  10836. } /* lpfc_sli4_fp_intr_handler */
  10837. /**
  10838. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10839. * @irq: Interrupt number.
  10840. * @dev_id: The device context pointer.
  10841. *
  10842. * This function is the device-level interrupt handler to device with SLI-4
  10843. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10844. * interrupt mode is enabled and there is an event in the HBA which requires
  10845. * driver attention. This function invokes the slow-path interrupt attention
  10846. * handling function and fast-path interrupt attention handling function in
  10847. * turn to process the relevant HBA attention events. This function is called
  10848. * without any lock held. It gets the hbalock to access and update SLI data
  10849. * structures.
  10850. *
  10851. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10852. * returns IRQ_NONE.
  10853. **/
  10854. irqreturn_t
  10855. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10856. {
  10857. struct lpfc_hba *phba;
  10858. irqreturn_t sp_irq_rc, fp_irq_rc;
  10859. bool fp_handled = false;
  10860. uint32_t fcp_eqidx;
  10861. /* Get the driver's phba structure from the dev_id */
  10862. phba = (struct lpfc_hba *)dev_id;
  10863. if (unlikely(!phba))
  10864. return IRQ_NONE;
  10865. /*
  10866. * Invokes slow-path host attention interrupt handling as appropriate.
  10867. */
  10868. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  10869. /*
  10870. * Invoke fast-path host attention interrupt handling as appropriate.
  10871. */
  10872. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  10873. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  10874. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10875. if (fp_irq_rc == IRQ_HANDLED)
  10876. fp_handled |= true;
  10877. }
  10878. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  10879. } /* lpfc_sli4_intr_handler */
  10880. /**
  10881. * lpfc_sli4_queue_free - free a queue structure and associated memory
  10882. * @queue: The queue structure to free.
  10883. *
  10884. * This function frees a queue structure and the DMAable memory used for
  10885. * the host resident queue. This function must be called after destroying the
  10886. * queue on the HBA.
  10887. **/
  10888. void
  10889. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  10890. {
  10891. struct lpfc_dmabuf *dmabuf;
  10892. if (!queue)
  10893. return;
  10894. while (!list_empty(&queue->page_list)) {
  10895. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  10896. list);
  10897. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  10898. dmabuf->virt, dmabuf->phys);
  10899. kfree(dmabuf);
  10900. }
  10901. kfree(queue);
  10902. return;
  10903. }
  10904. /**
  10905. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  10906. * @phba: The HBA that this queue is being created on.
  10907. * @entry_size: The size of each queue entry for this queue.
  10908. * @entry count: The number of entries that this queue will handle.
  10909. *
  10910. * This function allocates a queue structure and the DMAable memory used for
  10911. * the host resident queue. This function must be called before creating the
  10912. * queue on the HBA.
  10913. **/
  10914. struct lpfc_queue *
  10915. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  10916. uint32_t entry_count)
  10917. {
  10918. struct lpfc_queue *queue;
  10919. struct lpfc_dmabuf *dmabuf;
  10920. int x, total_qe_count;
  10921. void *dma_pointer;
  10922. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10923. if (!phba->sli4_hba.pc_sli4_params.supported)
  10924. hw_page_size = SLI4_PAGE_SIZE;
  10925. queue = kzalloc(sizeof(struct lpfc_queue) +
  10926. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  10927. if (!queue)
  10928. return NULL;
  10929. queue->page_count = (ALIGN(entry_size * entry_count,
  10930. hw_page_size))/hw_page_size;
  10931. INIT_LIST_HEAD(&queue->list);
  10932. INIT_LIST_HEAD(&queue->page_list);
  10933. INIT_LIST_HEAD(&queue->child_list);
  10934. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  10935. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  10936. if (!dmabuf)
  10937. goto out_fail;
  10938. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  10939. hw_page_size, &dmabuf->phys,
  10940. GFP_KERNEL);
  10941. if (!dmabuf->virt) {
  10942. kfree(dmabuf);
  10943. goto out_fail;
  10944. }
  10945. memset(dmabuf->virt, 0, hw_page_size);
  10946. dmabuf->buffer_tag = x;
  10947. list_add_tail(&dmabuf->list, &queue->page_list);
  10948. /* initialize queue's entry array */
  10949. dma_pointer = dmabuf->virt;
  10950. for (; total_qe_count < entry_count &&
  10951. dma_pointer < (hw_page_size + dmabuf->virt);
  10952. total_qe_count++, dma_pointer += entry_size) {
  10953. queue->qe[total_qe_count].address = dma_pointer;
  10954. }
  10955. }
  10956. queue->entry_size = entry_size;
  10957. queue->entry_count = entry_count;
  10958. /*
  10959. * entry_repost is calculated based on the number of entries in the
  10960. * queue. This works out except for RQs. If buffers are NOT initially
  10961. * posted for every RQE, entry_repost should be adjusted accordingly.
  10962. */
  10963. queue->entry_repost = (entry_count >> 3);
  10964. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  10965. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  10966. queue->phba = phba;
  10967. return queue;
  10968. out_fail:
  10969. lpfc_sli4_queue_free(queue);
  10970. return NULL;
  10971. }
  10972. /**
  10973. * lpfc_eq_create - Create an Event Queue on the HBA
  10974. * @phba: HBA structure that indicates port to create a queue on.
  10975. * @eq: The queue structure to use to create the event queue.
  10976. * @imax: The maximum interrupt per second limit.
  10977. *
  10978. * This function creates an event queue, as detailed in @eq, on a port,
  10979. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  10980. *
  10981. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  10982. * is used to get the entry count and entry size that are necessary to
  10983. * determine the number of pages to allocate and use for this queue. This
  10984. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  10985. * event queue. This function is asynchronous and will wait for the mailbox
  10986. * command to finish before continuing.
  10987. *
  10988. * On success this function will return a zero. If unable to allocate enough
  10989. * memory this function will return -ENOMEM. If the queue create mailbox command
  10990. * fails this function will return -ENXIO.
  10991. **/
  10992. uint32_t
  10993. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  10994. {
  10995. struct lpfc_mbx_eq_create *eq_create;
  10996. LPFC_MBOXQ_t *mbox;
  10997. int rc, length, status = 0;
  10998. struct lpfc_dmabuf *dmabuf;
  10999. uint32_t shdr_status, shdr_add_status;
  11000. union lpfc_sli4_cfg_shdr *shdr;
  11001. uint16_t dmult;
  11002. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11003. /* sanity check on queue memory */
  11004. if (!eq)
  11005. return -ENODEV;
  11006. if (!phba->sli4_hba.pc_sli4_params.supported)
  11007. hw_page_size = SLI4_PAGE_SIZE;
  11008. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11009. if (!mbox)
  11010. return -ENOMEM;
  11011. length = (sizeof(struct lpfc_mbx_eq_create) -
  11012. sizeof(struct lpfc_sli4_cfg_mhdr));
  11013. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11014. LPFC_MBOX_OPCODE_EQ_CREATE,
  11015. length, LPFC_SLI4_MBX_EMBED);
  11016. eq_create = &mbox->u.mqe.un.eq_create;
  11017. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  11018. eq->page_count);
  11019. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  11020. LPFC_EQE_SIZE);
  11021. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  11022. /* Calculate delay multiper from maximum interrupt per second */
  11023. dmult = LPFC_DMULT_CONST/imax - 1;
  11024. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  11025. dmult);
  11026. switch (eq->entry_count) {
  11027. default:
  11028. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11029. "0360 Unsupported EQ count. (%d)\n",
  11030. eq->entry_count);
  11031. if (eq->entry_count < 256)
  11032. return -EINVAL;
  11033. /* otherwise default to smallest count (drop through) */
  11034. case 256:
  11035. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11036. LPFC_EQ_CNT_256);
  11037. break;
  11038. case 512:
  11039. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11040. LPFC_EQ_CNT_512);
  11041. break;
  11042. case 1024:
  11043. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11044. LPFC_EQ_CNT_1024);
  11045. break;
  11046. case 2048:
  11047. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11048. LPFC_EQ_CNT_2048);
  11049. break;
  11050. case 4096:
  11051. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  11052. LPFC_EQ_CNT_4096);
  11053. break;
  11054. }
  11055. list_for_each_entry(dmabuf, &eq->page_list, list) {
  11056. memset(dmabuf->virt, 0, hw_page_size);
  11057. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11058. putPaddrLow(dmabuf->phys);
  11059. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11060. putPaddrHigh(dmabuf->phys);
  11061. }
  11062. mbox->vport = phba->pport;
  11063. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11064. mbox->context1 = NULL;
  11065. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11066. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  11067. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11068. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11069. if (shdr_status || shdr_add_status || rc) {
  11070. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11071. "2500 EQ_CREATE mailbox failed with "
  11072. "status x%x add_status x%x, mbx status x%x\n",
  11073. shdr_status, shdr_add_status, rc);
  11074. status = -ENXIO;
  11075. }
  11076. eq->type = LPFC_EQ;
  11077. eq->subtype = LPFC_NONE;
  11078. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  11079. if (eq->queue_id == 0xFFFF)
  11080. status = -ENXIO;
  11081. eq->host_index = 0;
  11082. eq->hba_index = 0;
  11083. mempool_free(mbox, phba->mbox_mem_pool);
  11084. return status;
  11085. }
  11086. /**
  11087. * lpfc_cq_create - Create a Completion Queue on the HBA
  11088. * @phba: HBA structure that indicates port to create a queue on.
  11089. * @cq: The queue structure to use to create the completion queue.
  11090. * @eq: The event queue to bind this completion queue to.
  11091. *
  11092. * This function creates a completion queue, as detailed in @wq, on a port,
  11093. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  11094. *
  11095. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11096. * is used to get the entry count and entry size that are necessary to
  11097. * determine the number of pages to allocate and use for this queue. The @eq
  11098. * is used to indicate which event queue to bind this completion queue to. This
  11099. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  11100. * completion queue. This function is asynchronous and will wait for the mailbox
  11101. * command to finish before continuing.
  11102. *
  11103. * On success this function will return a zero. If unable to allocate enough
  11104. * memory this function will return -ENOMEM. If the queue create mailbox command
  11105. * fails this function will return -ENXIO.
  11106. **/
  11107. uint32_t
  11108. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  11109. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  11110. {
  11111. struct lpfc_mbx_cq_create *cq_create;
  11112. struct lpfc_dmabuf *dmabuf;
  11113. LPFC_MBOXQ_t *mbox;
  11114. int rc, length, status = 0;
  11115. uint32_t shdr_status, shdr_add_status;
  11116. union lpfc_sli4_cfg_shdr *shdr;
  11117. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11118. /* sanity check on queue memory */
  11119. if (!cq || !eq)
  11120. return -ENODEV;
  11121. if (!phba->sli4_hba.pc_sli4_params.supported)
  11122. hw_page_size = SLI4_PAGE_SIZE;
  11123. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11124. if (!mbox)
  11125. return -ENOMEM;
  11126. length = (sizeof(struct lpfc_mbx_cq_create) -
  11127. sizeof(struct lpfc_sli4_cfg_mhdr));
  11128. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11129. LPFC_MBOX_OPCODE_CQ_CREATE,
  11130. length, LPFC_SLI4_MBX_EMBED);
  11131. cq_create = &mbox->u.mqe.un.cq_create;
  11132. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  11133. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  11134. cq->page_count);
  11135. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  11136. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  11137. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11138. phba->sli4_hba.pc_sli4_params.cqv);
  11139. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  11140. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  11141. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  11142. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  11143. eq->queue_id);
  11144. } else {
  11145. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  11146. eq->queue_id);
  11147. }
  11148. switch (cq->entry_count) {
  11149. default:
  11150. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11151. "0361 Unsupported CQ count. (%d)\n",
  11152. cq->entry_count);
  11153. if (cq->entry_count < 256)
  11154. return -EINVAL;
  11155. /* otherwise default to smallest count (drop through) */
  11156. case 256:
  11157. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11158. LPFC_CQ_CNT_256);
  11159. break;
  11160. case 512:
  11161. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11162. LPFC_CQ_CNT_512);
  11163. break;
  11164. case 1024:
  11165. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  11166. LPFC_CQ_CNT_1024);
  11167. break;
  11168. }
  11169. list_for_each_entry(dmabuf, &cq->page_list, list) {
  11170. memset(dmabuf->virt, 0, hw_page_size);
  11171. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11172. putPaddrLow(dmabuf->phys);
  11173. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11174. putPaddrHigh(dmabuf->phys);
  11175. }
  11176. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11177. /* The IOCTL status is embedded in the mailbox subheader. */
  11178. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11179. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11180. if (shdr_status || shdr_add_status || rc) {
  11181. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11182. "2501 CQ_CREATE mailbox failed with "
  11183. "status x%x add_status x%x, mbx status x%x\n",
  11184. shdr_status, shdr_add_status, rc);
  11185. status = -ENXIO;
  11186. goto out;
  11187. }
  11188. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11189. if (cq->queue_id == 0xFFFF) {
  11190. status = -ENXIO;
  11191. goto out;
  11192. }
  11193. /* link the cq onto the parent eq child list */
  11194. list_add_tail(&cq->list, &eq->child_list);
  11195. /* Set up completion queue's type and subtype */
  11196. cq->type = type;
  11197. cq->subtype = subtype;
  11198. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  11199. cq->assoc_qid = eq->queue_id;
  11200. cq->host_index = 0;
  11201. cq->hba_index = 0;
  11202. out:
  11203. mempool_free(mbox, phba->mbox_mem_pool);
  11204. return status;
  11205. }
  11206. /**
  11207. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  11208. * @phba: HBA structure that indicates port to create a queue on.
  11209. * @mq: The queue structure to use to create the mailbox queue.
  11210. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  11211. * @cq: The completion queue to associate with this cq.
  11212. *
  11213. * This function provides failback (fb) functionality when the
  11214. * mq_create_ext fails on older FW generations. It's purpose is identical
  11215. * to mq_create_ext otherwise.
  11216. *
  11217. * This routine cannot fail as all attributes were previously accessed and
  11218. * initialized in mq_create_ext.
  11219. **/
  11220. static void
  11221. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11222. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  11223. {
  11224. struct lpfc_mbx_mq_create *mq_create;
  11225. struct lpfc_dmabuf *dmabuf;
  11226. int length;
  11227. length = (sizeof(struct lpfc_mbx_mq_create) -
  11228. sizeof(struct lpfc_sli4_cfg_mhdr));
  11229. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11230. LPFC_MBOX_OPCODE_MQ_CREATE,
  11231. length, LPFC_SLI4_MBX_EMBED);
  11232. mq_create = &mbox->u.mqe.un.mq_create;
  11233. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  11234. mq->page_count);
  11235. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  11236. cq->queue_id);
  11237. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  11238. switch (mq->entry_count) {
  11239. case 16:
  11240. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11241. LPFC_MQ_RING_SIZE_16);
  11242. break;
  11243. case 32:
  11244. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11245. LPFC_MQ_RING_SIZE_32);
  11246. break;
  11247. case 64:
  11248. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11249. LPFC_MQ_RING_SIZE_64);
  11250. break;
  11251. case 128:
  11252. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11253. LPFC_MQ_RING_SIZE_128);
  11254. break;
  11255. }
  11256. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11257. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11258. putPaddrLow(dmabuf->phys);
  11259. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11260. putPaddrHigh(dmabuf->phys);
  11261. }
  11262. }
  11263. /**
  11264. * lpfc_mq_create - Create a mailbox Queue on the HBA
  11265. * @phba: HBA structure that indicates port to create a queue on.
  11266. * @mq: The queue structure to use to create the mailbox queue.
  11267. * @cq: The completion queue to associate with this cq.
  11268. * @subtype: The queue's subtype.
  11269. *
  11270. * This function creates a mailbox queue, as detailed in @mq, on a port,
  11271. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  11272. *
  11273. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11274. * is used to get the entry count and entry size that are necessary to
  11275. * determine the number of pages to allocate and use for this queue. This
  11276. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  11277. * mailbox queue. This function is asynchronous and will wait for the mailbox
  11278. * command to finish before continuing.
  11279. *
  11280. * On success this function will return a zero. If unable to allocate enough
  11281. * memory this function will return -ENOMEM. If the queue create mailbox command
  11282. * fails this function will return -ENXIO.
  11283. **/
  11284. int32_t
  11285. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11286. struct lpfc_queue *cq, uint32_t subtype)
  11287. {
  11288. struct lpfc_mbx_mq_create *mq_create;
  11289. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11290. struct lpfc_dmabuf *dmabuf;
  11291. LPFC_MBOXQ_t *mbox;
  11292. int rc, length, status = 0;
  11293. uint32_t shdr_status, shdr_add_status;
  11294. union lpfc_sli4_cfg_shdr *shdr;
  11295. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11296. /* sanity check on queue memory */
  11297. if (!mq || !cq)
  11298. return -ENODEV;
  11299. if (!phba->sli4_hba.pc_sli4_params.supported)
  11300. hw_page_size = SLI4_PAGE_SIZE;
  11301. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11302. if (!mbox)
  11303. return -ENOMEM;
  11304. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11305. sizeof(struct lpfc_sli4_cfg_mhdr));
  11306. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11307. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11308. length, LPFC_SLI4_MBX_EMBED);
  11309. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11310. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11311. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11312. &mq_create_ext->u.request, mq->page_count);
  11313. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11314. &mq_create_ext->u.request, 1);
  11315. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11316. &mq_create_ext->u.request, 1);
  11317. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11318. &mq_create_ext->u.request, 1);
  11319. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11320. &mq_create_ext->u.request, 1);
  11321. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11322. &mq_create_ext->u.request, 1);
  11323. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11324. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11325. phba->sli4_hba.pc_sli4_params.mqv);
  11326. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11327. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11328. cq->queue_id);
  11329. else
  11330. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11331. cq->queue_id);
  11332. switch (mq->entry_count) {
  11333. default:
  11334. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11335. "0362 Unsupported MQ count. (%d)\n",
  11336. mq->entry_count);
  11337. if (mq->entry_count < 16)
  11338. return -EINVAL;
  11339. /* otherwise default to smallest count (drop through) */
  11340. case 16:
  11341. bf_set(lpfc_mq_context_ring_size,
  11342. &mq_create_ext->u.request.context,
  11343. LPFC_MQ_RING_SIZE_16);
  11344. break;
  11345. case 32:
  11346. bf_set(lpfc_mq_context_ring_size,
  11347. &mq_create_ext->u.request.context,
  11348. LPFC_MQ_RING_SIZE_32);
  11349. break;
  11350. case 64:
  11351. bf_set(lpfc_mq_context_ring_size,
  11352. &mq_create_ext->u.request.context,
  11353. LPFC_MQ_RING_SIZE_64);
  11354. break;
  11355. case 128:
  11356. bf_set(lpfc_mq_context_ring_size,
  11357. &mq_create_ext->u.request.context,
  11358. LPFC_MQ_RING_SIZE_128);
  11359. break;
  11360. }
  11361. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11362. memset(dmabuf->virt, 0, hw_page_size);
  11363. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11364. putPaddrLow(dmabuf->phys);
  11365. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11366. putPaddrHigh(dmabuf->phys);
  11367. }
  11368. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11369. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11370. &mq_create_ext->u.response);
  11371. if (rc != MBX_SUCCESS) {
  11372. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11373. "2795 MQ_CREATE_EXT failed with "
  11374. "status x%x. Failback to MQ_CREATE.\n",
  11375. rc);
  11376. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11377. mq_create = &mbox->u.mqe.un.mq_create;
  11378. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11379. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11380. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11381. &mq_create->u.response);
  11382. }
  11383. /* The IOCTL status is embedded in the mailbox subheader. */
  11384. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11385. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11386. if (shdr_status || shdr_add_status || rc) {
  11387. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11388. "2502 MQ_CREATE mailbox failed with "
  11389. "status x%x add_status x%x, mbx status x%x\n",
  11390. shdr_status, shdr_add_status, rc);
  11391. status = -ENXIO;
  11392. goto out;
  11393. }
  11394. if (mq->queue_id == 0xFFFF) {
  11395. status = -ENXIO;
  11396. goto out;
  11397. }
  11398. mq->type = LPFC_MQ;
  11399. mq->assoc_qid = cq->queue_id;
  11400. mq->subtype = subtype;
  11401. mq->host_index = 0;
  11402. mq->hba_index = 0;
  11403. /* link the mq onto the parent cq child list */
  11404. list_add_tail(&mq->list, &cq->child_list);
  11405. out:
  11406. mempool_free(mbox, phba->mbox_mem_pool);
  11407. return status;
  11408. }
  11409. /**
  11410. * lpfc_wq_create - Create a Work Queue on the HBA
  11411. * @phba: HBA structure that indicates port to create a queue on.
  11412. * @wq: The queue structure to use to create the work queue.
  11413. * @cq: The completion queue to bind this work queue to.
  11414. * @subtype: The subtype of the work queue indicating its functionality.
  11415. *
  11416. * This function creates a work queue, as detailed in @wq, on a port, described
  11417. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11418. *
  11419. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11420. * is used to get the entry count and entry size that are necessary to
  11421. * determine the number of pages to allocate and use for this queue. The @cq
  11422. * is used to indicate which completion queue to bind this work queue to. This
  11423. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11424. * work queue. This function is asynchronous and will wait for the mailbox
  11425. * command to finish before continuing.
  11426. *
  11427. * On success this function will return a zero. If unable to allocate enough
  11428. * memory this function will return -ENOMEM. If the queue create mailbox command
  11429. * fails this function will return -ENXIO.
  11430. **/
  11431. uint32_t
  11432. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11433. struct lpfc_queue *cq, uint32_t subtype)
  11434. {
  11435. struct lpfc_mbx_wq_create *wq_create;
  11436. struct lpfc_dmabuf *dmabuf;
  11437. LPFC_MBOXQ_t *mbox;
  11438. int rc, length, status = 0;
  11439. uint32_t shdr_status, shdr_add_status;
  11440. union lpfc_sli4_cfg_shdr *shdr;
  11441. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11442. struct dma_address *page;
  11443. /* sanity check on queue memory */
  11444. if (!wq || !cq)
  11445. return -ENODEV;
  11446. if (!phba->sli4_hba.pc_sli4_params.supported)
  11447. hw_page_size = SLI4_PAGE_SIZE;
  11448. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11449. if (!mbox)
  11450. return -ENOMEM;
  11451. length = (sizeof(struct lpfc_mbx_wq_create) -
  11452. sizeof(struct lpfc_sli4_cfg_mhdr));
  11453. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11454. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11455. length, LPFC_SLI4_MBX_EMBED);
  11456. wq_create = &mbox->u.mqe.un.wq_create;
  11457. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11458. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11459. wq->page_count);
  11460. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11461. cq->queue_id);
  11462. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11463. phba->sli4_hba.pc_sli4_params.wqv);
  11464. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11465. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11466. wq->entry_count);
  11467. switch (wq->entry_size) {
  11468. default:
  11469. case 64:
  11470. bf_set(lpfc_mbx_wq_create_wqe_size,
  11471. &wq_create->u.request_1,
  11472. LPFC_WQ_WQE_SIZE_64);
  11473. break;
  11474. case 128:
  11475. bf_set(lpfc_mbx_wq_create_wqe_size,
  11476. &wq_create->u.request_1,
  11477. LPFC_WQ_WQE_SIZE_128);
  11478. break;
  11479. }
  11480. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11481. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11482. page = wq_create->u.request_1.page;
  11483. } else {
  11484. page = wq_create->u.request.page;
  11485. }
  11486. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11487. memset(dmabuf->virt, 0, hw_page_size);
  11488. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11489. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11490. }
  11491. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11492. /* The IOCTL status is embedded in the mailbox subheader. */
  11493. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11494. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11495. if (shdr_status || shdr_add_status || rc) {
  11496. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11497. "2503 WQ_CREATE mailbox failed with "
  11498. "status x%x add_status x%x, mbx status x%x\n",
  11499. shdr_status, shdr_add_status, rc);
  11500. status = -ENXIO;
  11501. goto out;
  11502. }
  11503. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11504. if (wq->queue_id == 0xFFFF) {
  11505. status = -ENXIO;
  11506. goto out;
  11507. }
  11508. wq->type = LPFC_WQ;
  11509. wq->assoc_qid = cq->queue_id;
  11510. wq->subtype = subtype;
  11511. wq->host_index = 0;
  11512. wq->hba_index = 0;
  11513. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11514. /* link the wq onto the parent cq child list */
  11515. list_add_tail(&wq->list, &cq->child_list);
  11516. out:
  11517. mempool_free(mbox, phba->mbox_mem_pool);
  11518. return status;
  11519. }
  11520. /**
  11521. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11522. * @phba: HBA structure that indicates port to create a queue on.
  11523. * @rq: The queue structure to use for the receive queue.
  11524. * @qno: The associated HBQ number
  11525. *
  11526. *
  11527. * For SLI4 we need to adjust the RQ repost value based on
  11528. * the number of buffers that are initially posted to the RQ.
  11529. */
  11530. void
  11531. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11532. {
  11533. uint32_t cnt;
  11534. /* sanity check on queue memory */
  11535. if (!rq)
  11536. return;
  11537. cnt = lpfc_hbq_defs[qno]->entry_count;
  11538. /* Recalc repost for RQs based on buffers initially posted */
  11539. cnt = (cnt >> 3);
  11540. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11541. cnt = LPFC_QUEUE_MIN_REPOST;
  11542. rq->entry_repost = cnt;
  11543. }
  11544. /**
  11545. * lpfc_rq_create - Create a Receive Queue on the HBA
  11546. * @phba: HBA structure that indicates port to create a queue on.
  11547. * @hrq: The queue structure to use to create the header receive queue.
  11548. * @drq: The queue structure to use to create the data receive queue.
  11549. * @cq: The completion queue to bind this work queue to.
  11550. *
  11551. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11552. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11553. * to the HBA.
  11554. *
  11555. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11556. * struct is used to get the entry count that is necessary to determine the
  11557. * number of pages to use for this queue. The @cq is used to indicate which
  11558. * completion queue to bind received buffers that are posted to these queues to.
  11559. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11560. * receive queue pair. This function is asynchronous and will wait for the
  11561. * mailbox command to finish before continuing.
  11562. *
  11563. * On success this function will return a zero. If unable to allocate enough
  11564. * memory this function will return -ENOMEM. If the queue create mailbox command
  11565. * fails this function will return -ENXIO.
  11566. **/
  11567. uint32_t
  11568. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11569. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11570. {
  11571. struct lpfc_mbx_rq_create *rq_create;
  11572. struct lpfc_dmabuf *dmabuf;
  11573. LPFC_MBOXQ_t *mbox;
  11574. int rc, length, status = 0;
  11575. uint32_t shdr_status, shdr_add_status;
  11576. union lpfc_sli4_cfg_shdr *shdr;
  11577. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11578. /* sanity check on queue memory */
  11579. if (!hrq || !drq || !cq)
  11580. return -ENODEV;
  11581. if (!phba->sli4_hba.pc_sli4_params.supported)
  11582. hw_page_size = SLI4_PAGE_SIZE;
  11583. if (hrq->entry_count != drq->entry_count)
  11584. return -EINVAL;
  11585. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11586. if (!mbox)
  11587. return -ENOMEM;
  11588. length = (sizeof(struct lpfc_mbx_rq_create) -
  11589. sizeof(struct lpfc_sli4_cfg_mhdr));
  11590. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11591. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11592. length, LPFC_SLI4_MBX_EMBED);
  11593. rq_create = &mbox->u.mqe.un.rq_create;
  11594. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11595. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11596. phba->sli4_hba.pc_sli4_params.rqv);
  11597. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11598. bf_set(lpfc_rq_context_rqe_count_1,
  11599. &rq_create->u.request.context,
  11600. hrq->entry_count);
  11601. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11602. bf_set(lpfc_rq_context_rqe_size,
  11603. &rq_create->u.request.context,
  11604. LPFC_RQE_SIZE_8);
  11605. bf_set(lpfc_rq_context_page_size,
  11606. &rq_create->u.request.context,
  11607. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11608. } else {
  11609. switch (hrq->entry_count) {
  11610. default:
  11611. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11612. "2535 Unsupported RQ count. (%d)\n",
  11613. hrq->entry_count);
  11614. if (hrq->entry_count < 512)
  11615. return -EINVAL;
  11616. /* otherwise default to smallest count (drop through) */
  11617. case 512:
  11618. bf_set(lpfc_rq_context_rqe_count,
  11619. &rq_create->u.request.context,
  11620. LPFC_RQ_RING_SIZE_512);
  11621. break;
  11622. case 1024:
  11623. bf_set(lpfc_rq_context_rqe_count,
  11624. &rq_create->u.request.context,
  11625. LPFC_RQ_RING_SIZE_1024);
  11626. break;
  11627. case 2048:
  11628. bf_set(lpfc_rq_context_rqe_count,
  11629. &rq_create->u.request.context,
  11630. LPFC_RQ_RING_SIZE_2048);
  11631. break;
  11632. case 4096:
  11633. bf_set(lpfc_rq_context_rqe_count,
  11634. &rq_create->u.request.context,
  11635. LPFC_RQ_RING_SIZE_4096);
  11636. break;
  11637. }
  11638. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11639. LPFC_HDR_BUF_SIZE);
  11640. }
  11641. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11642. cq->queue_id);
  11643. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11644. hrq->page_count);
  11645. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11646. memset(dmabuf->virt, 0, hw_page_size);
  11647. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11648. putPaddrLow(dmabuf->phys);
  11649. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11650. putPaddrHigh(dmabuf->phys);
  11651. }
  11652. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11653. /* The IOCTL status is embedded in the mailbox subheader. */
  11654. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11655. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11656. if (shdr_status || shdr_add_status || rc) {
  11657. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11658. "2504 RQ_CREATE mailbox failed with "
  11659. "status x%x add_status x%x, mbx status x%x\n",
  11660. shdr_status, shdr_add_status, rc);
  11661. status = -ENXIO;
  11662. goto out;
  11663. }
  11664. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11665. if (hrq->queue_id == 0xFFFF) {
  11666. status = -ENXIO;
  11667. goto out;
  11668. }
  11669. hrq->type = LPFC_HRQ;
  11670. hrq->assoc_qid = cq->queue_id;
  11671. hrq->subtype = subtype;
  11672. hrq->host_index = 0;
  11673. hrq->hba_index = 0;
  11674. /* now create the data queue */
  11675. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11676. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11677. length, LPFC_SLI4_MBX_EMBED);
  11678. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11679. phba->sli4_hba.pc_sli4_params.rqv);
  11680. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11681. bf_set(lpfc_rq_context_rqe_count_1,
  11682. &rq_create->u.request.context, hrq->entry_count);
  11683. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  11684. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  11685. LPFC_RQE_SIZE_8);
  11686. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  11687. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11688. } else {
  11689. switch (drq->entry_count) {
  11690. default:
  11691. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11692. "2536 Unsupported RQ count. (%d)\n",
  11693. drq->entry_count);
  11694. if (drq->entry_count < 512)
  11695. return -EINVAL;
  11696. /* otherwise default to smallest count (drop through) */
  11697. case 512:
  11698. bf_set(lpfc_rq_context_rqe_count,
  11699. &rq_create->u.request.context,
  11700. LPFC_RQ_RING_SIZE_512);
  11701. break;
  11702. case 1024:
  11703. bf_set(lpfc_rq_context_rqe_count,
  11704. &rq_create->u.request.context,
  11705. LPFC_RQ_RING_SIZE_1024);
  11706. break;
  11707. case 2048:
  11708. bf_set(lpfc_rq_context_rqe_count,
  11709. &rq_create->u.request.context,
  11710. LPFC_RQ_RING_SIZE_2048);
  11711. break;
  11712. case 4096:
  11713. bf_set(lpfc_rq_context_rqe_count,
  11714. &rq_create->u.request.context,
  11715. LPFC_RQ_RING_SIZE_4096);
  11716. break;
  11717. }
  11718. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11719. LPFC_DATA_BUF_SIZE);
  11720. }
  11721. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11722. cq->queue_id);
  11723. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11724. drq->page_count);
  11725. list_for_each_entry(dmabuf, &drq->page_list, list) {
  11726. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11727. putPaddrLow(dmabuf->phys);
  11728. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11729. putPaddrHigh(dmabuf->phys);
  11730. }
  11731. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11732. /* The IOCTL status is embedded in the mailbox subheader. */
  11733. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11734. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11735. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11736. if (shdr_status || shdr_add_status || rc) {
  11737. status = -ENXIO;
  11738. goto out;
  11739. }
  11740. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11741. if (drq->queue_id == 0xFFFF) {
  11742. status = -ENXIO;
  11743. goto out;
  11744. }
  11745. drq->type = LPFC_DRQ;
  11746. drq->assoc_qid = cq->queue_id;
  11747. drq->subtype = subtype;
  11748. drq->host_index = 0;
  11749. drq->hba_index = 0;
  11750. /* link the header and data RQs onto the parent cq child list */
  11751. list_add_tail(&hrq->list, &cq->child_list);
  11752. list_add_tail(&drq->list, &cq->child_list);
  11753. out:
  11754. mempool_free(mbox, phba->mbox_mem_pool);
  11755. return status;
  11756. }
  11757. /**
  11758. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  11759. * @eq: The queue structure associated with the queue to destroy.
  11760. *
  11761. * This function destroys a queue, as detailed in @eq by sending an mailbox
  11762. * command, specific to the type of queue, to the HBA.
  11763. *
  11764. * The @eq struct is used to get the queue ID of the queue to destroy.
  11765. *
  11766. * On success this function will return a zero. If the queue destroy mailbox
  11767. * command fails this function will return -ENXIO.
  11768. **/
  11769. uint32_t
  11770. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11771. {
  11772. LPFC_MBOXQ_t *mbox;
  11773. int rc, length, status = 0;
  11774. uint32_t shdr_status, shdr_add_status;
  11775. union lpfc_sli4_cfg_shdr *shdr;
  11776. /* sanity check on queue memory */
  11777. if (!eq)
  11778. return -ENODEV;
  11779. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  11780. if (!mbox)
  11781. return -ENOMEM;
  11782. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  11783. sizeof(struct lpfc_sli4_cfg_mhdr));
  11784. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11785. LPFC_MBOX_OPCODE_EQ_DESTROY,
  11786. length, LPFC_SLI4_MBX_EMBED);
  11787. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  11788. eq->queue_id);
  11789. mbox->vport = eq->phba->pport;
  11790. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11791. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  11792. /* The IOCTL status is embedded in the mailbox subheader. */
  11793. shdr = (union lpfc_sli4_cfg_shdr *)
  11794. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  11795. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11796. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11797. if (shdr_status || shdr_add_status || rc) {
  11798. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11799. "2505 EQ_DESTROY mailbox failed with "
  11800. "status x%x add_status x%x, mbx status x%x\n",
  11801. shdr_status, shdr_add_status, rc);
  11802. status = -ENXIO;
  11803. }
  11804. /* Remove eq from any list */
  11805. list_del_init(&eq->list);
  11806. mempool_free(mbox, eq->phba->mbox_mem_pool);
  11807. return status;
  11808. }
  11809. /**
  11810. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  11811. * @cq: The queue structure associated with the queue to destroy.
  11812. *
  11813. * This function destroys a queue, as detailed in @cq by sending an mailbox
  11814. * command, specific to the type of queue, to the HBA.
  11815. *
  11816. * The @cq struct is used to get the queue ID of the queue to destroy.
  11817. *
  11818. * On success this function will return a zero. If the queue destroy mailbox
  11819. * command fails this function will return -ENXIO.
  11820. **/
  11821. uint32_t
  11822. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  11823. {
  11824. LPFC_MBOXQ_t *mbox;
  11825. int rc, length, status = 0;
  11826. uint32_t shdr_status, shdr_add_status;
  11827. union lpfc_sli4_cfg_shdr *shdr;
  11828. /* sanity check on queue memory */
  11829. if (!cq)
  11830. return -ENODEV;
  11831. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  11832. if (!mbox)
  11833. return -ENOMEM;
  11834. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  11835. sizeof(struct lpfc_sli4_cfg_mhdr));
  11836. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11837. LPFC_MBOX_OPCODE_CQ_DESTROY,
  11838. length, LPFC_SLI4_MBX_EMBED);
  11839. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  11840. cq->queue_id);
  11841. mbox->vport = cq->phba->pport;
  11842. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11843. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  11844. /* The IOCTL status is embedded in the mailbox subheader. */
  11845. shdr = (union lpfc_sli4_cfg_shdr *)
  11846. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  11847. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11848. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11849. if (shdr_status || shdr_add_status || rc) {
  11850. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11851. "2506 CQ_DESTROY mailbox failed with "
  11852. "status x%x add_status x%x, mbx status x%x\n",
  11853. shdr_status, shdr_add_status, rc);
  11854. status = -ENXIO;
  11855. }
  11856. /* Remove cq from any list */
  11857. list_del_init(&cq->list);
  11858. mempool_free(mbox, cq->phba->mbox_mem_pool);
  11859. return status;
  11860. }
  11861. /**
  11862. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  11863. * @qm: The queue structure associated with the queue to destroy.
  11864. *
  11865. * This function destroys a queue, as detailed in @mq by sending an mailbox
  11866. * command, specific to the type of queue, to the HBA.
  11867. *
  11868. * The @mq struct is used to get the queue ID of the queue to destroy.
  11869. *
  11870. * On success this function will return a zero. If the queue destroy mailbox
  11871. * command fails this function will return -ENXIO.
  11872. **/
  11873. uint32_t
  11874. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  11875. {
  11876. LPFC_MBOXQ_t *mbox;
  11877. int rc, length, status = 0;
  11878. uint32_t shdr_status, shdr_add_status;
  11879. union lpfc_sli4_cfg_shdr *shdr;
  11880. /* sanity check on queue memory */
  11881. if (!mq)
  11882. return -ENODEV;
  11883. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  11884. if (!mbox)
  11885. return -ENOMEM;
  11886. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  11887. sizeof(struct lpfc_sli4_cfg_mhdr));
  11888. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11889. LPFC_MBOX_OPCODE_MQ_DESTROY,
  11890. length, LPFC_SLI4_MBX_EMBED);
  11891. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  11892. mq->queue_id);
  11893. mbox->vport = mq->phba->pport;
  11894. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11895. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  11896. /* The IOCTL status is embedded in the mailbox subheader. */
  11897. shdr = (union lpfc_sli4_cfg_shdr *)
  11898. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  11899. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11900. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11901. if (shdr_status || shdr_add_status || rc) {
  11902. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11903. "2507 MQ_DESTROY mailbox failed with "
  11904. "status x%x add_status x%x, mbx status x%x\n",
  11905. shdr_status, shdr_add_status, rc);
  11906. status = -ENXIO;
  11907. }
  11908. /* Remove mq from any list */
  11909. list_del_init(&mq->list);
  11910. mempool_free(mbox, mq->phba->mbox_mem_pool);
  11911. return status;
  11912. }
  11913. /**
  11914. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  11915. * @wq: The queue structure associated with the queue to destroy.
  11916. *
  11917. * This function destroys a queue, as detailed in @wq by sending an mailbox
  11918. * command, specific to the type of queue, to the HBA.
  11919. *
  11920. * The @wq struct is used to get the queue ID of the queue to destroy.
  11921. *
  11922. * On success this function will return a zero. If the queue destroy mailbox
  11923. * command fails this function will return -ENXIO.
  11924. **/
  11925. uint32_t
  11926. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  11927. {
  11928. LPFC_MBOXQ_t *mbox;
  11929. int rc, length, status = 0;
  11930. uint32_t shdr_status, shdr_add_status;
  11931. union lpfc_sli4_cfg_shdr *shdr;
  11932. /* sanity check on queue memory */
  11933. if (!wq)
  11934. return -ENODEV;
  11935. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  11936. if (!mbox)
  11937. return -ENOMEM;
  11938. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  11939. sizeof(struct lpfc_sli4_cfg_mhdr));
  11940. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11941. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  11942. length, LPFC_SLI4_MBX_EMBED);
  11943. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  11944. wq->queue_id);
  11945. mbox->vport = wq->phba->pport;
  11946. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11947. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  11948. shdr = (union lpfc_sli4_cfg_shdr *)
  11949. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  11950. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11951. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11952. if (shdr_status || shdr_add_status || rc) {
  11953. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11954. "2508 WQ_DESTROY mailbox failed with "
  11955. "status x%x add_status x%x, mbx status x%x\n",
  11956. shdr_status, shdr_add_status, rc);
  11957. status = -ENXIO;
  11958. }
  11959. /* Remove wq from any list */
  11960. list_del_init(&wq->list);
  11961. mempool_free(mbox, wq->phba->mbox_mem_pool);
  11962. return status;
  11963. }
  11964. /**
  11965. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  11966. * @rq: The queue structure associated with the queue to destroy.
  11967. *
  11968. * This function destroys a queue, as detailed in @rq by sending an mailbox
  11969. * command, specific to the type of queue, to the HBA.
  11970. *
  11971. * The @rq struct is used to get the queue ID of the queue to destroy.
  11972. *
  11973. * On success this function will return a zero. If the queue destroy mailbox
  11974. * command fails this function will return -ENXIO.
  11975. **/
  11976. uint32_t
  11977. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11978. struct lpfc_queue *drq)
  11979. {
  11980. LPFC_MBOXQ_t *mbox;
  11981. int rc, length, status = 0;
  11982. uint32_t shdr_status, shdr_add_status;
  11983. union lpfc_sli4_cfg_shdr *shdr;
  11984. /* sanity check on queue memory */
  11985. if (!hrq || !drq)
  11986. return -ENODEV;
  11987. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  11988. if (!mbox)
  11989. return -ENOMEM;
  11990. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  11991. sizeof(struct lpfc_sli4_cfg_mhdr));
  11992. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11993. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  11994. length, LPFC_SLI4_MBX_EMBED);
  11995. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  11996. hrq->queue_id);
  11997. mbox->vport = hrq->phba->pport;
  11998. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11999. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  12000. /* The IOCTL status is embedded in the mailbox subheader. */
  12001. shdr = (union lpfc_sli4_cfg_shdr *)
  12002. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12003. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12004. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12005. if (shdr_status || shdr_add_status || rc) {
  12006. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12007. "2509 RQ_DESTROY mailbox failed with "
  12008. "status x%x add_status x%x, mbx status x%x\n",
  12009. shdr_status, shdr_add_status, rc);
  12010. if (rc != MBX_TIMEOUT)
  12011. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12012. return -ENXIO;
  12013. }
  12014. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  12015. drq->queue_id);
  12016. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  12017. shdr = (union lpfc_sli4_cfg_shdr *)
  12018. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  12019. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12020. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12021. if (shdr_status || shdr_add_status || rc) {
  12022. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12023. "2510 RQ_DESTROY mailbox failed with "
  12024. "status x%x add_status x%x, mbx status x%x\n",
  12025. shdr_status, shdr_add_status, rc);
  12026. status = -ENXIO;
  12027. }
  12028. list_del_init(&hrq->list);
  12029. list_del_init(&drq->list);
  12030. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  12031. return status;
  12032. }
  12033. /**
  12034. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  12035. * @phba: The virtual port for which this call being executed.
  12036. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  12037. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  12038. * @xritag: the xritag that ties this io to the SGL pages.
  12039. *
  12040. * This routine will post the sgl pages for the IO that has the xritag
  12041. * that is in the iocbq structure. The xritag is assigned during iocbq
  12042. * creation and persists for as long as the driver is loaded.
  12043. * if the caller has fewer than 256 scatter gather segments to map then
  12044. * pdma_phys_addr1 should be 0.
  12045. * If the caller needs to map more than 256 scatter gather segment then
  12046. * pdma_phys_addr1 should be a valid physical address.
  12047. * physical address for SGLs must be 64 byte aligned.
  12048. * If you are going to map 2 SGL's then the first one must have 256 entries
  12049. * the second sgl can have between 1 and 256 entries.
  12050. *
  12051. * Return codes:
  12052. * 0 - Success
  12053. * -ENXIO, -ENOMEM - Failure
  12054. **/
  12055. int
  12056. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  12057. dma_addr_t pdma_phys_addr0,
  12058. dma_addr_t pdma_phys_addr1,
  12059. uint16_t xritag)
  12060. {
  12061. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  12062. LPFC_MBOXQ_t *mbox;
  12063. int rc;
  12064. uint32_t shdr_status, shdr_add_status;
  12065. uint32_t mbox_tmo;
  12066. union lpfc_sli4_cfg_shdr *shdr;
  12067. if (xritag == NO_XRI) {
  12068. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12069. "0364 Invalid param:\n");
  12070. return -EINVAL;
  12071. }
  12072. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12073. if (!mbox)
  12074. return -ENOMEM;
  12075. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12076. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12077. sizeof(struct lpfc_mbx_post_sgl_pages) -
  12078. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  12079. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  12080. &mbox->u.mqe.un.post_sgl_pages;
  12081. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  12082. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  12083. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  12084. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  12085. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  12086. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  12087. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  12088. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  12089. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  12090. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  12091. if (!phba->sli4_hba.intr_enable)
  12092. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12093. else {
  12094. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12095. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12096. }
  12097. /* The IOCTL status is embedded in the mailbox subheader. */
  12098. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  12099. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12100. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12101. if (rc != MBX_TIMEOUT)
  12102. mempool_free(mbox, phba->mbox_mem_pool);
  12103. if (shdr_status || shdr_add_status || rc) {
  12104. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12105. "2511 POST_SGL mailbox failed with "
  12106. "status x%x add_status x%x, mbx status x%x\n",
  12107. shdr_status, shdr_add_status, rc);
  12108. rc = -ENXIO;
  12109. }
  12110. return 0;
  12111. }
  12112. /**
  12113. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  12114. * @phba: pointer to lpfc hba data structure.
  12115. *
  12116. * This routine is invoked to post rpi header templates to the
  12117. * HBA consistent with the SLI-4 interface spec. This routine
  12118. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  12119. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  12120. *
  12121. * Returns
  12122. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  12123. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  12124. **/
  12125. uint16_t
  12126. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  12127. {
  12128. unsigned long xri;
  12129. /*
  12130. * Fetch the next logical xri. Because this index is logical,
  12131. * the driver starts at 0 each time.
  12132. */
  12133. spin_lock_irq(&phba->hbalock);
  12134. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  12135. phba->sli4_hba.max_cfg_param.max_xri, 0);
  12136. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  12137. spin_unlock_irq(&phba->hbalock);
  12138. return NO_XRI;
  12139. } else {
  12140. set_bit(xri, phba->sli4_hba.xri_bmask);
  12141. phba->sli4_hba.max_cfg_param.xri_used++;
  12142. }
  12143. spin_unlock_irq(&phba->hbalock);
  12144. return xri;
  12145. }
  12146. /**
  12147. * lpfc_sli4_free_xri - Release an xri for reuse.
  12148. * @phba: pointer to lpfc hba data structure.
  12149. *
  12150. * This routine is invoked to release an xri to the pool of
  12151. * available rpis maintained by the driver.
  12152. **/
  12153. void
  12154. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12155. {
  12156. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  12157. phba->sli4_hba.max_cfg_param.xri_used--;
  12158. }
  12159. }
  12160. /**
  12161. * lpfc_sli4_free_xri - Release an xri for reuse.
  12162. * @phba: pointer to lpfc hba data structure.
  12163. *
  12164. * This routine is invoked to release an xri to the pool of
  12165. * available rpis maintained by the driver.
  12166. **/
  12167. void
  12168. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  12169. {
  12170. spin_lock_irq(&phba->hbalock);
  12171. __lpfc_sli4_free_xri(phba, xri);
  12172. spin_unlock_irq(&phba->hbalock);
  12173. }
  12174. /**
  12175. * lpfc_sli4_next_xritag - Get an xritag for the io
  12176. * @phba: Pointer to HBA context object.
  12177. *
  12178. * This function gets an xritag for the iocb. If there is no unused xritag
  12179. * it will return 0xffff.
  12180. * The function returns the allocated xritag if successful, else returns zero.
  12181. * Zero is not a valid xritag.
  12182. * The caller is not required to hold any lock.
  12183. **/
  12184. uint16_t
  12185. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  12186. {
  12187. uint16_t xri_index;
  12188. xri_index = lpfc_sli4_alloc_xri(phba);
  12189. if (xri_index == NO_XRI)
  12190. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  12191. "2004 Failed to allocate XRI.last XRITAG is %d"
  12192. " Max XRI is %d, Used XRI is %d\n",
  12193. xri_index,
  12194. phba->sli4_hba.max_cfg_param.max_xri,
  12195. phba->sli4_hba.max_cfg_param.xri_used);
  12196. return xri_index;
  12197. }
  12198. /**
  12199. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  12200. * @phba: pointer to lpfc hba data structure.
  12201. * @post_sgl_list: pointer to els sgl entry list.
  12202. * @count: number of els sgl entries on the list.
  12203. *
  12204. * This routine is invoked to post a block of driver's sgl pages to the
  12205. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12206. * is only called when the driver is loading and after all IO has been
  12207. * stopped.
  12208. **/
  12209. static int
  12210. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba,
  12211. struct list_head *post_sgl_list,
  12212. int post_cnt)
  12213. {
  12214. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  12215. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12216. struct sgl_page_pairs *sgl_pg_pairs;
  12217. void *viraddr;
  12218. LPFC_MBOXQ_t *mbox;
  12219. uint32_t reqlen, alloclen, pg_pairs;
  12220. uint32_t mbox_tmo;
  12221. uint16_t xritag_start = 0;
  12222. int rc = 0;
  12223. uint32_t shdr_status, shdr_add_status;
  12224. union lpfc_sli4_cfg_shdr *shdr;
  12225. reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12226. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12227. if (reqlen > SLI4_PAGE_SIZE) {
  12228. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12229. "2559 Block sgl registration required DMA "
  12230. "size (%d) great than a page\n", reqlen);
  12231. return -ENOMEM;
  12232. }
  12233. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12234. if (!mbox)
  12235. return -ENOMEM;
  12236. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12237. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12238. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12239. LPFC_SLI4_MBX_NEMBED);
  12240. if (alloclen < reqlen) {
  12241. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12242. "0285 Allocated DMA memory size (%d) is "
  12243. "less than the requested DMA memory "
  12244. "size (%d)\n", alloclen, reqlen);
  12245. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12246. return -ENOMEM;
  12247. }
  12248. /* Set up the SGL pages in the non-embedded DMA pages */
  12249. viraddr = mbox->sge_array->addr[0];
  12250. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12251. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12252. pg_pairs = 0;
  12253. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  12254. /* Set up the sge entry */
  12255. sgl_pg_pairs->sgl_pg0_addr_lo =
  12256. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12257. sgl_pg_pairs->sgl_pg0_addr_hi =
  12258. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12259. sgl_pg_pairs->sgl_pg1_addr_lo =
  12260. cpu_to_le32(putPaddrLow(0));
  12261. sgl_pg_pairs->sgl_pg1_addr_hi =
  12262. cpu_to_le32(putPaddrHigh(0));
  12263. /* Keep the first xritag on the list */
  12264. if (pg_pairs == 0)
  12265. xritag_start = sglq_entry->sli4_xritag;
  12266. sgl_pg_pairs++;
  12267. pg_pairs++;
  12268. }
  12269. /* Complete initialization and perform endian conversion. */
  12270. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12271. bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt);
  12272. sgl->word0 = cpu_to_le32(sgl->word0);
  12273. if (!phba->sli4_hba.intr_enable)
  12274. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12275. else {
  12276. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12277. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12278. }
  12279. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12280. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12281. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12282. if (rc != MBX_TIMEOUT)
  12283. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12284. if (shdr_status || shdr_add_status || rc) {
  12285. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12286. "2513 POST_SGL_BLOCK mailbox command failed "
  12287. "status x%x add_status x%x mbx status x%x\n",
  12288. shdr_status, shdr_add_status, rc);
  12289. rc = -ENXIO;
  12290. }
  12291. return rc;
  12292. }
  12293. /**
  12294. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12295. * @phba: pointer to lpfc hba data structure.
  12296. * @sblist: pointer to scsi buffer list.
  12297. * @count: number of scsi buffers on the list.
  12298. *
  12299. * This routine is invoked to post a block of @count scsi sgl pages from a
  12300. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12301. * No Lock is held.
  12302. *
  12303. **/
  12304. int
  12305. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
  12306. struct list_head *sblist,
  12307. int count)
  12308. {
  12309. struct lpfc_scsi_buf *psb;
  12310. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12311. struct sgl_page_pairs *sgl_pg_pairs;
  12312. void *viraddr;
  12313. LPFC_MBOXQ_t *mbox;
  12314. uint32_t reqlen, alloclen, pg_pairs;
  12315. uint32_t mbox_tmo;
  12316. uint16_t xritag_start = 0;
  12317. int rc = 0;
  12318. uint32_t shdr_status, shdr_add_status;
  12319. dma_addr_t pdma_phys_bpl1;
  12320. union lpfc_sli4_cfg_shdr *shdr;
  12321. /* Calculate the requested length of the dma memory */
  12322. reqlen = count * sizeof(struct sgl_page_pairs) +
  12323. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12324. if (reqlen > SLI4_PAGE_SIZE) {
  12325. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12326. "0217 Block sgl registration required DMA "
  12327. "size (%d) great than a page\n", reqlen);
  12328. return -ENOMEM;
  12329. }
  12330. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12331. if (!mbox) {
  12332. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12333. "0283 Failed to allocate mbox cmd memory\n");
  12334. return -ENOMEM;
  12335. }
  12336. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12337. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12338. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12339. LPFC_SLI4_MBX_NEMBED);
  12340. if (alloclen < reqlen) {
  12341. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12342. "2561 Allocated DMA memory size (%d) is "
  12343. "less than the requested DMA memory "
  12344. "size (%d)\n", alloclen, reqlen);
  12345. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12346. return -ENOMEM;
  12347. }
  12348. /* Get the first SGE entry from the non-embedded DMA memory */
  12349. viraddr = mbox->sge_array->addr[0];
  12350. /* Set up the SGL pages in the non-embedded DMA pages */
  12351. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12352. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12353. pg_pairs = 0;
  12354. list_for_each_entry(psb, sblist, list) {
  12355. /* Set up the sge entry */
  12356. sgl_pg_pairs->sgl_pg0_addr_lo =
  12357. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12358. sgl_pg_pairs->sgl_pg0_addr_hi =
  12359. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12360. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12361. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12362. else
  12363. pdma_phys_bpl1 = 0;
  12364. sgl_pg_pairs->sgl_pg1_addr_lo =
  12365. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12366. sgl_pg_pairs->sgl_pg1_addr_hi =
  12367. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12368. /* Keep the first xritag on the list */
  12369. if (pg_pairs == 0)
  12370. xritag_start = psb->cur_iocbq.sli4_xritag;
  12371. sgl_pg_pairs++;
  12372. pg_pairs++;
  12373. }
  12374. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12375. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12376. /* Perform endian conversion if necessary */
  12377. sgl->word0 = cpu_to_le32(sgl->word0);
  12378. if (!phba->sli4_hba.intr_enable)
  12379. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12380. else {
  12381. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12382. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12383. }
  12384. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12385. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12386. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12387. if (rc != MBX_TIMEOUT)
  12388. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12389. if (shdr_status || shdr_add_status || rc) {
  12390. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12391. "2564 POST_SGL_BLOCK mailbox command failed "
  12392. "status x%x add_status x%x mbx status x%x\n",
  12393. shdr_status, shdr_add_status, rc);
  12394. rc = -ENXIO;
  12395. }
  12396. return rc;
  12397. }
  12398. /**
  12399. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12400. * @phba: pointer to lpfc_hba struct that the frame was received on
  12401. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12402. *
  12403. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12404. * valid type of frame that the LPFC driver will handle. This function will
  12405. * return a zero if the frame is a valid frame or a non zero value when the
  12406. * frame does not pass the check.
  12407. **/
  12408. static int
  12409. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12410. {
  12411. /* make rctl_names static to save stack space */
  12412. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12413. char *type_names[] = FC_TYPE_NAMES_INIT;
  12414. struct fc_vft_header *fc_vft_hdr;
  12415. uint32_t *header = (uint32_t *) fc_hdr;
  12416. switch (fc_hdr->fh_r_ctl) {
  12417. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12418. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12419. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12420. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12421. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12422. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12423. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12424. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12425. case FC_RCTL_ELS_REQ: /* extended link services request */
  12426. case FC_RCTL_ELS_REP: /* extended link services reply */
  12427. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12428. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12429. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12430. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12431. case FC_RCTL_BA_RMC: /* remove connection */
  12432. case FC_RCTL_BA_ACC: /* basic accept */
  12433. case FC_RCTL_BA_RJT: /* basic reject */
  12434. case FC_RCTL_BA_PRMT:
  12435. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12436. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12437. case FC_RCTL_P_RJT: /* port reject */
  12438. case FC_RCTL_F_RJT: /* fabric reject */
  12439. case FC_RCTL_P_BSY: /* port busy */
  12440. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12441. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12442. case FC_RCTL_LCR: /* link credit reset */
  12443. case FC_RCTL_END: /* end */
  12444. break;
  12445. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12446. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12447. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12448. return lpfc_fc_frame_check(phba, fc_hdr);
  12449. default:
  12450. goto drop;
  12451. }
  12452. switch (fc_hdr->fh_type) {
  12453. case FC_TYPE_BLS:
  12454. case FC_TYPE_ELS:
  12455. case FC_TYPE_FCP:
  12456. case FC_TYPE_CT:
  12457. break;
  12458. case FC_TYPE_IP:
  12459. case FC_TYPE_ILS:
  12460. default:
  12461. goto drop;
  12462. }
  12463. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12464. "2538 Received frame rctl:%s type:%s "
  12465. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12466. rctl_names[fc_hdr->fh_r_ctl],
  12467. type_names[fc_hdr->fh_type],
  12468. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12469. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12470. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12471. return 0;
  12472. drop:
  12473. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12474. "2539 Dropped frame rctl:%s type:%s\n",
  12475. rctl_names[fc_hdr->fh_r_ctl],
  12476. type_names[fc_hdr->fh_type]);
  12477. return 1;
  12478. }
  12479. /**
  12480. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12481. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12482. *
  12483. * This function processes the FC header to retrieve the VFI from the VF
  12484. * header, if one exists. This function will return the VFI if one exists
  12485. * or 0 if no VSAN Header exists.
  12486. **/
  12487. static uint32_t
  12488. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12489. {
  12490. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12491. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12492. return 0;
  12493. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12494. }
  12495. /**
  12496. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12497. * @phba: Pointer to the HBA structure to search for the vport on
  12498. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12499. * @fcfi: The FC Fabric ID that the frame came from
  12500. *
  12501. * This function searches the @phba for a vport that matches the content of the
  12502. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12503. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12504. * returns the matching vport pointer or NULL if unable to match frame to a
  12505. * vport.
  12506. **/
  12507. static struct lpfc_vport *
  12508. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12509. uint16_t fcfi)
  12510. {
  12511. struct lpfc_vport **vports;
  12512. struct lpfc_vport *vport = NULL;
  12513. int i;
  12514. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12515. fc_hdr->fh_d_id[1] << 8 |
  12516. fc_hdr->fh_d_id[2]);
  12517. if (did == Fabric_DID)
  12518. return phba->pport;
  12519. if ((phba->pport->fc_flag & FC_PT2PT) &&
  12520. !(phba->link_state == LPFC_HBA_READY))
  12521. return phba->pport;
  12522. vports = lpfc_create_vport_work_array(phba);
  12523. if (vports != NULL)
  12524. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12525. if (phba->fcf.fcfi == fcfi &&
  12526. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12527. vports[i]->fc_myDID == did) {
  12528. vport = vports[i];
  12529. break;
  12530. }
  12531. }
  12532. lpfc_destroy_vport_work_array(phba, vports);
  12533. return vport;
  12534. }
  12535. /**
  12536. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12537. * @vport: The vport to work on.
  12538. *
  12539. * This function updates the receive sequence time stamp for this vport. The
  12540. * receive sequence time stamp indicates the time that the last frame of the
  12541. * the sequence that has been idle for the longest amount of time was received.
  12542. * the driver uses this time stamp to indicate if any received sequences have
  12543. * timed out.
  12544. **/
  12545. void
  12546. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12547. {
  12548. struct lpfc_dmabuf *h_buf;
  12549. struct hbq_dmabuf *dmabuf = NULL;
  12550. /* get the oldest sequence on the rcv list */
  12551. h_buf = list_get_first(&vport->rcv_buffer_list,
  12552. struct lpfc_dmabuf, list);
  12553. if (!h_buf)
  12554. return;
  12555. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12556. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12557. }
  12558. /**
  12559. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12560. * @vport: The vport that the received sequences were sent to.
  12561. *
  12562. * This function cleans up all outstanding received sequences. This is called
  12563. * by the driver when a link event or user action invalidates all the received
  12564. * sequences.
  12565. **/
  12566. void
  12567. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12568. {
  12569. struct lpfc_dmabuf *h_buf, *hnext;
  12570. struct lpfc_dmabuf *d_buf, *dnext;
  12571. struct hbq_dmabuf *dmabuf = NULL;
  12572. /* start with the oldest sequence on the rcv list */
  12573. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12574. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12575. list_del_init(&dmabuf->hbuf.list);
  12576. list_for_each_entry_safe(d_buf, dnext,
  12577. &dmabuf->dbuf.list, list) {
  12578. list_del_init(&d_buf->list);
  12579. lpfc_in_buf_free(vport->phba, d_buf);
  12580. }
  12581. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12582. }
  12583. }
  12584. /**
  12585. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12586. * @vport: The vport that the received sequences were sent to.
  12587. *
  12588. * This function determines whether any received sequences have timed out by
  12589. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12590. * indicates that there is at least one timed out sequence this routine will
  12591. * go through the received sequences one at a time from most inactive to most
  12592. * active to determine which ones need to be cleaned up. Once it has determined
  12593. * that a sequence needs to be cleaned up it will simply free up the resources
  12594. * without sending an abort.
  12595. **/
  12596. void
  12597. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12598. {
  12599. struct lpfc_dmabuf *h_buf, *hnext;
  12600. struct lpfc_dmabuf *d_buf, *dnext;
  12601. struct hbq_dmabuf *dmabuf = NULL;
  12602. unsigned long timeout;
  12603. int abort_count = 0;
  12604. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12605. vport->rcv_buffer_time_stamp);
  12606. if (list_empty(&vport->rcv_buffer_list) ||
  12607. time_before(jiffies, timeout))
  12608. return;
  12609. /* start with the oldest sequence on the rcv list */
  12610. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12611. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12612. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12613. dmabuf->time_stamp);
  12614. if (time_before(jiffies, timeout))
  12615. break;
  12616. abort_count++;
  12617. list_del_init(&dmabuf->hbuf.list);
  12618. list_for_each_entry_safe(d_buf, dnext,
  12619. &dmabuf->dbuf.list, list) {
  12620. list_del_init(&d_buf->list);
  12621. lpfc_in_buf_free(vport->phba, d_buf);
  12622. }
  12623. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12624. }
  12625. if (abort_count)
  12626. lpfc_update_rcv_time_stamp(vport);
  12627. }
  12628. /**
  12629. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12630. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12631. *
  12632. * This function searches through the existing incomplete sequences that have
  12633. * been sent to this @vport. If the frame matches one of the incomplete
  12634. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12635. * make up that sequence. If no sequence is found that matches this frame then
  12636. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12637. * This function returns a pointer to the first dmabuf in the sequence list that
  12638. * the frame was linked to.
  12639. **/
  12640. static struct hbq_dmabuf *
  12641. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12642. {
  12643. struct fc_frame_header *new_hdr;
  12644. struct fc_frame_header *temp_hdr;
  12645. struct lpfc_dmabuf *d_buf;
  12646. struct lpfc_dmabuf *h_buf;
  12647. struct hbq_dmabuf *seq_dmabuf = NULL;
  12648. struct hbq_dmabuf *temp_dmabuf = NULL;
  12649. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12650. dmabuf->time_stamp = jiffies;
  12651. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12652. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12653. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12654. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12655. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12656. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12657. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12658. continue;
  12659. /* found a pending sequence that matches this frame */
  12660. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12661. break;
  12662. }
  12663. if (!seq_dmabuf) {
  12664. /*
  12665. * This indicates first frame received for this sequence.
  12666. * Queue the buffer on the vport's rcv_buffer_list.
  12667. */
  12668. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12669. lpfc_update_rcv_time_stamp(vport);
  12670. return dmabuf;
  12671. }
  12672. temp_hdr = seq_dmabuf->hbuf.virt;
  12673. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  12674. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12675. list_del_init(&seq_dmabuf->hbuf.list);
  12676. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12677. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12678. lpfc_update_rcv_time_stamp(vport);
  12679. return dmabuf;
  12680. }
  12681. /* move this sequence to the tail to indicate a young sequence */
  12682. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12683. seq_dmabuf->time_stamp = jiffies;
  12684. lpfc_update_rcv_time_stamp(vport);
  12685. if (list_empty(&seq_dmabuf->dbuf.list)) {
  12686. temp_hdr = dmabuf->hbuf.virt;
  12687. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12688. return seq_dmabuf;
  12689. }
  12690. /* find the correct place in the sequence to insert this frame */
  12691. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  12692. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12693. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  12694. /*
  12695. * If the frame's sequence count is greater than the frame on
  12696. * the list then insert the frame right after this frame
  12697. */
  12698. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  12699. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12700. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  12701. return seq_dmabuf;
  12702. }
  12703. }
  12704. return NULL;
  12705. }
  12706. /**
  12707. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  12708. * @vport: pointer to a vitural port
  12709. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12710. *
  12711. * This function tries to abort from the partially assembed sequence, described
  12712. * by the information from basic abbort @dmabuf. It checks to see whether such
  12713. * partially assembled sequence held by the driver. If so, it shall free up all
  12714. * the frames from the partially assembled sequence.
  12715. *
  12716. * Return
  12717. * true -- if there is matching partially assembled sequence present and all
  12718. * the frames freed with the sequence;
  12719. * false -- if there is no matching partially assembled sequence present so
  12720. * nothing got aborted in the lower layer driver
  12721. **/
  12722. static bool
  12723. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  12724. struct hbq_dmabuf *dmabuf)
  12725. {
  12726. struct fc_frame_header *new_hdr;
  12727. struct fc_frame_header *temp_hdr;
  12728. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  12729. struct hbq_dmabuf *seq_dmabuf = NULL;
  12730. /* Use the hdr_buf to find the sequence that matches this frame */
  12731. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12732. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  12733. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12734. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12735. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12736. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12737. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12738. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12739. continue;
  12740. /* found a pending sequence that matches this frame */
  12741. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12742. break;
  12743. }
  12744. /* Free up all the frames from the partially assembled sequence */
  12745. if (seq_dmabuf) {
  12746. list_for_each_entry_safe(d_buf, n_buf,
  12747. &seq_dmabuf->dbuf.list, list) {
  12748. list_del_init(&d_buf->list);
  12749. lpfc_in_buf_free(vport->phba, d_buf);
  12750. }
  12751. return true;
  12752. }
  12753. return false;
  12754. }
  12755. /**
  12756. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  12757. * @phba: Pointer to HBA context object.
  12758. * @cmd_iocbq: pointer to the command iocbq structure.
  12759. * @rsp_iocbq: pointer to the response iocbq structure.
  12760. *
  12761. * This function handles the sequence abort response iocb command complete
  12762. * event. It properly releases the memory allocated to the sequence abort
  12763. * accept iocb.
  12764. **/
  12765. static void
  12766. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  12767. struct lpfc_iocbq *cmd_iocbq,
  12768. struct lpfc_iocbq *rsp_iocbq)
  12769. {
  12770. if (cmd_iocbq)
  12771. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  12772. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  12773. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  12774. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12775. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  12776. rsp_iocbq->iocb.ulpStatus,
  12777. rsp_iocbq->iocb.un.ulpWord[4]);
  12778. }
  12779. /**
  12780. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  12781. * @phba: Pointer to HBA context object.
  12782. * @xri: xri id in transaction.
  12783. *
  12784. * This function validates the xri maps to the known range of XRIs allocated an
  12785. * used by the driver.
  12786. **/
  12787. uint16_t
  12788. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  12789. uint16_t xri)
  12790. {
  12791. int i;
  12792. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  12793. if (xri == phba->sli4_hba.xri_ids[i])
  12794. return i;
  12795. }
  12796. return NO_XRI;
  12797. }
  12798. /**
  12799. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  12800. * @phba: Pointer to HBA context object.
  12801. * @fc_hdr: pointer to a FC frame header.
  12802. *
  12803. * This function sends a basic response to a previous unsol sequence abort
  12804. * event after aborting the sequence handling.
  12805. **/
  12806. static void
  12807. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  12808. struct fc_frame_header *fc_hdr)
  12809. {
  12810. struct lpfc_iocbq *ctiocb = NULL;
  12811. struct lpfc_nodelist *ndlp;
  12812. uint16_t oxid, rxid, xri, lxri;
  12813. uint32_t sid, fctl;
  12814. IOCB_t *icmd;
  12815. int rc;
  12816. if (!lpfc_is_link_up(phba))
  12817. return;
  12818. sid = sli4_sid_from_fc_hdr(fc_hdr);
  12819. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  12820. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  12821. ndlp = lpfc_findnode_did(phba->pport, sid);
  12822. if (!ndlp) {
  12823. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12824. "1268 Find ndlp returned NULL for oxid:x%x "
  12825. "SID:x%x\n", oxid, sid);
  12826. return;
  12827. }
  12828. /* Allocate buffer for rsp iocb */
  12829. ctiocb = lpfc_sli_get_iocbq(phba);
  12830. if (!ctiocb)
  12831. return;
  12832. /* Extract the F_CTL field from FC_HDR */
  12833. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  12834. icmd = &ctiocb->iocb;
  12835. icmd->un.xseq64.bdl.bdeSize = 0;
  12836. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  12837. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  12838. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  12839. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  12840. /* Fill in the rest of iocb fields */
  12841. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  12842. icmd->ulpBdeCount = 0;
  12843. icmd->ulpLe = 1;
  12844. icmd->ulpClass = CLASS3;
  12845. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  12846. ctiocb->context1 = ndlp;
  12847. ctiocb->iocb_cmpl = NULL;
  12848. ctiocb->vport = phba->pport;
  12849. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  12850. ctiocb->sli4_lxritag = NO_XRI;
  12851. ctiocb->sli4_xritag = NO_XRI;
  12852. if (fctl & FC_FC_EX_CTX)
  12853. /* Exchange responder sent the abort so we
  12854. * own the oxid.
  12855. */
  12856. xri = oxid;
  12857. else
  12858. xri = rxid;
  12859. lxri = lpfc_sli4_xri_inrange(phba, xri);
  12860. if (lxri != NO_XRI)
  12861. lpfc_set_rrq_active(phba, ndlp, lxri,
  12862. (xri == oxid) ? rxid : oxid, 0);
  12863. /* If the oxid maps to the FCP XRI range or if it is out of range,
  12864. * send a BLS_RJT. The driver no longer has that exchange.
  12865. * Override the IOCB for a BA_RJT.
  12866. */
  12867. if (xri > (phba->sli4_hba.max_cfg_param.max_xri +
  12868. phba->sli4_hba.max_cfg_param.xri_base) ||
  12869. xri > (lpfc_sli4_get_els_iocb_cnt(phba) +
  12870. phba->sli4_hba.max_cfg_param.xri_base)) {
  12871. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  12872. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  12873. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  12874. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  12875. }
  12876. if (fctl & FC_FC_EX_CTX) {
  12877. /* ABTS sent by responder to CT exchange, construction
  12878. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  12879. * field and RX_ID from ABTS for RX_ID field.
  12880. */
  12881. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  12882. } else {
  12883. /* ABTS sent by initiator to CT exchange, construction
  12884. * of BA_ACC will need to allocate a new XRI as for the
  12885. * XRI_TAG field.
  12886. */
  12887. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  12888. }
  12889. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  12890. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  12891. /* Xmit CT abts response on exchange <xid> */
  12892. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12893. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  12894. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  12895. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  12896. if (rc == IOCB_ERROR) {
  12897. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  12898. "2925 Failed to issue CT ABTS RSP x%x on "
  12899. "xri x%x, Data x%x\n",
  12900. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  12901. phba->link_state);
  12902. lpfc_sli_release_iocbq(phba, ctiocb);
  12903. }
  12904. }
  12905. /**
  12906. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  12907. * @vport: Pointer to the vport on which this sequence was received
  12908. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12909. *
  12910. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  12911. * receive sequence is only partially assembed by the driver, it shall abort
  12912. * the partially assembled frames for the sequence. Otherwise, if the
  12913. * unsolicited receive sequence has been completely assembled and passed to
  12914. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  12915. * unsolicited sequence has been aborted. After that, it will issue a basic
  12916. * accept to accept the abort.
  12917. **/
  12918. void
  12919. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  12920. struct hbq_dmabuf *dmabuf)
  12921. {
  12922. struct lpfc_hba *phba = vport->phba;
  12923. struct fc_frame_header fc_hdr;
  12924. uint32_t fctl;
  12925. bool abts_par;
  12926. /* Make a copy of fc_hdr before the dmabuf being released */
  12927. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  12928. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  12929. if (fctl & FC_FC_EX_CTX) {
  12930. /*
  12931. * ABTS sent by responder to exchange, just free the buffer
  12932. */
  12933. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  12934. } else {
  12935. /*
  12936. * ABTS sent by initiator to exchange, need to do cleanup
  12937. */
  12938. /* Try to abort partially assembled seq */
  12939. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  12940. /* Send abort to ULP if partially seq abort failed */
  12941. if (abts_par == false)
  12942. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  12943. else
  12944. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  12945. }
  12946. /* Send basic accept (BA_ACC) to the abort requester */
  12947. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  12948. }
  12949. /**
  12950. * lpfc_seq_complete - Indicates if a sequence is complete
  12951. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12952. *
  12953. * This function checks the sequence, starting with the frame described by
  12954. * @dmabuf, to see if all the frames associated with this sequence are present.
  12955. * the frames associated with this sequence are linked to the @dmabuf using the
  12956. * dbuf list. This function looks for two major things. 1) That the first frame
  12957. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  12958. * set. 3) That there are no holes in the sequence count. The function will
  12959. * return 1 when the sequence is complete, otherwise it will return 0.
  12960. **/
  12961. static int
  12962. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  12963. {
  12964. struct fc_frame_header *hdr;
  12965. struct lpfc_dmabuf *d_buf;
  12966. struct hbq_dmabuf *seq_dmabuf;
  12967. uint32_t fctl;
  12968. int seq_count = 0;
  12969. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12970. /* make sure first fame of sequence has a sequence count of zero */
  12971. if (hdr->fh_seq_cnt != seq_count)
  12972. return 0;
  12973. fctl = (hdr->fh_f_ctl[0] << 16 |
  12974. hdr->fh_f_ctl[1] << 8 |
  12975. hdr->fh_f_ctl[2]);
  12976. /* If last frame of sequence we can return success. */
  12977. if (fctl & FC_FC_END_SEQ)
  12978. return 1;
  12979. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  12980. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12981. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  12982. /* If there is a hole in the sequence count then fail. */
  12983. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  12984. return 0;
  12985. fctl = (hdr->fh_f_ctl[0] << 16 |
  12986. hdr->fh_f_ctl[1] << 8 |
  12987. hdr->fh_f_ctl[2]);
  12988. /* If last frame of sequence we can return success. */
  12989. if (fctl & FC_FC_END_SEQ)
  12990. return 1;
  12991. }
  12992. return 0;
  12993. }
  12994. /**
  12995. * lpfc_prep_seq - Prep sequence for ULP processing
  12996. * @vport: Pointer to the vport on which this sequence was received
  12997. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12998. *
  12999. * This function takes a sequence, described by a list of frames, and creates
  13000. * a list of iocbq structures to describe the sequence. This iocbq list will be
  13001. * used to issue to the generic unsolicited sequence handler. This routine
  13002. * returns a pointer to the first iocbq in the list. If the function is unable
  13003. * to allocate an iocbq then it throw out the received frames that were not
  13004. * able to be described and return a pointer to the first iocbq. If unable to
  13005. * allocate any iocbqs (including the first) this function will return NULL.
  13006. **/
  13007. static struct lpfc_iocbq *
  13008. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  13009. {
  13010. struct hbq_dmabuf *hbq_buf;
  13011. struct lpfc_dmabuf *d_buf, *n_buf;
  13012. struct lpfc_iocbq *first_iocbq, *iocbq;
  13013. struct fc_frame_header *fc_hdr;
  13014. uint32_t sid;
  13015. uint32_t len, tot_len;
  13016. struct ulp_bde64 *pbde;
  13017. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13018. /* remove from receive buffer list */
  13019. list_del_init(&seq_dmabuf->hbuf.list);
  13020. lpfc_update_rcv_time_stamp(vport);
  13021. /* get the Remote Port's SID */
  13022. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13023. tot_len = 0;
  13024. /* Get an iocbq struct to fill in. */
  13025. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13026. if (first_iocbq) {
  13027. /* Initialize the first IOCB. */
  13028. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13029. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13030. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  13031. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  13032. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
  13033. first_iocbq->iocb.un.rcvels.parmRo =
  13034. sli4_did_from_fc_hdr(fc_hdr);
  13035. first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
  13036. } else
  13037. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13038. first_iocbq->iocb.ulpContext = NO_XRI;
  13039. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13040. be16_to_cpu(fc_hdr->fh_ox_id);
  13041. /* iocbq is prepped for internal consumption. Physical vpi. */
  13042. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13043. vport->phba->vpi_ids[vport->vpi];
  13044. /* put the first buffer into the first IOCBq */
  13045. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13046. first_iocbq->context3 = NULL;
  13047. first_iocbq->iocb.ulpBdeCount = 1;
  13048. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13049. LPFC_DATA_BUF_SIZE;
  13050. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13051. tot_len = bf_get(lpfc_rcqe_length,
  13052. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13053. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13054. }
  13055. iocbq = first_iocbq;
  13056. /*
  13057. * Each IOCBq can have two Buffers assigned, so go through the list
  13058. * of buffers for this sequence and save two buffers in each IOCBq
  13059. */
  13060. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13061. if (!iocbq) {
  13062. lpfc_in_buf_free(vport->phba, d_buf);
  13063. continue;
  13064. }
  13065. if (!iocbq->context3) {
  13066. iocbq->context3 = d_buf;
  13067. iocbq->iocb.ulpBdeCount++;
  13068. pbde = (struct ulp_bde64 *)
  13069. &iocbq->iocb.unsli3.sli3Words[4];
  13070. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13071. /* We need to get the size out of the right CQE */
  13072. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13073. len = bf_get(lpfc_rcqe_length,
  13074. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13075. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13076. tot_len += len;
  13077. } else {
  13078. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13079. if (!iocbq) {
  13080. if (first_iocbq) {
  13081. first_iocbq->iocb.ulpStatus =
  13082. IOSTAT_FCP_RSP_ERROR;
  13083. first_iocbq->iocb.un.ulpWord[4] =
  13084. IOERR_NO_RESOURCES;
  13085. }
  13086. lpfc_in_buf_free(vport->phba, d_buf);
  13087. continue;
  13088. }
  13089. iocbq->context2 = d_buf;
  13090. iocbq->context3 = NULL;
  13091. iocbq->iocb.ulpBdeCount = 1;
  13092. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13093. LPFC_DATA_BUF_SIZE;
  13094. /* We need to get the size out of the right CQE */
  13095. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13096. len = bf_get(lpfc_rcqe_length,
  13097. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13098. tot_len += len;
  13099. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13100. iocbq->iocb.un.rcvels.remoteID = sid;
  13101. list_add_tail(&iocbq->list, &first_iocbq->list);
  13102. }
  13103. }
  13104. return first_iocbq;
  13105. }
  13106. static void
  13107. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13108. struct hbq_dmabuf *seq_dmabuf)
  13109. {
  13110. struct fc_frame_header *fc_hdr;
  13111. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13112. struct lpfc_hba *phba = vport->phba;
  13113. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13114. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13115. if (!iocbq) {
  13116. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13117. "2707 Ring %d handler: Failed to allocate "
  13118. "iocb Rctl x%x Type x%x received\n",
  13119. LPFC_ELS_RING,
  13120. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13121. return;
  13122. }
  13123. if (!lpfc_complete_unsol_iocb(phba,
  13124. &phba->sli.ring[LPFC_ELS_RING],
  13125. iocbq, fc_hdr->fh_r_ctl,
  13126. fc_hdr->fh_type))
  13127. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13128. "2540 Ring %d handler: unexpected Rctl "
  13129. "x%x Type x%x received\n",
  13130. LPFC_ELS_RING,
  13131. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13132. /* Free iocb created in lpfc_prep_seq */
  13133. list_for_each_entry_safe(curr_iocb, next_iocb,
  13134. &iocbq->list, list) {
  13135. list_del_init(&curr_iocb->list);
  13136. lpfc_sli_release_iocbq(phba, curr_iocb);
  13137. }
  13138. lpfc_sli_release_iocbq(phba, iocbq);
  13139. }
  13140. /**
  13141. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13142. * @phba: Pointer to HBA context object.
  13143. *
  13144. * This function is called with no lock held. This function processes all
  13145. * the received buffers and gives it to upper layers when a received buffer
  13146. * indicates that it is the final frame in the sequence. The interrupt
  13147. * service routine processes received buffers at interrupt contexts and adds
  13148. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13149. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13150. * appropriate receive function when the final frame in a sequence is received.
  13151. **/
  13152. void
  13153. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13154. struct hbq_dmabuf *dmabuf)
  13155. {
  13156. struct hbq_dmabuf *seq_dmabuf;
  13157. struct fc_frame_header *fc_hdr;
  13158. struct lpfc_vport *vport;
  13159. uint32_t fcfi;
  13160. uint32_t did;
  13161. /* Process each received buffer */
  13162. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13163. /* check to see if this a valid type of frame */
  13164. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13165. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13166. return;
  13167. }
  13168. if ((bf_get(lpfc_cqe_code,
  13169. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13170. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13171. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13172. else
  13173. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13174. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13175. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13176. if (!vport) {
  13177. /* throw out the frame */
  13178. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13179. return;
  13180. }
  13181. /* d_id this frame is directed to */
  13182. did = sli4_did_from_fc_hdr(fc_hdr);
  13183. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  13184. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  13185. (did != Fabric_DID)) {
  13186. /*
  13187. * Throw out the frame if we are not pt2pt.
  13188. * The pt2pt protocol allows for discovery frames
  13189. * to be received without a registered VPI.
  13190. */
  13191. if (!(vport->fc_flag & FC_PT2PT) ||
  13192. (phba->link_state == LPFC_HBA_READY)) {
  13193. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13194. return;
  13195. }
  13196. }
  13197. /* Handle the basic abort sequence (BA_ABTS) event */
  13198. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13199. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13200. return;
  13201. }
  13202. /* Link this frame */
  13203. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13204. if (!seq_dmabuf) {
  13205. /* unable to add frame to vport - throw it out */
  13206. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13207. return;
  13208. }
  13209. /* If not last frame in sequence continue processing frames. */
  13210. if (!lpfc_seq_complete(seq_dmabuf))
  13211. return;
  13212. /* Send the complete sequence to the upper layer protocol */
  13213. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13214. }
  13215. /**
  13216. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13217. * @phba: pointer to lpfc hba data structure.
  13218. *
  13219. * This routine is invoked to post rpi header templates to the
  13220. * HBA consistent with the SLI-4 interface spec. This routine
  13221. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13222. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13223. *
  13224. * This routine does not require any locks. It's usage is expected
  13225. * to be driver load or reset recovery when the driver is
  13226. * sequential.
  13227. *
  13228. * Return codes
  13229. * 0 - successful
  13230. * -EIO - The mailbox failed to complete successfully.
  13231. * When this error occurs, the driver is not guaranteed
  13232. * to have any rpi regions posted to the device and
  13233. * must either attempt to repost the regions or take a
  13234. * fatal error.
  13235. **/
  13236. int
  13237. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13238. {
  13239. struct lpfc_rpi_hdr *rpi_page;
  13240. uint32_t rc = 0;
  13241. uint16_t lrpi = 0;
  13242. /* SLI4 ports that support extents do not require RPI headers. */
  13243. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13244. goto exit;
  13245. if (phba->sli4_hba.extents_in_use)
  13246. return -EIO;
  13247. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13248. /*
  13249. * Assign the rpi headers a physical rpi only if the driver
  13250. * has not initialized those resources. A port reset only
  13251. * needs the headers posted.
  13252. */
  13253. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13254. LPFC_RPI_RSRC_RDY)
  13255. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13256. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13257. if (rc != MBX_SUCCESS) {
  13258. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13259. "2008 Error %d posting all rpi "
  13260. "headers\n", rc);
  13261. rc = -EIO;
  13262. break;
  13263. }
  13264. }
  13265. exit:
  13266. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13267. LPFC_RPI_RSRC_RDY);
  13268. return rc;
  13269. }
  13270. /**
  13271. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13272. * @phba: pointer to lpfc hba data structure.
  13273. * @rpi_page: pointer to the rpi memory region.
  13274. *
  13275. * This routine is invoked to post a single rpi header to the
  13276. * HBA consistent with the SLI-4 interface spec. This memory region
  13277. * maps up to 64 rpi context regions.
  13278. *
  13279. * Return codes
  13280. * 0 - successful
  13281. * -ENOMEM - No available memory
  13282. * -EIO - The mailbox failed to complete successfully.
  13283. **/
  13284. int
  13285. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13286. {
  13287. LPFC_MBOXQ_t *mboxq;
  13288. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13289. uint32_t rc = 0;
  13290. uint32_t shdr_status, shdr_add_status;
  13291. union lpfc_sli4_cfg_shdr *shdr;
  13292. /* SLI4 ports that support extents do not require RPI headers. */
  13293. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13294. return rc;
  13295. if (phba->sli4_hba.extents_in_use)
  13296. return -EIO;
  13297. /* The port is notified of the header region via a mailbox command. */
  13298. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13299. if (!mboxq) {
  13300. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13301. "2001 Unable to allocate memory for issuing "
  13302. "SLI_CONFIG_SPECIAL mailbox command\n");
  13303. return -ENOMEM;
  13304. }
  13305. /* Post all rpi memory regions to the port. */
  13306. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13307. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13308. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13309. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13310. sizeof(struct lpfc_sli4_cfg_mhdr),
  13311. LPFC_SLI4_MBX_EMBED);
  13312. /* Post the physical rpi to the port for this rpi header. */
  13313. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13314. rpi_page->start_rpi);
  13315. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13316. hdr_tmpl, rpi_page->page_count);
  13317. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13318. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13319. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13320. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13321. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13322. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13323. if (rc != MBX_TIMEOUT)
  13324. mempool_free(mboxq, phba->mbox_mem_pool);
  13325. if (shdr_status || shdr_add_status || rc) {
  13326. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13327. "2514 POST_RPI_HDR mailbox failed with "
  13328. "status x%x add_status x%x, mbx status x%x\n",
  13329. shdr_status, shdr_add_status, rc);
  13330. rc = -ENXIO;
  13331. }
  13332. return rc;
  13333. }
  13334. /**
  13335. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13336. * @phba: pointer to lpfc hba data structure.
  13337. *
  13338. * This routine is invoked to post rpi header templates to the
  13339. * HBA consistent with the SLI-4 interface spec. This routine
  13340. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13341. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13342. *
  13343. * Returns
  13344. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13345. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13346. **/
  13347. int
  13348. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13349. {
  13350. unsigned long rpi;
  13351. uint16_t max_rpi, rpi_limit;
  13352. uint16_t rpi_remaining, lrpi = 0;
  13353. struct lpfc_rpi_hdr *rpi_hdr;
  13354. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13355. rpi_limit = phba->sli4_hba.next_rpi;
  13356. /*
  13357. * Fetch the next logical rpi. Because this index is logical,
  13358. * the driver starts at 0 each time.
  13359. */
  13360. spin_lock_irq(&phba->hbalock);
  13361. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13362. if (rpi >= rpi_limit)
  13363. rpi = LPFC_RPI_ALLOC_ERROR;
  13364. else {
  13365. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13366. phba->sli4_hba.max_cfg_param.rpi_used++;
  13367. phba->sli4_hba.rpi_count++;
  13368. }
  13369. /*
  13370. * Don't try to allocate more rpi header regions if the device limit
  13371. * has been exhausted.
  13372. */
  13373. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13374. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13375. spin_unlock_irq(&phba->hbalock);
  13376. return rpi;
  13377. }
  13378. /*
  13379. * RPI header postings are not required for SLI4 ports capable of
  13380. * extents.
  13381. */
  13382. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13383. spin_unlock_irq(&phba->hbalock);
  13384. return rpi;
  13385. }
  13386. /*
  13387. * If the driver is running low on rpi resources, allocate another
  13388. * page now. Note that the next_rpi value is used because
  13389. * it represents how many are actually in use whereas max_rpi notes
  13390. * how many are supported max by the device.
  13391. */
  13392. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13393. spin_unlock_irq(&phba->hbalock);
  13394. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13395. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13396. if (!rpi_hdr) {
  13397. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13398. "2002 Error Could not grow rpi "
  13399. "count\n");
  13400. } else {
  13401. lrpi = rpi_hdr->start_rpi;
  13402. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13403. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13404. }
  13405. }
  13406. return rpi;
  13407. }
  13408. /**
  13409. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13410. * @phba: pointer to lpfc hba data structure.
  13411. *
  13412. * This routine is invoked to release an rpi to the pool of
  13413. * available rpis maintained by the driver.
  13414. **/
  13415. void
  13416. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13417. {
  13418. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13419. phba->sli4_hba.rpi_count--;
  13420. phba->sli4_hba.max_cfg_param.rpi_used--;
  13421. }
  13422. }
  13423. /**
  13424. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13425. * @phba: pointer to lpfc hba data structure.
  13426. *
  13427. * This routine is invoked to release an rpi to the pool of
  13428. * available rpis maintained by the driver.
  13429. **/
  13430. void
  13431. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13432. {
  13433. spin_lock_irq(&phba->hbalock);
  13434. __lpfc_sli4_free_rpi(phba, rpi);
  13435. spin_unlock_irq(&phba->hbalock);
  13436. }
  13437. /**
  13438. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13439. * @phba: pointer to lpfc hba data structure.
  13440. *
  13441. * This routine is invoked to remove the memory region that
  13442. * provided rpi via a bitmask.
  13443. **/
  13444. void
  13445. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13446. {
  13447. kfree(phba->sli4_hba.rpi_bmask);
  13448. kfree(phba->sli4_hba.rpi_ids);
  13449. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13450. }
  13451. /**
  13452. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13453. * @phba: pointer to lpfc hba data structure.
  13454. *
  13455. * This routine is invoked to remove the memory region that
  13456. * provided rpi via a bitmask.
  13457. **/
  13458. int
  13459. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  13460. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  13461. {
  13462. LPFC_MBOXQ_t *mboxq;
  13463. struct lpfc_hba *phba = ndlp->phba;
  13464. int rc;
  13465. /* The port is notified of the header region via a mailbox command. */
  13466. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13467. if (!mboxq)
  13468. return -ENOMEM;
  13469. /* Post all rpi memory regions to the port. */
  13470. lpfc_resume_rpi(mboxq, ndlp);
  13471. if (cmpl) {
  13472. mboxq->mbox_cmpl = cmpl;
  13473. mboxq->context1 = arg;
  13474. mboxq->context2 = ndlp;
  13475. } else
  13476. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  13477. mboxq->vport = ndlp->vport;
  13478. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13479. if (rc == MBX_NOT_FINISHED) {
  13480. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13481. "2010 Resume RPI Mailbox failed "
  13482. "status %d, mbxStatus x%x\n", rc,
  13483. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13484. mempool_free(mboxq, phba->mbox_mem_pool);
  13485. return -EIO;
  13486. }
  13487. return 0;
  13488. }
  13489. /**
  13490. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13491. * @vport: Pointer to the vport for which the vpi is being initialized
  13492. *
  13493. * This routine is invoked to activate a vpi with the port.
  13494. *
  13495. * Returns:
  13496. * 0 success
  13497. * -Evalue otherwise
  13498. **/
  13499. int
  13500. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13501. {
  13502. LPFC_MBOXQ_t *mboxq;
  13503. int rc = 0;
  13504. int retval = MBX_SUCCESS;
  13505. uint32_t mbox_tmo;
  13506. struct lpfc_hba *phba = vport->phba;
  13507. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13508. if (!mboxq)
  13509. return -ENOMEM;
  13510. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13511. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13512. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13513. if (rc != MBX_SUCCESS) {
  13514. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13515. "2022 INIT VPI Mailbox failed "
  13516. "status %d, mbxStatus x%x\n", rc,
  13517. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13518. retval = -EIO;
  13519. }
  13520. if (rc != MBX_TIMEOUT)
  13521. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13522. return retval;
  13523. }
  13524. /**
  13525. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13526. * @phba: pointer to lpfc hba data structure.
  13527. * @mboxq: Pointer to mailbox object.
  13528. *
  13529. * This routine is invoked to manually add a single FCF record. The caller
  13530. * must pass a completely initialized FCF_Record. This routine takes
  13531. * care of the nonembedded mailbox operations.
  13532. **/
  13533. static void
  13534. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13535. {
  13536. void *virt_addr;
  13537. union lpfc_sli4_cfg_shdr *shdr;
  13538. uint32_t shdr_status, shdr_add_status;
  13539. virt_addr = mboxq->sge_array->addr[0];
  13540. /* The IOCTL status is embedded in the mailbox subheader. */
  13541. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13542. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13543. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13544. if ((shdr_status || shdr_add_status) &&
  13545. (shdr_status != STATUS_FCF_IN_USE))
  13546. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13547. "2558 ADD_FCF_RECORD mailbox failed with "
  13548. "status x%x add_status x%x\n",
  13549. shdr_status, shdr_add_status);
  13550. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13551. }
  13552. /**
  13553. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13554. * @phba: pointer to lpfc hba data structure.
  13555. * @fcf_record: pointer to the initialized fcf record to add.
  13556. *
  13557. * This routine is invoked to manually add a single FCF record. The caller
  13558. * must pass a completely initialized FCF_Record. This routine takes
  13559. * care of the nonembedded mailbox operations.
  13560. **/
  13561. int
  13562. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13563. {
  13564. int rc = 0;
  13565. LPFC_MBOXQ_t *mboxq;
  13566. uint8_t *bytep;
  13567. void *virt_addr;
  13568. dma_addr_t phys_addr;
  13569. struct lpfc_mbx_sge sge;
  13570. uint32_t alloc_len, req_len;
  13571. uint32_t fcfindex;
  13572. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13573. if (!mboxq) {
  13574. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13575. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13576. return -ENOMEM;
  13577. }
  13578. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13579. sizeof(uint32_t);
  13580. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13581. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13582. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13583. req_len, LPFC_SLI4_MBX_NEMBED);
  13584. if (alloc_len < req_len) {
  13585. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13586. "2523 Allocated DMA memory size (x%x) is "
  13587. "less than the requested DMA memory "
  13588. "size (x%x)\n", alloc_len, req_len);
  13589. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13590. return -ENOMEM;
  13591. }
  13592. /*
  13593. * Get the first SGE entry from the non-embedded DMA memory. This
  13594. * routine only uses a single SGE.
  13595. */
  13596. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13597. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13598. virt_addr = mboxq->sge_array->addr[0];
  13599. /*
  13600. * Configure the FCF record for FCFI 0. This is the driver's
  13601. * hardcoded default and gets used in nonFIP mode.
  13602. */
  13603. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  13604. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  13605. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  13606. /*
  13607. * Copy the fcf_index and the FCF Record Data. The data starts after
  13608. * the FCoE header plus word10. The data copy needs to be endian
  13609. * correct.
  13610. */
  13611. bytep += sizeof(uint32_t);
  13612. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  13613. mboxq->vport = phba->pport;
  13614. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  13615. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13616. if (rc == MBX_NOT_FINISHED) {
  13617. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13618. "2515 ADD_FCF_RECORD mailbox failed with "
  13619. "status 0x%x\n", rc);
  13620. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13621. rc = -EIO;
  13622. } else
  13623. rc = 0;
  13624. return rc;
  13625. }
  13626. /**
  13627. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  13628. * @phba: pointer to lpfc hba data structure.
  13629. * @fcf_record: pointer to the fcf record to write the default data.
  13630. * @fcf_index: FCF table entry index.
  13631. *
  13632. * This routine is invoked to build the driver's default FCF record. The
  13633. * values used are hardcoded. This routine handles memory initialization.
  13634. *
  13635. **/
  13636. void
  13637. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  13638. struct fcf_record *fcf_record,
  13639. uint16_t fcf_index)
  13640. {
  13641. memset(fcf_record, 0, sizeof(struct fcf_record));
  13642. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  13643. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  13644. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  13645. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  13646. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  13647. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  13648. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  13649. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  13650. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  13651. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  13652. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  13653. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  13654. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  13655. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  13656. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  13657. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  13658. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  13659. /* Set the VLAN bit map */
  13660. if (phba->valid_vlan) {
  13661. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  13662. = 1 << (phba->vlan_id % 8);
  13663. }
  13664. }
  13665. /**
  13666. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  13667. * @phba: pointer to lpfc hba data structure.
  13668. * @fcf_index: FCF table entry offset.
  13669. *
  13670. * This routine is invoked to scan the entire FCF table by reading FCF
  13671. * record and processing it one at a time starting from the @fcf_index
  13672. * for initial FCF discovery or fast FCF failover rediscovery.
  13673. *
  13674. * Return 0 if the mailbox command is submitted successfully, none 0
  13675. * otherwise.
  13676. **/
  13677. int
  13678. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13679. {
  13680. int rc = 0, error;
  13681. LPFC_MBOXQ_t *mboxq;
  13682. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  13683. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  13684. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13685. if (!mboxq) {
  13686. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13687. "2000 Failed to allocate mbox for "
  13688. "READ_FCF cmd\n");
  13689. error = -ENOMEM;
  13690. goto fail_fcf_scan;
  13691. }
  13692. /* Construct the read FCF record mailbox command */
  13693. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13694. if (rc) {
  13695. error = -EINVAL;
  13696. goto fail_fcf_scan;
  13697. }
  13698. /* Issue the mailbox command asynchronously */
  13699. mboxq->vport = phba->pport;
  13700. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  13701. spin_lock_irq(&phba->hbalock);
  13702. phba->hba_flag |= FCF_TS_INPROG;
  13703. spin_unlock_irq(&phba->hbalock);
  13704. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13705. if (rc == MBX_NOT_FINISHED)
  13706. error = -EIO;
  13707. else {
  13708. /* Reset eligible FCF count for new scan */
  13709. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  13710. phba->fcf.eligible_fcf_cnt = 0;
  13711. error = 0;
  13712. }
  13713. fail_fcf_scan:
  13714. if (error) {
  13715. if (mboxq)
  13716. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13717. /* FCF scan failed, clear FCF_TS_INPROG flag */
  13718. spin_lock_irq(&phba->hbalock);
  13719. phba->hba_flag &= ~FCF_TS_INPROG;
  13720. spin_unlock_irq(&phba->hbalock);
  13721. }
  13722. return error;
  13723. }
  13724. /**
  13725. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  13726. * @phba: pointer to lpfc hba data structure.
  13727. * @fcf_index: FCF table entry offset.
  13728. *
  13729. * This routine is invoked to read an FCF record indicated by @fcf_index
  13730. * and to use it for FLOGI roundrobin FCF failover.
  13731. *
  13732. * Return 0 if the mailbox command is submitted successfully, none 0
  13733. * otherwise.
  13734. **/
  13735. int
  13736. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13737. {
  13738. int rc = 0, error;
  13739. LPFC_MBOXQ_t *mboxq;
  13740. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13741. if (!mboxq) {
  13742. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13743. "2763 Failed to allocate mbox for "
  13744. "READ_FCF cmd\n");
  13745. error = -ENOMEM;
  13746. goto fail_fcf_read;
  13747. }
  13748. /* Construct the read FCF record mailbox command */
  13749. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13750. if (rc) {
  13751. error = -EINVAL;
  13752. goto fail_fcf_read;
  13753. }
  13754. /* Issue the mailbox command asynchronously */
  13755. mboxq->vport = phba->pport;
  13756. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  13757. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13758. if (rc == MBX_NOT_FINISHED)
  13759. error = -EIO;
  13760. else
  13761. error = 0;
  13762. fail_fcf_read:
  13763. if (error && mboxq)
  13764. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13765. return error;
  13766. }
  13767. /**
  13768. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  13769. * @phba: pointer to lpfc hba data structure.
  13770. * @fcf_index: FCF table entry offset.
  13771. *
  13772. * This routine is invoked to read an FCF record indicated by @fcf_index to
  13773. * determine whether it's eligible for FLOGI roundrobin failover list.
  13774. *
  13775. * Return 0 if the mailbox command is submitted successfully, none 0
  13776. * otherwise.
  13777. **/
  13778. int
  13779. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13780. {
  13781. int rc = 0, error;
  13782. LPFC_MBOXQ_t *mboxq;
  13783. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13784. if (!mboxq) {
  13785. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13786. "2758 Failed to allocate mbox for "
  13787. "READ_FCF cmd\n");
  13788. error = -ENOMEM;
  13789. goto fail_fcf_read;
  13790. }
  13791. /* Construct the read FCF record mailbox command */
  13792. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13793. if (rc) {
  13794. error = -EINVAL;
  13795. goto fail_fcf_read;
  13796. }
  13797. /* Issue the mailbox command asynchronously */
  13798. mboxq->vport = phba->pport;
  13799. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  13800. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13801. if (rc == MBX_NOT_FINISHED)
  13802. error = -EIO;
  13803. else
  13804. error = 0;
  13805. fail_fcf_read:
  13806. if (error && mboxq)
  13807. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13808. return error;
  13809. }
  13810. /**
  13811. * lpfc_check_next_fcf_pri
  13812. * phba pointer to the lpfc_hba struct for this port.
  13813. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  13814. * routine when the rr_bmask is empty. The FCF indecies are put into the
  13815. * rr_bmask based on their priority level. Starting from the highest priority
  13816. * to the lowest. The most likely FCF candidate will be in the highest
  13817. * priority group. When this routine is called it searches the fcf_pri list for
  13818. * next lowest priority group and repopulates the rr_bmask with only those
  13819. * fcf_indexes.
  13820. * returns:
  13821. * 1=success 0=failure
  13822. **/
  13823. int
  13824. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  13825. {
  13826. uint16_t next_fcf_pri;
  13827. uint16_t last_index;
  13828. struct lpfc_fcf_pri *fcf_pri;
  13829. int rc;
  13830. int ret = 0;
  13831. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  13832. LPFC_SLI4_FCF_TBL_INDX_MAX);
  13833. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13834. "3060 Last IDX %d\n", last_index);
  13835. if (list_empty(&phba->fcf.fcf_pri_list)) {
  13836. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13837. "3061 Last IDX %d\n", last_index);
  13838. return 0; /* Empty rr list */
  13839. }
  13840. next_fcf_pri = 0;
  13841. /*
  13842. * Clear the rr_bmask and set all of the bits that are at this
  13843. * priority.
  13844. */
  13845. memset(phba->fcf.fcf_rr_bmask, 0,
  13846. sizeof(*phba->fcf.fcf_rr_bmask));
  13847. spin_lock_irq(&phba->hbalock);
  13848. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13849. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  13850. continue;
  13851. /*
  13852. * the 1st priority that has not FLOGI failed
  13853. * will be the highest.
  13854. */
  13855. if (!next_fcf_pri)
  13856. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13857. spin_unlock_irq(&phba->hbalock);
  13858. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13859. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13860. fcf_pri->fcf_rec.fcf_index);
  13861. if (rc)
  13862. return 0;
  13863. }
  13864. spin_lock_irq(&phba->hbalock);
  13865. }
  13866. /*
  13867. * if next_fcf_pri was not set above and the list is not empty then
  13868. * we have failed flogis on all of them. So reset flogi failed
  13869. * and start at the begining.
  13870. */
  13871. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  13872. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13873. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  13874. /*
  13875. * the 1st priority that has not FLOGI failed
  13876. * will be the highest.
  13877. */
  13878. if (!next_fcf_pri)
  13879. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13880. spin_unlock_irq(&phba->hbalock);
  13881. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13882. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13883. fcf_pri->fcf_rec.fcf_index);
  13884. if (rc)
  13885. return 0;
  13886. }
  13887. spin_lock_irq(&phba->hbalock);
  13888. }
  13889. } else
  13890. ret = 1;
  13891. spin_unlock_irq(&phba->hbalock);
  13892. return ret;
  13893. }
  13894. /**
  13895. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  13896. * @phba: pointer to lpfc hba data structure.
  13897. *
  13898. * This routine is to get the next eligible FCF record index in a round
  13899. * robin fashion. If the next eligible FCF record index equals to the
  13900. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  13901. * shall be returned, otherwise, the next eligible FCF record's index
  13902. * shall be returned.
  13903. **/
  13904. uint16_t
  13905. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  13906. {
  13907. uint16_t next_fcf_index;
  13908. /* Search start from next bit of currently registered FCF index */
  13909. next_priority:
  13910. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  13911. LPFC_SLI4_FCF_TBL_INDX_MAX;
  13912. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  13913. LPFC_SLI4_FCF_TBL_INDX_MAX,
  13914. next_fcf_index);
  13915. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  13916. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13917. /*
  13918. * If we have wrapped then we need to clear the bits that
  13919. * have been tested so that we can detect when we should
  13920. * change the priority level.
  13921. */
  13922. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  13923. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  13924. }
  13925. /* Check roundrobin failover list empty condition */
  13926. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  13927. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  13928. /*
  13929. * If next fcf index is not found check if there are lower
  13930. * Priority level fcf's in the fcf_priority list.
  13931. * Set up the rr_bmask with all of the avaiable fcf bits
  13932. * at that level and continue the selection process.
  13933. */
  13934. if (lpfc_check_next_fcf_pri_level(phba))
  13935. goto next_priority;
  13936. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  13937. "2844 No roundrobin failover FCF available\n");
  13938. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  13939. return LPFC_FCOE_FCF_NEXT_NONE;
  13940. else {
  13941. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  13942. "3063 Only FCF available idx %d, flag %x\n",
  13943. next_fcf_index,
  13944. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  13945. return next_fcf_index;
  13946. }
  13947. }
  13948. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  13949. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  13950. LPFC_FCF_FLOGI_FAILED)
  13951. goto next_priority;
  13952. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13953. "2845 Get next roundrobin failover FCF (x%x)\n",
  13954. next_fcf_index);
  13955. return next_fcf_index;
  13956. }
  13957. /**
  13958. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  13959. * @phba: pointer to lpfc hba data structure.
  13960. *
  13961. * This routine sets the FCF record index in to the eligible bmask for
  13962. * roundrobin failover search. It checks to make sure that the index
  13963. * does not go beyond the range of the driver allocated bmask dimension
  13964. * before setting the bit.
  13965. *
  13966. * Returns 0 if the index bit successfully set, otherwise, it returns
  13967. * -EINVAL.
  13968. **/
  13969. int
  13970. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  13971. {
  13972. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  13973. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13974. "2610 FCF (x%x) reached driver's book "
  13975. "keeping dimension:x%x\n",
  13976. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  13977. return -EINVAL;
  13978. }
  13979. /* Set the eligible FCF record index bmask */
  13980. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  13981. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13982. "2790 Set FCF (x%x) to roundrobin FCF failover "
  13983. "bmask\n", fcf_index);
  13984. return 0;
  13985. }
  13986. /**
  13987. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  13988. * @phba: pointer to lpfc hba data structure.
  13989. *
  13990. * This routine clears the FCF record index from the eligible bmask for
  13991. * roundrobin failover search. It checks to make sure that the index
  13992. * does not go beyond the range of the driver allocated bmask dimension
  13993. * before clearing the bit.
  13994. **/
  13995. void
  13996. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  13997. {
  13998. struct lpfc_fcf_pri *fcf_pri;
  13999. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14000. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14001. "2762 FCF (x%x) reached driver's book "
  14002. "keeping dimension:x%x\n",
  14003. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14004. return;
  14005. }
  14006. /* Clear the eligible FCF record index bmask */
  14007. spin_lock_irq(&phba->hbalock);
  14008. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14009. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  14010. list_del_init(&fcf_pri->list);
  14011. break;
  14012. }
  14013. }
  14014. spin_unlock_irq(&phba->hbalock);
  14015. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14016. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14017. "2791 Clear FCF (x%x) from roundrobin failover "
  14018. "bmask\n", fcf_index);
  14019. }
  14020. /**
  14021. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  14022. * @phba: pointer to lpfc hba data structure.
  14023. *
  14024. * This routine is the completion routine for the rediscover FCF table mailbox
  14025. * command. If the mailbox command returned failure, it will try to stop the
  14026. * FCF rediscover wait timer.
  14027. **/
  14028. void
  14029. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14030. {
  14031. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14032. uint32_t shdr_status, shdr_add_status;
  14033. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14034. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14035. &redisc_fcf->header.cfg_shdr.response);
  14036. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14037. &redisc_fcf->header.cfg_shdr.response);
  14038. if (shdr_status || shdr_add_status) {
  14039. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14040. "2746 Requesting for FCF rediscovery failed "
  14041. "status x%x add_status x%x\n",
  14042. shdr_status, shdr_add_status);
  14043. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14044. spin_lock_irq(&phba->hbalock);
  14045. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14046. spin_unlock_irq(&phba->hbalock);
  14047. /*
  14048. * CVL event triggered FCF rediscover request failed,
  14049. * last resort to re-try current registered FCF entry.
  14050. */
  14051. lpfc_retry_pport_discovery(phba);
  14052. } else {
  14053. spin_lock_irq(&phba->hbalock);
  14054. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14055. spin_unlock_irq(&phba->hbalock);
  14056. /*
  14057. * DEAD FCF event triggered FCF rediscover request
  14058. * failed, last resort to fail over as a link down
  14059. * to FCF registration.
  14060. */
  14061. lpfc_sli4_fcf_dead_failthrough(phba);
  14062. }
  14063. } else {
  14064. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14065. "2775 Start FCF rediscover quiescent timer\n");
  14066. /*
  14067. * Start FCF rediscovery wait timer for pending FCF
  14068. * before rescan FCF record table.
  14069. */
  14070. lpfc_fcf_redisc_wait_start_timer(phba);
  14071. }
  14072. mempool_free(mbox, phba->mbox_mem_pool);
  14073. }
  14074. /**
  14075. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14076. * @phba: pointer to lpfc hba data structure.
  14077. *
  14078. * This routine is invoked to request for rediscovery of the entire FCF table
  14079. * by the port.
  14080. **/
  14081. int
  14082. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14083. {
  14084. LPFC_MBOXQ_t *mbox;
  14085. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14086. int rc, length;
  14087. /* Cancel retry delay timers to all vports before FCF rediscover */
  14088. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14089. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14090. if (!mbox) {
  14091. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14092. "2745 Failed to allocate mbox for "
  14093. "requesting FCF rediscover.\n");
  14094. return -ENOMEM;
  14095. }
  14096. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14097. sizeof(struct lpfc_sli4_cfg_mhdr));
  14098. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14099. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14100. length, LPFC_SLI4_MBX_EMBED);
  14101. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14102. /* Set count to 0 for invalidating the entire FCF database */
  14103. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14104. /* Issue the mailbox command asynchronously */
  14105. mbox->vport = phba->pport;
  14106. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14107. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14108. if (rc == MBX_NOT_FINISHED) {
  14109. mempool_free(mbox, phba->mbox_mem_pool);
  14110. return -EIO;
  14111. }
  14112. return 0;
  14113. }
  14114. /**
  14115. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14116. * @phba: pointer to lpfc hba data structure.
  14117. *
  14118. * This function is the failover routine as a last resort to the FCF DEAD
  14119. * event when driver failed to perform fast FCF failover.
  14120. **/
  14121. void
  14122. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14123. {
  14124. uint32_t link_state;
  14125. /*
  14126. * Last resort as FCF DEAD event failover will treat this as
  14127. * a link down, but save the link state because we don't want
  14128. * it to be changed to Link Down unless it is already down.
  14129. */
  14130. link_state = phba->link_state;
  14131. lpfc_linkdown(phba);
  14132. phba->link_state = link_state;
  14133. /* Unregister FCF if no devices connected to it */
  14134. lpfc_unregister_unused_fcf(phba);
  14135. }
  14136. /**
  14137. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14138. * @phba: pointer to lpfc hba data structure.
  14139. * @rgn23_data: pointer to configure region 23 data.
  14140. *
  14141. * This function gets SLI3 port configure region 23 data through memory dump
  14142. * mailbox command. When it successfully retrieves data, the size of the data
  14143. * will be returned, otherwise, 0 will be returned.
  14144. **/
  14145. static uint32_t
  14146. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14147. {
  14148. LPFC_MBOXQ_t *pmb = NULL;
  14149. MAILBOX_t *mb;
  14150. uint32_t offset = 0;
  14151. int rc;
  14152. if (!rgn23_data)
  14153. return 0;
  14154. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14155. if (!pmb) {
  14156. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14157. "2600 failed to allocate mailbox memory\n");
  14158. return 0;
  14159. }
  14160. mb = &pmb->u.mb;
  14161. do {
  14162. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14163. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14164. if (rc != MBX_SUCCESS) {
  14165. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14166. "2601 failed to read config "
  14167. "region 23, rc 0x%x Status 0x%x\n",
  14168. rc, mb->mbxStatus);
  14169. mb->un.varDmp.word_cnt = 0;
  14170. }
  14171. /*
  14172. * dump mem may return a zero when finished or we got a
  14173. * mailbox error, either way we are done.
  14174. */
  14175. if (mb->un.varDmp.word_cnt == 0)
  14176. break;
  14177. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14178. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14179. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14180. rgn23_data + offset,
  14181. mb->un.varDmp.word_cnt);
  14182. offset += mb->un.varDmp.word_cnt;
  14183. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14184. mempool_free(pmb, phba->mbox_mem_pool);
  14185. return offset;
  14186. }
  14187. /**
  14188. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14189. * @phba: pointer to lpfc hba data structure.
  14190. * @rgn23_data: pointer to configure region 23 data.
  14191. *
  14192. * This function gets SLI4 port configure region 23 data through memory dump
  14193. * mailbox command. When it successfully retrieves data, the size of the data
  14194. * will be returned, otherwise, 0 will be returned.
  14195. **/
  14196. static uint32_t
  14197. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14198. {
  14199. LPFC_MBOXQ_t *mboxq = NULL;
  14200. struct lpfc_dmabuf *mp = NULL;
  14201. struct lpfc_mqe *mqe;
  14202. uint32_t data_length = 0;
  14203. int rc;
  14204. if (!rgn23_data)
  14205. return 0;
  14206. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14207. if (!mboxq) {
  14208. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14209. "3105 failed to allocate mailbox memory\n");
  14210. return 0;
  14211. }
  14212. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14213. goto out;
  14214. mqe = &mboxq->u.mqe;
  14215. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14216. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14217. if (rc)
  14218. goto out;
  14219. data_length = mqe->un.mb_words[5];
  14220. if (data_length == 0)
  14221. goto out;
  14222. if (data_length > DMP_RGN23_SIZE) {
  14223. data_length = 0;
  14224. goto out;
  14225. }
  14226. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14227. out:
  14228. mempool_free(mboxq, phba->mbox_mem_pool);
  14229. if (mp) {
  14230. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14231. kfree(mp);
  14232. }
  14233. return data_length;
  14234. }
  14235. /**
  14236. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14237. * @phba: pointer to lpfc hba data structure.
  14238. *
  14239. * This function read region 23 and parse TLV for port status to
  14240. * decide if the user disaled the port. If the TLV indicates the
  14241. * port is disabled, the hba_flag is set accordingly.
  14242. **/
  14243. void
  14244. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14245. {
  14246. uint8_t *rgn23_data = NULL;
  14247. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14248. uint32_t offset = 0;
  14249. /* Get adapter Region 23 data */
  14250. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14251. if (!rgn23_data)
  14252. goto out;
  14253. if (phba->sli_rev < LPFC_SLI_REV4)
  14254. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14255. else {
  14256. if_type = bf_get(lpfc_sli_intf_if_type,
  14257. &phba->sli4_hba.sli_intf);
  14258. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14259. goto out;
  14260. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14261. }
  14262. if (!data_size)
  14263. goto out;
  14264. /* Check the region signature first */
  14265. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14266. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14267. "2619 Config region 23 has bad signature\n");
  14268. goto out;
  14269. }
  14270. offset += 4;
  14271. /* Check the data structure version */
  14272. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14273. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14274. "2620 Config region 23 has bad version\n");
  14275. goto out;
  14276. }
  14277. offset += 4;
  14278. /* Parse TLV entries in the region */
  14279. while (offset < data_size) {
  14280. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14281. break;
  14282. /*
  14283. * If the TLV is not driver specific TLV or driver id is
  14284. * not linux driver id, skip the record.
  14285. */
  14286. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14287. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14288. (rgn23_data[offset + 3] != 0)) {
  14289. offset += rgn23_data[offset + 1] * 4 + 4;
  14290. continue;
  14291. }
  14292. /* Driver found a driver specific TLV in the config region */
  14293. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14294. offset += 4;
  14295. tlv_offset = 0;
  14296. /*
  14297. * Search for configured port state sub-TLV.
  14298. */
  14299. while ((offset < data_size) &&
  14300. (tlv_offset < sub_tlv_len)) {
  14301. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14302. offset += 4;
  14303. tlv_offset += 4;
  14304. break;
  14305. }
  14306. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14307. offset += rgn23_data[offset + 1] * 4 + 4;
  14308. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14309. continue;
  14310. }
  14311. /* This HBA contains PORT_STE configured */
  14312. if (!rgn23_data[offset + 2])
  14313. phba->hba_flag |= LINK_DISABLED;
  14314. goto out;
  14315. }
  14316. }
  14317. out:
  14318. kfree(rgn23_data);
  14319. return;
  14320. }
  14321. /**
  14322. * lpfc_wr_object - write an object to the firmware
  14323. * @phba: HBA structure that indicates port to create a queue on.
  14324. * @dmabuf_list: list of dmabufs to write to the port.
  14325. * @size: the total byte value of the objects to write to the port.
  14326. * @offset: the current offset to be used to start the transfer.
  14327. *
  14328. * This routine will create a wr_object mailbox command to send to the port.
  14329. * the mailbox command will be constructed using the dma buffers described in
  14330. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14331. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14332. * used to indicate the starting offset of the transfer and will also return
  14333. * the offset after the write object mailbox has completed. @size is used to
  14334. * determine the end of the object and whether the eof bit should be set.
  14335. *
  14336. * Return 0 is successful and offset will contain the the new offset to use
  14337. * for the next write.
  14338. * Return negative value for error cases.
  14339. **/
  14340. int
  14341. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14342. uint32_t size, uint32_t *offset)
  14343. {
  14344. struct lpfc_mbx_wr_object *wr_object;
  14345. LPFC_MBOXQ_t *mbox;
  14346. int rc = 0, i = 0;
  14347. uint32_t shdr_status, shdr_add_status;
  14348. uint32_t mbox_tmo;
  14349. union lpfc_sli4_cfg_shdr *shdr;
  14350. struct lpfc_dmabuf *dmabuf;
  14351. uint32_t written = 0;
  14352. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14353. if (!mbox)
  14354. return -ENOMEM;
  14355. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14356. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14357. sizeof(struct lpfc_mbx_wr_object) -
  14358. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14359. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14360. wr_object->u.request.write_offset = *offset;
  14361. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14362. wr_object->u.request.object_name[0] =
  14363. cpu_to_le32(wr_object->u.request.object_name[0]);
  14364. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14365. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14366. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14367. break;
  14368. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14369. wr_object->u.request.bde[i].addrHigh =
  14370. putPaddrHigh(dmabuf->phys);
  14371. if (written + SLI4_PAGE_SIZE >= size) {
  14372. wr_object->u.request.bde[i].tus.f.bdeSize =
  14373. (size - written);
  14374. written += (size - written);
  14375. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14376. } else {
  14377. wr_object->u.request.bde[i].tus.f.bdeSize =
  14378. SLI4_PAGE_SIZE;
  14379. written += SLI4_PAGE_SIZE;
  14380. }
  14381. i++;
  14382. }
  14383. wr_object->u.request.bde_count = i;
  14384. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14385. if (!phba->sli4_hba.intr_enable)
  14386. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14387. else {
  14388. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14389. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14390. }
  14391. /* The IOCTL status is embedded in the mailbox subheader. */
  14392. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14393. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14394. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14395. if (rc != MBX_TIMEOUT)
  14396. mempool_free(mbox, phba->mbox_mem_pool);
  14397. if (shdr_status || shdr_add_status || rc) {
  14398. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14399. "3025 Write Object mailbox failed with "
  14400. "status x%x add_status x%x, mbx status x%x\n",
  14401. shdr_status, shdr_add_status, rc);
  14402. rc = -ENXIO;
  14403. } else
  14404. *offset += wr_object->u.response.actual_write_length;
  14405. return rc;
  14406. }
  14407. /**
  14408. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14409. * @vport: pointer to vport data structure.
  14410. *
  14411. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14412. * and REG_VPI mailbox commands associated with the vport. This function
  14413. * is called when driver want to restart discovery of the vport due to
  14414. * a Clear Virtual Link event.
  14415. **/
  14416. void
  14417. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14418. {
  14419. struct lpfc_hba *phba = vport->phba;
  14420. LPFC_MBOXQ_t *mb, *nextmb;
  14421. struct lpfc_dmabuf *mp;
  14422. struct lpfc_nodelist *ndlp;
  14423. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14424. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14425. LIST_HEAD(mbox_cmd_list);
  14426. uint8_t restart_loop;
  14427. /* Clean up internally queued mailbox commands with the vport */
  14428. spin_lock_irq(&phba->hbalock);
  14429. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14430. if (mb->vport != vport)
  14431. continue;
  14432. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14433. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14434. continue;
  14435. list_del(&mb->list);
  14436. list_add_tail(&mb->list, &mbox_cmd_list);
  14437. }
  14438. /* Clean up active mailbox command with the vport */
  14439. mb = phba->sli.mbox_active;
  14440. if (mb && (mb->vport == vport)) {
  14441. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14442. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14443. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14444. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14445. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14446. /* Put reference count for delayed processing */
  14447. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14448. /* Unregister the RPI when mailbox complete */
  14449. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14450. }
  14451. }
  14452. /* Cleanup any mailbox completions which are not yet processed */
  14453. do {
  14454. restart_loop = 0;
  14455. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14456. /*
  14457. * If this mailox is already processed or it is
  14458. * for another vport ignore it.
  14459. */
  14460. if ((mb->vport != vport) ||
  14461. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14462. continue;
  14463. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14464. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14465. continue;
  14466. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14467. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14468. ndlp = (struct lpfc_nodelist *)mb->context2;
  14469. /* Unregister the RPI when mailbox complete */
  14470. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14471. restart_loop = 1;
  14472. spin_unlock_irq(&phba->hbalock);
  14473. spin_lock(shost->host_lock);
  14474. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14475. spin_unlock(shost->host_lock);
  14476. spin_lock_irq(&phba->hbalock);
  14477. break;
  14478. }
  14479. }
  14480. } while (restart_loop);
  14481. spin_unlock_irq(&phba->hbalock);
  14482. /* Release the cleaned-up mailbox commands */
  14483. while (!list_empty(&mbox_cmd_list)) {
  14484. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14485. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14486. mp = (struct lpfc_dmabuf *) (mb->context1);
  14487. if (mp) {
  14488. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14489. kfree(mp);
  14490. }
  14491. ndlp = (struct lpfc_nodelist *) mb->context2;
  14492. mb->context2 = NULL;
  14493. if (ndlp) {
  14494. spin_lock(shost->host_lock);
  14495. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14496. spin_unlock(shost->host_lock);
  14497. lpfc_nlp_put(ndlp);
  14498. }
  14499. }
  14500. mempool_free(mb, phba->mbox_mem_pool);
  14501. }
  14502. /* Release the ndlp with the cleaned-up active mailbox command */
  14503. if (act_mbx_ndlp) {
  14504. spin_lock(shost->host_lock);
  14505. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14506. spin_unlock(shost->host_lock);
  14507. lpfc_nlp_put(act_mbx_ndlp);
  14508. }
  14509. }
  14510. /**
  14511. * lpfc_drain_txq - Drain the txq
  14512. * @phba: Pointer to HBA context object.
  14513. *
  14514. * This function attempt to submit IOCBs on the txq
  14515. * to the adapter. For SLI4 adapters, the txq contains
  14516. * ELS IOCBs that have been deferred because the there
  14517. * are no SGLs. This congestion can occur with large
  14518. * vport counts during node discovery.
  14519. **/
  14520. uint32_t
  14521. lpfc_drain_txq(struct lpfc_hba *phba)
  14522. {
  14523. LIST_HEAD(completions);
  14524. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14525. struct lpfc_iocbq *piocbq = 0;
  14526. unsigned long iflags = 0;
  14527. char *fail_msg = NULL;
  14528. struct lpfc_sglq *sglq;
  14529. union lpfc_wqe wqe;
  14530. spin_lock_irqsave(&phba->hbalock, iflags);
  14531. if (pring->txq_cnt > pring->txq_max)
  14532. pring->txq_max = pring->txq_cnt;
  14533. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14534. while (pring->txq_cnt) {
  14535. spin_lock_irqsave(&phba->hbalock, iflags);
  14536. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14537. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14538. if (!sglq) {
  14539. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14540. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14541. break;
  14542. } else {
  14543. if (!piocbq) {
  14544. /* The txq_cnt out of sync. This should
  14545. * never happen
  14546. */
  14547. sglq = __lpfc_clear_active_sglq(phba,
  14548. sglq->sli4_lxritag);
  14549. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14550. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14551. "2823 txq empty and txq_cnt is %d\n ",
  14552. pring->txq_cnt);
  14553. break;
  14554. }
  14555. }
  14556. /* The xri and iocb resources secured,
  14557. * attempt to issue request
  14558. */
  14559. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14560. piocbq->sli4_xritag = sglq->sli4_xritag;
  14561. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14562. fail_msg = "to convert bpl to sgl";
  14563. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14564. fail_msg = "to convert iocb to wqe";
  14565. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14566. fail_msg = " - Wq is full";
  14567. else
  14568. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14569. if (fail_msg) {
  14570. /* Failed means we can't issue and need to cancel */
  14571. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14572. "2822 IOCB failed %s iotag 0x%x "
  14573. "xri 0x%x\n",
  14574. fail_msg,
  14575. piocbq->iotag, piocbq->sli4_xritag);
  14576. list_add_tail(&piocbq->list, &completions);
  14577. }
  14578. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14579. }
  14580. /* Cancel all the IOCBs that cannot be issued */
  14581. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14582. IOERR_SLI_ABORTED);
  14583. return pring->txq_cnt;
  14584. }