lpfc_sli.c 489 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2011 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 IOCB_t *
  65. lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
  66. {
  67. return &iocbq->iocb;
  68. }
  69. /**
  70. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  71. * @q: The Work Queue to operate on.
  72. * @wqe: The work Queue Entry to put on the Work queue.
  73. *
  74. * This routine will copy the contents of @wqe to the next available entry on
  75. * the @q. This function will then ring the Work Queue Doorbell to signal the
  76. * HBA to start processing the Work Queue Entry. This function returns 0 if
  77. * successful. If no entries are available on @q then this function will return
  78. * -ENOMEM.
  79. * The caller is expected to hold the hbalock when calling this routine.
  80. **/
  81. static uint32_t
  82. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
  83. {
  84. union lpfc_wqe *temp_wqe;
  85. struct lpfc_register doorbell;
  86. uint32_t host_index;
  87. /* sanity check on queue memory */
  88. if (unlikely(!q))
  89. return -ENOMEM;
  90. temp_wqe = q->qe[q->host_index].wqe;
  91. /* If the host has not yet processed the next entry then we are done */
  92. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  93. return -ENOMEM;
  94. /* set consumption flag every once in a while */
  95. if (!((q->host_index + 1) % q->entry_repost))
  96. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  97. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  98. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  99. lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  100. /* Update the host index before invoking device */
  101. host_index = q->host_index;
  102. q->host_index = ((q->host_index + 1) % q->entry_count);
  103. /* Ring Doorbell */
  104. doorbell.word0 = 0;
  105. bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1);
  106. bf_set(lpfc_wq_doorbell_index, &doorbell, host_index);
  107. bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id);
  108. writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr);
  109. readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */
  110. return 0;
  111. }
  112. /**
  113. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  114. * @q: The Work Queue to operate on.
  115. * @index: The index to advance the hba index to.
  116. *
  117. * This routine will update the HBA index of a queue to reflect consumption of
  118. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  119. * an entry the host calls this function to update the queue's internal
  120. * pointers. This routine returns the number of entries that were consumed by
  121. * the HBA.
  122. **/
  123. static uint32_t
  124. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  125. {
  126. uint32_t released = 0;
  127. /* sanity check on queue memory */
  128. if (unlikely(!q))
  129. return 0;
  130. if (q->hba_index == index)
  131. return 0;
  132. do {
  133. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  134. released++;
  135. } while (q->hba_index != index);
  136. return released;
  137. }
  138. /**
  139. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  140. * @q: The Mailbox Queue to operate on.
  141. * @wqe: The Mailbox Queue Entry to put on the Work queue.
  142. *
  143. * This routine will copy the contents of @mqe to the next available entry on
  144. * the @q. This function will then ring the Work Queue Doorbell to signal the
  145. * HBA to start processing the Work Queue Entry. This function returns 0 if
  146. * successful. If no entries are available on @q then this function will return
  147. * -ENOMEM.
  148. * The caller is expected to hold the hbalock when calling this routine.
  149. **/
  150. static uint32_t
  151. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  152. {
  153. struct lpfc_mqe *temp_mqe;
  154. struct lpfc_register doorbell;
  155. uint32_t host_index;
  156. /* sanity check on queue memory */
  157. if (unlikely(!q))
  158. return -ENOMEM;
  159. temp_mqe = q->qe[q->host_index].mqe;
  160. /* If the host has not yet processed the next entry then we are done */
  161. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  162. return -ENOMEM;
  163. lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  164. /* Save off the mailbox pointer for completion */
  165. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  166. /* Update the host index before invoking device */
  167. host_index = q->host_index;
  168. q->host_index = ((q->host_index + 1) % q->entry_count);
  169. /* Ring Doorbell */
  170. doorbell.word0 = 0;
  171. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  172. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  173. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  174. readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */
  175. return 0;
  176. }
  177. /**
  178. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  179. * @q: The Mailbox Queue to operate on.
  180. *
  181. * This routine will update the HBA index of a queue to reflect consumption of
  182. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  183. * an entry the host calls this function to update the queue's internal
  184. * pointers. This routine returns the number of entries that were consumed by
  185. * the HBA.
  186. **/
  187. static uint32_t
  188. lpfc_sli4_mq_release(struct lpfc_queue *q)
  189. {
  190. /* sanity check on queue memory */
  191. if (unlikely(!q))
  192. return 0;
  193. /* Clear the mailbox pointer for completion */
  194. q->phba->mbox = NULL;
  195. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  196. return 1;
  197. }
  198. /**
  199. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  200. * @q: The Event Queue to get the first valid EQE from
  201. *
  202. * This routine will get the first valid Event Queue Entry from @q, update
  203. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  204. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  205. * processed, but not popped back to the HBA then this routine will return NULL.
  206. **/
  207. static struct lpfc_eqe *
  208. lpfc_sli4_eq_get(struct lpfc_queue *q)
  209. {
  210. struct lpfc_eqe *eqe;
  211. /* sanity check on queue memory */
  212. if (unlikely(!q))
  213. return NULL;
  214. eqe = q->qe[q->hba_index].eqe;
  215. /* If the next EQE is not valid then we are done */
  216. if (!bf_get_le32(lpfc_eqe_valid, eqe))
  217. return NULL;
  218. /* If the host has not yet processed the next entry then we are done */
  219. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  220. return NULL;
  221. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  222. return eqe;
  223. }
  224. /**
  225. * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
  226. * @q: The Event Queue that the host has completed processing for.
  227. * @arm: Indicates whether the host wants to arms this CQ.
  228. *
  229. * This routine will mark all Event Queue Entries on @q, from the last
  230. * known completed entry to the last entry that was processed, as completed
  231. * by clearing the valid bit for each completion queue entry. Then it will
  232. * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
  233. * The internal host index in the @q will be updated by this routine to indicate
  234. * that the host has finished processing the entries. The @arm parameter
  235. * indicates that the queue should be rearmed when ringing the doorbell.
  236. *
  237. * This function will return the number of EQEs that were popped.
  238. **/
  239. uint32_t
  240. lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
  241. {
  242. uint32_t released = 0;
  243. struct lpfc_eqe *temp_eqe;
  244. struct lpfc_register doorbell;
  245. /* sanity check on queue memory */
  246. if (unlikely(!q))
  247. return 0;
  248. /* while there are valid entries */
  249. while (q->hba_index != q->host_index) {
  250. temp_eqe = q->qe[q->host_index].eqe;
  251. bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
  252. released++;
  253. q->host_index = ((q->host_index + 1) % q->entry_count);
  254. }
  255. if (unlikely(released == 0 && !arm))
  256. return 0;
  257. /* ring doorbell for number popped */
  258. doorbell.word0 = 0;
  259. if (arm) {
  260. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  261. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  262. }
  263. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  264. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  265. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  266. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  267. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  268. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  269. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  270. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  271. readl(q->phba->sli4_hba.EQCQDBregaddr);
  272. return released;
  273. }
  274. /**
  275. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  276. * @q: The Completion Queue to get the first valid CQE from
  277. *
  278. * This routine will get the first valid Completion Queue Entry from @q, update
  279. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  280. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  281. * processed, but not popped back to the HBA then this routine will return NULL.
  282. **/
  283. static struct lpfc_cqe *
  284. lpfc_sli4_cq_get(struct lpfc_queue *q)
  285. {
  286. struct lpfc_cqe *cqe;
  287. /* sanity check on queue memory */
  288. if (unlikely(!q))
  289. return NULL;
  290. /* If the next CQE is not valid then we are done */
  291. if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
  292. return NULL;
  293. /* If the host has not yet processed the next entry then we are done */
  294. if (((q->hba_index + 1) % q->entry_count) == q->host_index)
  295. return NULL;
  296. cqe = q->qe[q->hba_index].cqe;
  297. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  298. return cqe;
  299. }
  300. /**
  301. * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
  302. * @q: The Completion Queue that the host has completed processing for.
  303. * @arm: Indicates whether the host wants to arms this CQ.
  304. *
  305. * This routine will mark all Completion queue entries on @q, from the last
  306. * known completed entry to the last entry that was processed, as completed
  307. * by clearing the valid bit for each completion queue entry. Then it will
  308. * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
  309. * The internal host index in the @q will be updated by this routine to indicate
  310. * that the host has finished processing the entries. The @arm parameter
  311. * indicates that the queue should be rearmed when ringing the doorbell.
  312. *
  313. * This function will return the number of CQEs that were released.
  314. **/
  315. uint32_t
  316. lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
  317. {
  318. uint32_t released = 0;
  319. struct lpfc_cqe *temp_qe;
  320. struct lpfc_register doorbell;
  321. /* sanity check on queue memory */
  322. if (unlikely(!q))
  323. return 0;
  324. /* while there are valid entries */
  325. while (q->hba_index != q->host_index) {
  326. temp_qe = q->qe[q->host_index].cqe;
  327. bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
  328. released++;
  329. q->host_index = ((q->host_index + 1) % q->entry_count);
  330. }
  331. if (unlikely(released == 0 && !arm))
  332. return 0;
  333. /* ring doorbell for number popped */
  334. doorbell.word0 = 0;
  335. if (arm)
  336. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  337. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
  338. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  339. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  340. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  341. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  342. writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
  343. return released;
  344. }
  345. /**
  346. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  347. * @q: The Header Receive Queue to operate on.
  348. * @wqe: The Receive Queue Entry to put on the Receive queue.
  349. *
  350. * This routine will copy the contents of @wqe to the next available entry on
  351. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  352. * HBA to start processing the Receive Queue Entry. This function returns the
  353. * index that the rqe was copied to if successful. If no entries are available
  354. * on @q then this function will return -ENOMEM.
  355. * The caller is expected to hold the hbalock when calling this routine.
  356. **/
  357. static int
  358. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  359. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  360. {
  361. struct lpfc_rqe *temp_hrqe;
  362. struct lpfc_rqe *temp_drqe;
  363. struct lpfc_register doorbell;
  364. int put_index = hq->host_index;
  365. /* sanity check on queue memory */
  366. if (unlikely(!hq) || unlikely(!dq))
  367. return -ENOMEM;
  368. temp_hrqe = hq->qe[hq->host_index].rqe;
  369. temp_drqe = dq->qe[dq->host_index].rqe;
  370. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  371. return -EINVAL;
  372. if (hq->host_index != dq->host_index)
  373. return -EINVAL;
  374. /* If the host has not yet processed the next entry then we are done */
  375. if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
  376. return -EBUSY;
  377. lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  378. lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  379. /* Update the host index to point to the next slot */
  380. hq->host_index = ((hq->host_index + 1) % hq->entry_count);
  381. dq->host_index = ((dq->host_index + 1) % dq->entry_count);
  382. /* Ring The Header Receive Queue Doorbell */
  383. if (!(hq->host_index % hq->entry_repost)) {
  384. doorbell.word0 = 0;
  385. bf_set(lpfc_rq_doorbell_num_posted, &doorbell,
  386. hq->entry_repost);
  387. bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id);
  388. writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr);
  389. }
  390. return put_index;
  391. }
  392. /**
  393. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  394. * @q: The Header Receive Queue to operate on.
  395. *
  396. * This routine will update the HBA index of a queue to reflect consumption of
  397. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  398. * consumed an entry the host calls this function to update the queue's
  399. * internal pointers. This routine returns the number of entries that were
  400. * consumed by the HBA.
  401. **/
  402. static uint32_t
  403. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  404. {
  405. /* sanity check on queue memory */
  406. if (unlikely(!hq) || unlikely(!dq))
  407. return 0;
  408. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  409. return 0;
  410. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  411. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  412. return 1;
  413. }
  414. /**
  415. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  416. * @phba: Pointer to HBA context object.
  417. * @pring: Pointer to driver SLI ring object.
  418. *
  419. * This function returns pointer to next command iocb entry
  420. * in the command ring. The caller must hold hbalock to prevent
  421. * other threads consume the next command iocb.
  422. * SLI-2/SLI-3 provide different sized iocbs.
  423. **/
  424. static inline IOCB_t *
  425. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  426. {
  427. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  428. pring->cmdidx * phba->iocb_cmd_size);
  429. }
  430. /**
  431. * lpfc_resp_iocb - Get next response iocb entry in the ring
  432. * @phba: Pointer to HBA context object.
  433. * @pring: Pointer to driver SLI ring object.
  434. *
  435. * This function returns pointer to next response iocb entry
  436. * in the response ring. The caller must hold hbalock to make sure
  437. * that no other thread consume the next response iocb.
  438. * SLI-2/SLI-3 provide different sized iocbs.
  439. **/
  440. static inline IOCB_t *
  441. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  442. {
  443. return (IOCB_t *) (((char *) pring->rspringaddr) +
  444. pring->rspidx * phba->iocb_rsp_size);
  445. }
  446. /**
  447. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  448. * @phba: Pointer to HBA context object.
  449. *
  450. * This function is called with hbalock held. This function
  451. * allocates a new driver iocb object from the iocb pool. If the
  452. * allocation is successful, it returns pointer to the newly
  453. * allocated iocb object else it returns NULL.
  454. **/
  455. static struct lpfc_iocbq *
  456. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  457. {
  458. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  459. struct lpfc_iocbq * iocbq = NULL;
  460. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  461. if (iocbq)
  462. phba->iocb_cnt++;
  463. if (phba->iocb_cnt > phba->iocb_max)
  464. phba->iocb_max = phba->iocb_cnt;
  465. return iocbq;
  466. }
  467. /**
  468. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  469. * @phba: Pointer to HBA context object.
  470. * @xritag: XRI value.
  471. *
  472. * This function clears the sglq pointer from the array of acive
  473. * sglq's. The xritag that is passed in is used to index into the
  474. * array. Before the xritag can be used it needs to be adjusted
  475. * by subtracting the xribase.
  476. *
  477. * Returns sglq ponter = success, NULL = Failure.
  478. **/
  479. static struct lpfc_sglq *
  480. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  481. {
  482. struct lpfc_sglq *sglq;
  483. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  484. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  485. return sglq;
  486. }
  487. /**
  488. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  489. * @phba: Pointer to HBA context object.
  490. * @xritag: XRI value.
  491. *
  492. * This function returns the sglq pointer from the array of acive
  493. * sglq's. The xritag that is passed in is used to index into the
  494. * array. Before the xritag can be used it needs to be adjusted
  495. * by subtracting the xribase.
  496. *
  497. * Returns sglq ponter = success, NULL = Failure.
  498. **/
  499. struct lpfc_sglq *
  500. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  501. {
  502. struct lpfc_sglq *sglq;
  503. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  504. return sglq;
  505. }
  506. /**
  507. * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap.
  508. * @phba: Pointer to HBA context object.
  509. * @ndlp: nodelist pointer for this target.
  510. * @xritag: xri used in this exchange.
  511. * @rxid: Remote Exchange ID.
  512. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  513. *
  514. * This function is called with hbalock held.
  515. * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an
  516. * rrq struct and adds it to the active_rrq_list.
  517. *
  518. * returns 0 for rrq slot for this xri
  519. * < 0 Were not able to get rrq mem or invalid parameter.
  520. **/
  521. static int
  522. __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  523. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  524. {
  525. struct lpfc_node_rrq *rrq;
  526. int empty;
  527. uint32_t did = 0;
  528. if (!ndlp)
  529. return -EINVAL;
  530. if (!phba->cfg_enable_rrq)
  531. return -EINVAL;
  532. if (phba->pport->load_flag & FC_UNLOADING) {
  533. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  534. goto out;
  535. }
  536. did = ndlp->nlp_DID;
  537. /*
  538. * set the active bit even if there is no mem available.
  539. */
  540. if (NLP_CHK_FREE_REQ(ndlp))
  541. goto out;
  542. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  543. goto out;
  544. if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  545. goto out;
  546. rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
  547. if (rrq) {
  548. rrq->send_rrq = send_rrq;
  549. rrq->xritag = xritag;
  550. rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1);
  551. rrq->ndlp = ndlp;
  552. rrq->nlp_DID = ndlp->nlp_DID;
  553. rrq->vport = ndlp->vport;
  554. rrq->rxid = rxid;
  555. empty = list_empty(&phba->active_rrq_list);
  556. rrq->send_rrq = send_rrq;
  557. list_add_tail(&rrq->list, &phba->active_rrq_list);
  558. if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) {
  559. phba->hba_flag |= HBA_RRQ_ACTIVE;
  560. if (empty)
  561. lpfc_worker_wake_up(phba);
  562. }
  563. return 0;
  564. }
  565. out:
  566. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  567. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  568. " DID:0x%x Send:%d\n",
  569. xritag, rxid, did, send_rrq);
  570. return -EINVAL;
  571. }
  572. /**
  573. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  574. * @phba: Pointer to HBA context object.
  575. * @xritag: xri used in this exchange.
  576. * @rrq: The RRQ to be cleared.
  577. *
  578. **/
  579. void
  580. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  581. uint16_t xritag,
  582. struct lpfc_node_rrq *rrq)
  583. {
  584. struct lpfc_nodelist *ndlp = NULL;
  585. if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
  586. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  587. /* The target DID could have been swapped (cable swap)
  588. * we should use the ndlp from the findnode if it is
  589. * available.
  590. */
  591. if ((!ndlp) && rrq->ndlp)
  592. ndlp = rrq->ndlp;
  593. if (!ndlp)
  594. goto out;
  595. if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) {
  596. rrq->send_rrq = 0;
  597. rrq->xritag = 0;
  598. rrq->rrq_stop_time = 0;
  599. }
  600. out:
  601. mempool_free(rrq, phba->rrq_pool);
  602. }
  603. /**
  604. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  605. * @phba: Pointer to HBA context object.
  606. *
  607. * This function is called with hbalock held. This function
  608. * Checks if stop_time (ratov from setting rrq active) has
  609. * been reached, if it has and the send_rrq flag is set then
  610. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  611. * then it will just call the routine to clear the rrq and
  612. * free the rrq resource.
  613. * The timer is set to the next rrq that is going to expire before
  614. * leaving the routine.
  615. *
  616. **/
  617. void
  618. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  619. {
  620. struct lpfc_node_rrq *rrq;
  621. struct lpfc_node_rrq *nextrrq;
  622. unsigned long next_time;
  623. unsigned long iflags;
  624. LIST_HEAD(send_rrq);
  625. spin_lock_irqsave(&phba->hbalock, iflags);
  626. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  627. next_time = jiffies + HZ * (phba->fc_ratov + 1);
  628. list_for_each_entry_safe(rrq, nextrrq,
  629. &phba->active_rrq_list, list) {
  630. if (time_after(jiffies, rrq->rrq_stop_time))
  631. list_move(&rrq->list, &send_rrq);
  632. else if (time_before(rrq->rrq_stop_time, next_time))
  633. next_time = rrq->rrq_stop_time;
  634. }
  635. spin_unlock_irqrestore(&phba->hbalock, iflags);
  636. if (!list_empty(&phba->active_rrq_list))
  637. mod_timer(&phba->rrq_tmr, next_time);
  638. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  639. list_del(&rrq->list);
  640. if (!rrq->send_rrq)
  641. /* this call will free the rrq */
  642. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  643. else if (lpfc_send_rrq(phba, rrq)) {
  644. /* if we send the rrq then the completion handler
  645. * will clear the bit in the xribitmap.
  646. */
  647. lpfc_clr_rrq_active(phba, rrq->xritag,
  648. rrq);
  649. }
  650. }
  651. }
  652. /**
  653. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  654. * @vport: Pointer to vport context object.
  655. * @xri: The xri used in the exchange.
  656. * @did: The targets DID for this exchange.
  657. *
  658. * returns NULL = rrq not found in the phba->active_rrq_list.
  659. * rrq = rrq for this xri and target.
  660. **/
  661. struct lpfc_node_rrq *
  662. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  663. {
  664. struct lpfc_hba *phba = vport->phba;
  665. struct lpfc_node_rrq *rrq;
  666. struct lpfc_node_rrq *nextrrq;
  667. unsigned long iflags;
  668. if (phba->sli_rev != LPFC_SLI_REV4)
  669. return NULL;
  670. spin_lock_irqsave(&phba->hbalock, iflags);
  671. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  672. if (rrq->vport == vport && rrq->xritag == xri &&
  673. rrq->nlp_DID == did){
  674. list_del(&rrq->list);
  675. spin_unlock_irqrestore(&phba->hbalock, iflags);
  676. return rrq;
  677. }
  678. }
  679. spin_unlock_irqrestore(&phba->hbalock, iflags);
  680. return NULL;
  681. }
  682. /**
  683. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  684. * @vport: Pointer to vport context object.
  685. * @ndlp: Pointer to the lpfc_node_list structure.
  686. * If ndlp is NULL Remove all active RRQs for this vport from the
  687. * phba->active_rrq_list and clear the rrq.
  688. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  689. **/
  690. void
  691. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  692. {
  693. struct lpfc_hba *phba = vport->phba;
  694. struct lpfc_node_rrq *rrq;
  695. struct lpfc_node_rrq *nextrrq;
  696. unsigned long iflags;
  697. LIST_HEAD(rrq_list);
  698. if (phba->sli_rev != LPFC_SLI_REV4)
  699. return;
  700. if (!ndlp) {
  701. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  702. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  703. }
  704. spin_lock_irqsave(&phba->hbalock, iflags);
  705. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
  706. if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
  707. list_move(&rrq->list, &rrq_list);
  708. spin_unlock_irqrestore(&phba->hbalock, iflags);
  709. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  710. list_del(&rrq->list);
  711. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  712. }
  713. }
  714. /**
  715. * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
  716. * @phba: Pointer to HBA context object.
  717. *
  718. * Remove all rrqs from the phba->active_rrq_list and free them by
  719. * calling __lpfc_clr_active_rrq
  720. *
  721. **/
  722. void
  723. lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba)
  724. {
  725. struct lpfc_node_rrq *rrq;
  726. struct lpfc_node_rrq *nextrrq;
  727. unsigned long next_time;
  728. unsigned long iflags;
  729. LIST_HEAD(rrq_list);
  730. if (phba->sli_rev != LPFC_SLI_REV4)
  731. return;
  732. spin_lock_irqsave(&phba->hbalock, iflags);
  733. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  734. next_time = jiffies + HZ * (phba->fc_ratov * 2);
  735. list_splice_init(&phba->active_rrq_list, &rrq_list);
  736. spin_unlock_irqrestore(&phba->hbalock, iflags);
  737. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  738. list_del(&rrq->list);
  739. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  740. }
  741. if (!list_empty(&phba->active_rrq_list))
  742. mod_timer(&phba->rrq_tmr, next_time);
  743. }
  744. /**
  745. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  746. * @phba: Pointer to HBA context object.
  747. * @ndlp: Targets nodelist pointer for this exchange.
  748. * @xritag the xri in the bitmap to test.
  749. *
  750. * This function is called with hbalock held. This function
  751. * returns 0 = rrq not active for this xri
  752. * 1 = rrq is valid for this xri.
  753. **/
  754. int
  755. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  756. uint16_t xritag)
  757. {
  758. if (!ndlp)
  759. return 0;
  760. if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap))
  761. return 1;
  762. else
  763. return 0;
  764. }
  765. /**
  766. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  767. * @phba: Pointer to HBA context object.
  768. * @ndlp: nodelist pointer for this target.
  769. * @xritag: xri used in this exchange.
  770. * @rxid: Remote Exchange ID.
  771. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  772. *
  773. * This function takes the hbalock.
  774. * The active bit is always set in the active rrq xri_bitmap even
  775. * if there is no slot avaiable for the other rrq information.
  776. *
  777. * returns 0 rrq actived for this xri
  778. * < 0 No memory or invalid ndlp.
  779. **/
  780. int
  781. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  782. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  783. {
  784. int ret;
  785. unsigned long iflags;
  786. spin_lock_irqsave(&phba->hbalock, iflags);
  787. ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq);
  788. spin_unlock_irqrestore(&phba->hbalock, iflags);
  789. return ret;
  790. }
  791. /**
  792. * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
  793. * @phba: Pointer to HBA context object.
  794. * @piocb: Pointer to the iocbq.
  795. *
  796. * This function is called with hbalock held. This function
  797. * gets a new driver sglq object from the sglq list. If the
  798. * list is not empty then it is successful, it returns pointer to the newly
  799. * allocated sglq object else it returns NULL.
  800. **/
  801. static struct lpfc_sglq *
  802. __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  803. {
  804. struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list;
  805. struct lpfc_sglq *sglq = NULL;
  806. struct lpfc_sglq *start_sglq = NULL;
  807. struct lpfc_scsi_buf *lpfc_cmd;
  808. struct lpfc_nodelist *ndlp;
  809. int found = 0;
  810. if (piocbq->iocb_flag & LPFC_IO_FCP) {
  811. lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
  812. ndlp = lpfc_cmd->rdata->pnode;
  813. } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
  814. !(piocbq->iocb_flag & LPFC_IO_LIBDFC))
  815. ndlp = piocbq->context_un.ndlp;
  816. else
  817. ndlp = piocbq->context1;
  818. list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list);
  819. start_sglq = sglq;
  820. while (!found) {
  821. if (!sglq)
  822. return NULL;
  823. if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) {
  824. /* This xri has an rrq outstanding for this DID.
  825. * put it back in the list and get another xri.
  826. */
  827. list_add_tail(&sglq->list, lpfc_sgl_list);
  828. sglq = NULL;
  829. list_remove_head(lpfc_sgl_list, sglq,
  830. struct lpfc_sglq, list);
  831. if (sglq == start_sglq) {
  832. sglq = NULL;
  833. break;
  834. } else
  835. continue;
  836. }
  837. sglq->ndlp = ndlp;
  838. found = 1;
  839. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  840. sglq->state = SGL_ALLOCATED;
  841. }
  842. return sglq;
  843. }
  844. /**
  845. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  846. * @phba: Pointer to HBA context object.
  847. *
  848. * This function is called with no lock held. This function
  849. * allocates a new driver iocb object from the iocb pool. If the
  850. * allocation is successful, it returns pointer to the newly
  851. * allocated iocb object else it returns NULL.
  852. **/
  853. struct lpfc_iocbq *
  854. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  855. {
  856. struct lpfc_iocbq * iocbq = NULL;
  857. unsigned long iflags;
  858. spin_lock_irqsave(&phba->hbalock, iflags);
  859. iocbq = __lpfc_sli_get_iocbq(phba);
  860. spin_unlock_irqrestore(&phba->hbalock, iflags);
  861. return iocbq;
  862. }
  863. /**
  864. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  865. * @phba: Pointer to HBA context object.
  866. * @iocbq: Pointer to driver iocb object.
  867. *
  868. * This function is called with hbalock held to release driver
  869. * iocb object to the iocb pool. The iotag in the iocb object
  870. * does not change for each use of the iocb object. This function
  871. * clears all other fields of the iocb object when it is freed.
  872. * The sqlq structure that holds the xritag and phys and virtual
  873. * mappings for the scatter gather list is retrieved from the
  874. * active array of sglq. The get of the sglq pointer also clears
  875. * the entry in the array. If the status of the IO indiactes that
  876. * this IO was aborted then the sglq entry it put on the
  877. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  878. * IO has good status or fails for any other reason then the sglq
  879. * entry is added to the free list (lpfc_sgl_list).
  880. **/
  881. static void
  882. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  883. {
  884. struct lpfc_sglq *sglq;
  885. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  886. unsigned long iflag = 0;
  887. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  888. if (iocbq->sli4_xritag == NO_XRI)
  889. sglq = NULL;
  890. else
  891. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  892. if (sglq) {
  893. if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
  894. (sglq->state != SGL_XRI_ABORTED)) {
  895. spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
  896. iflag);
  897. list_add(&sglq->list,
  898. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  899. spin_unlock_irqrestore(
  900. &phba->sli4_hba.abts_sgl_list_lock, iflag);
  901. } else {
  902. sglq->state = SGL_FREED;
  903. sglq->ndlp = NULL;
  904. list_add_tail(&sglq->list,
  905. &phba->sli4_hba.lpfc_sgl_list);
  906. /* Check if TXQ queue needs to be serviced */
  907. if (pring->txq_cnt)
  908. lpfc_worker_wake_up(phba);
  909. }
  910. }
  911. /*
  912. * Clean all volatile data fields, preserve iotag and node struct.
  913. */
  914. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  915. iocbq->sli4_lxritag = NO_XRI;
  916. iocbq->sli4_xritag = NO_XRI;
  917. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  918. }
  919. /**
  920. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  921. * @phba: Pointer to HBA context object.
  922. * @iocbq: Pointer to driver iocb object.
  923. *
  924. * This function is called with hbalock held to release driver
  925. * iocb object to the iocb pool. The iotag in the iocb object
  926. * does not change for each use of the iocb object. This function
  927. * clears all other fields of the iocb object when it is freed.
  928. **/
  929. static void
  930. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  931. {
  932. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  933. /*
  934. * Clean all volatile data fields, preserve iotag and node struct.
  935. */
  936. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  937. iocbq->sli4_xritag = NO_XRI;
  938. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  939. }
  940. /**
  941. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  942. * @phba: Pointer to HBA context object.
  943. * @iocbq: Pointer to driver iocb object.
  944. *
  945. * This function is called with hbalock held to release driver
  946. * iocb object to the iocb pool. The iotag in the iocb object
  947. * does not change for each use of the iocb object. This function
  948. * clears all other fields of the iocb object when it is freed.
  949. **/
  950. static void
  951. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  952. {
  953. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  954. phba->iocb_cnt--;
  955. }
  956. /**
  957. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  958. * @phba: Pointer to HBA context object.
  959. * @iocbq: Pointer to driver iocb object.
  960. *
  961. * This function is called with no lock held to release the iocb to
  962. * iocb pool.
  963. **/
  964. void
  965. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  966. {
  967. unsigned long iflags;
  968. /*
  969. * Clean all volatile data fields, preserve iotag and node struct.
  970. */
  971. spin_lock_irqsave(&phba->hbalock, iflags);
  972. __lpfc_sli_release_iocbq(phba, iocbq);
  973. spin_unlock_irqrestore(&phba->hbalock, iflags);
  974. }
  975. /**
  976. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  977. * @phba: Pointer to HBA context object.
  978. * @iocblist: List of IOCBs.
  979. * @ulpstatus: ULP status in IOCB command field.
  980. * @ulpWord4: ULP word-4 in IOCB command field.
  981. *
  982. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  983. * on the list by invoking the complete callback function associated with the
  984. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  985. * fields.
  986. **/
  987. void
  988. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  989. uint32_t ulpstatus, uint32_t ulpWord4)
  990. {
  991. struct lpfc_iocbq *piocb;
  992. while (!list_empty(iocblist)) {
  993. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  994. if (!piocb->iocb_cmpl)
  995. lpfc_sli_release_iocbq(phba, piocb);
  996. else {
  997. piocb->iocb.ulpStatus = ulpstatus;
  998. piocb->iocb.un.ulpWord[4] = ulpWord4;
  999. (piocb->iocb_cmpl) (phba, piocb, piocb);
  1000. }
  1001. }
  1002. return;
  1003. }
  1004. /**
  1005. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1006. * @iocb_cmnd: iocb command code.
  1007. *
  1008. * This function is called by ring event handler function to get the iocb type.
  1009. * This function translates the iocb command to an iocb command type used to
  1010. * decide the final disposition of each completed IOCB.
  1011. * The function returns
  1012. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1013. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1014. * LPFC_ABORT_IOCB if it is an abort iocb
  1015. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1016. *
  1017. * The caller is not required to hold any lock.
  1018. **/
  1019. static lpfc_iocb_type
  1020. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1021. {
  1022. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1023. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1024. return 0;
  1025. switch (iocb_cmnd) {
  1026. case CMD_XMIT_SEQUENCE_CR:
  1027. case CMD_XMIT_SEQUENCE_CX:
  1028. case CMD_XMIT_BCAST_CN:
  1029. case CMD_XMIT_BCAST_CX:
  1030. case CMD_ELS_REQUEST_CR:
  1031. case CMD_ELS_REQUEST_CX:
  1032. case CMD_CREATE_XRI_CR:
  1033. case CMD_CREATE_XRI_CX:
  1034. case CMD_GET_RPI_CN:
  1035. case CMD_XMIT_ELS_RSP_CX:
  1036. case CMD_GET_RPI_CR:
  1037. case CMD_FCP_IWRITE_CR:
  1038. case CMD_FCP_IWRITE_CX:
  1039. case CMD_FCP_IREAD_CR:
  1040. case CMD_FCP_IREAD_CX:
  1041. case CMD_FCP_ICMND_CR:
  1042. case CMD_FCP_ICMND_CX:
  1043. case CMD_FCP_TSEND_CX:
  1044. case CMD_FCP_TRSP_CX:
  1045. case CMD_FCP_TRECEIVE_CX:
  1046. case CMD_FCP_AUTO_TRSP_CX:
  1047. case CMD_ADAPTER_MSG:
  1048. case CMD_ADAPTER_DUMP:
  1049. case CMD_XMIT_SEQUENCE64_CR:
  1050. case CMD_XMIT_SEQUENCE64_CX:
  1051. case CMD_XMIT_BCAST64_CN:
  1052. case CMD_XMIT_BCAST64_CX:
  1053. case CMD_ELS_REQUEST64_CR:
  1054. case CMD_ELS_REQUEST64_CX:
  1055. case CMD_FCP_IWRITE64_CR:
  1056. case CMD_FCP_IWRITE64_CX:
  1057. case CMD_FCP_IREAD64_CR:
  1058. case CMD_FCP_IREAD64_CX:
  1059. case CMD_FCP_ICMND64_CR:
  1060. case CMD_FCP_ICMND64_CX:
  1061. case CMD_FCP_TSEND64_CX:
  1062. case CMD_FCP_TRSP64_CX:
  1063. case CMD_FCP_TRECEIVE64_CX:
  1064. case CMD_GEN_REQUEST64_CR:
  1065. case CMD_GEN_REQUEST64_CX:
  1066. case CMD_XMIT_ELS_RSP64_CX:
  1067. case DSSCMD_IWRITE64_CR:
  1068. case DSSCMD_IWRITE64_CX:
  1069. case DSSCMD_IREAD64_CR:
  1070. case DSSCMD_IREAD64_CX:
  1071. type = LPFC_SOL_IOCB;
  1072. break;
  1073. case CMD_ABORT_XRI_CN:
  1074. case CMD_ABORT_XRI_CX:
  1075. case CMD_CLOSE_XRI_CN:
  1076. case CMD_CLOSE_XRI_CX:
  1077. case CMD_XRI_ABORTED_CX:
  1078. case CMD_ABORT_MXRI64_CN:
  1079. case CMD_XMIT_BLS_RSP64_CX:
  1080. type = LPFC_ABORT_IOCB;
  1081. break;
  1082. case CMD_RCV_SEQUENCE_CX:
  1083. case CMD_RCV_ELS_REQ_CX:
  1084. case CMD_RCV_SEQUENCE64_CX:
  1085. case CMD_RCV_ELS_REQ64_CX:
  1086. case CMD_ASYNC_STATUS:
  1087. case CMD_IOCB_RCV_SEQ64_CX:
  1088. case CMD_IOCB_RCV_ELS64_CX:
  1089. case CMD_IOCB_RCV_CONT64_CX:
  1090. case CMD_IOCB_RET_XRI64_CX:
  1091. type = LPFC_UNSOL_IOCB;
  1092. break;
  1093. case CMD_IOCB_XMIT_MSEQ64_CR:
  1094. case CMD_IOCB_XMIT_MSEQ64_CX:
  1095. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1096. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1097. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1098. case CMD_IOCB_ABORT_EXTENDED_CN:
  1099. case CMD_IOCB_RET_HBQE64_CN:
  1100. case CMD_IOCB_FCP_IBIDIR64_CR:
  1101. case CMD_IOCB_FCP_IBIDIR64_CX:
  1102. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1103. case CMD_IOCB_LOGENTRY_CN:
  1104. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1105. printk("%s - Unhandled SLI-3 Command x%x\n",
  1106. __func__, iocb_cmnd);
  1107. type = LPFC_UNKNOWN_IOCB;
  1108. break;
  1109. default:
  1110. type = LPFC_UNKNOWN_IOCB;
  1111. break;
  1112. }
  1113. return type;
  1114. }
  1115. /**
  1116. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1117. * @phba: Pointer to HBA context object.
  1118. *
  1119. * This function is called from SLI initialization code
  1120. * to configure every ring of the HBA's SLI interface. The
  1121. * caller is not required to hold any lock. This function issues
  1122. * a config_ring mailbox command for each ring.
  1123. * This function returns zero if successful else returns a negative
  1124. * error code.
  1125. **/
  1126. static int
  1127. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1128. {
  1129. struct lpfc_sli *psli = &phba->sli;
  1130. LPFC_MBOXQ_t *pmb;
  1131. MAILBOX_t *pmbox;
  1132. int i, rc, ret = 0;
  1133. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1134. if (!pmb)
  1135. return -ENOMEM;
  1136. pmbox = &pmb->u.mb;
  1137. phba->link_state = LPFC_INIT_MBX_CMDS;
  1138. for (i = 0; i < psli->num_rings; i++) {
  1139. lpfc_config_ring(phba, i, pmb);
  1140. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1141. if (rc != MBX_SUCCESS) {
  1142. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1143. "0446 Adapter failed to init (%d), "
  1144. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1145. "ring %d\n",
  1146. rc, pmbox->mbxCommand,
  1147. pmbox->mbxStatus, i);
  1148. phba->link_state = LPFC_HBA_ERROR;
  1149. ret = -ENXIO;
  1150. break;
  1151. }
  1152. }
  1153. mempool_free(pmb, phba->mbox_mem_pool);
  1154. return ret;
  1155. }
  1156. /**
  1157. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1158. * @phba: Pointer to HBA context object.
  1159. * @pring: Pointer to driver SLI ring object.
  1160. * @piocb: Pointer to the driver iocb object.
  1161. *
  1162. * This function is called with hbalock held. The function adds the
  1163. * new iocb to txcmplq of the given ring. This function always returns
  1164. * 0. If this function is called for ELS ring, this function checks if
  1165. * there is a vport associated with the ELS command. This function also
  1166. * starts els_tmofunc timer if this is an ELS command.
  1167. **/
  1168. static int
  1169. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1170. struct lpfc_iocbq *piocb)
  1171. {
  1172. list_add_tail(&piocb->list, &pring->txcmplq);
  1173. piocb->iocb_flag |= LPFC_IO_ON_Q;
  1174. pring->txcmplq_cnt++;
  1175. if (pring->txcmplq_cnt > pring->txcmplq_max)
  1176. pring->txcmplq_max = pring->txcmplq_cnt;
  1177. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1178. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  1179. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  1180. if (!piocb->vport)
  1181. BUG();
  1182. else
  1183. mod_timer(&piocb->vport->els_tmofunc,
  1184. jiffies + HZ * (phba->fc_ratov << 1));
  1185. }
  1186. return 0;
  1187. }
  1188. /**
  1189. * lpfc_sli_ringtx_get - Get first element of the txq
  1190. * @phba: Pointer to HBA context object.
  1191. * @pring: Pointer to driver SLI ring object.
  1192. *
  1193. * This function is called with hbalock held to get next
  1194. * iocb in txq of the given ring. If there is any iocb in
  1195. * the txq, the function returns first iocb in the list after
  1196. * removing the iocb from the list, else it returns NULL.
  1197. **/
  1198. struct lpfc_iocbq *
  1199. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1200. {
  1201. struct lpfc_iocbq *cmd_iocb;
  1202. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1203. if (cmd_iocb != NULL)
  1204. pring->txq_cnt--;
  1205. return cmd_iocb;
  1206. }
  1207. /**
  1208. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1209. * @phba: Pointer to HBA context object.
  1210. * @pring: Pointer to driver SLI ring object.
  1211. *
  1212. * This function is called with hbalock held and the caller must post the
  1213. * iocb without releasing the lock. If the caller releases the lock,
  1214. * iocb slot returned by the function is not guaranteed to be available.
  1215. * The function returns pointer to the next available iocb slot if there
  1216. * is available slot in the ring, else it returns NULL.
  1217. * If the get index of the ring is ahead of the put index, the function
  1218. * will post an error attention event to the worker thread to take the
  1219. * HBA to offline state.
  1220. **/
  1221. static IOCB_t *
  1222. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1223. {
  1224. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1225. uint32_t max_cmd_idx = pring->numCiocb;
  1226. if ((pring->next_cmdidx == pring->cmdidx) &&
  1227. (++pring->next_cmdidx >= max_cmd_idx))
  1228. pring->next_cmdidx = 0;
  1229. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  1230. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1231. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  1232. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1233. "0315 Ring %d issue: portCmdGet %d "
  1234. "is bigger than cmd ring %d\n",
  1235. pring->ringno,
  1236. pring->local_getidx, max_cmd_idx);
  1237. phba->link_state = LPFC_HBA_ERROR;
  1238. /*
  1239. * All error attention handlers are posted to
  1240. * worker thread
  1241. */
  1242. phba->work_ha |= HA_ERATT;
  1243. phba->work_hs = HS_FFER3;
  1244. lpfc_worker_wake_up(phba);
  1245. return NULL;
  1246. }
  1247. if (pring->local_getidx == pring->next_cmdidx)
  1248. return NULL;
  1249. }
  1250. return lpfc_cmd_iocb(phba, pring);
  1251. }
  1252. /**
  1253. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1254. * @phba: Pointer to HBA context object.
  1255. * @iocbq: Pointer to driver iocb object.
  1256. *
  1257. * This function gets an iotag for the iocb. If there is no unused iotag and
  1258. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1259. * array and assigns a new iotag.
  1260. * The function returns the allocated iotag if successful, else returns zero.
  1261. * Zero is not a valid iotag.
  1262. * The caller is not required to hold any lock.
  1263. **/
  1264. uint16_t
  1265. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1266. {
  1267. struct lpfc_iocbq **new_arr;
  1268. struct lpfc_iocbq **old_arr;
  1269. size_t new_len;
  1270. struct lpfc_sli *psli = &phba->sli;
  1271. uint16_t iotag;
  1272. spin_lock_irq(&phba->hbalock);
  1273. iotag = psli->last_iotag;
  1274. if(++iotag < psli->iocbq_lookup_len) {
  1275. psli->last_iotag = iotag;
  1276. psli->iocbq_lookup[iotag] = iocbq;
  1277. spin_unlock_irq(&phba->hbalock);
  1278. iocbq->iotag = iotag;
  1279. return iotag;
  1280. } else if (psli->iocbq_lookup_len < (0xffff
  1281. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1282. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1283. spin_unlock_irq(&phba->hbalock);
  1284. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  1285. GFP_KERNEL);
  1286. if (new_arr) {
  1287. spin_lock_irq(&phba->hbalock);
  1288. old_arr = psli->iocbq_lookup;
  1289. if (new_len <= psli->iocbq_lookup_len) {
  1290. /* highly unprobable case */
  1291. kfree(new_arr);
  1292. iotag = psli->last_iotag;
  1293. if(++iotag < psli->iocbq_lookup_len) {
  1294. psli->last_iotag = iotag;
  1295. psli->iocbq_lookup[iotag] = iocbq;
  1296. spin_unlock_irq(&phba->hbalock);
  1297. iocbq->iotag = iotag;
  1298. return iotag;
  1299. }
  1300. spin_unlock_irq(&phba->hbalock);
  1301. return 0;
  1302. }
  1303. if (psli->iocbq_lookup)
  1304. memcpy(new_arr, old_arr,
  1305. ((psli->last_iotag + 1) *
  1306. sizeof (struct lpfc_iocbq *)));
  1307. psli->iocbq_lookup = new_arr;
  1308. psli->iocbq_lookup_len = new_len;
  1309. psli->last_iotag = iotag;
  1310. psli->iocbq_lookup[iotag] = iocbq;
  1311. spin_unlock_irq(&phba->hbalock);
  1312. iocbq->iotag = iotag;
  1313. kfree(old_arr);
  1314. return iotag;
  1315. }
  1316. } else
  1317. spin_unlock_irq(&phba->hbalock);
  1318. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1319. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1320. psli->last_iotag);
  1321. return 0;
  1322. }
  1323. /**
  1324. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1325. * @phba: Pointer to HBA context object.
  1326. * @pring: Pointer to driver SLI ring object.
  1327. * @iocb: Pointer to iocb slot in the ring.
  1328. * @nextiocb: Pointer to driver iocb object which need to be
  1329. * posted to firmware.
  1330. *
  1331. * This function is called with hbalock held to post a new iocb to
  1332. * the firmware. This function copies the new iocb to ring iocb slot and
  1333. * updates the ring pointers. It adds the new iocb to txcmplq if there is
  1334. * a completion call back for this iocb else the function will free the
  1335. * iocb object.
  1336. **/
  1337. static void
  1338. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1339. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1340. {
  1341. /*
  1342. * Set up an iotag
  1343. */
  1344. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  1345. if (pring->ringno == LPFC_ELS_RING) {
  1346. lpfc_debugfs_slow_ring_trc(phba,
  1347. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1348. *(((uint32_t *) &nextiocb->iocb) + 4),
  1349. *(((uint32_t *) &nextiocb->iocb) + 6),
  1350. *(((uint32_t *) &nextiocb->iocb) + 7));
  1351. }
  1352. /*
  1353. * Issue iocb command to adapter
  1354. */
  1355. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1356. wmb();
  1357. pring->stats.iocb_cmd++;
  1358. /*
  1359. * If there is no completion routine to call, we can release the
  1360. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1361. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  1362. */
  1363. if (nextiocb->iocb_cmpl)
  1364. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1365. else
  1366. __lpfc_sli_release_iocbq(phba, nextiocb);
  1367. /*
  1368. * Let the HBA know what IOCB slot will be the next one the
  1369. * driver will put a command into.
  1370. */
  1371. pring->cmdidx = pring->next_cmdidx;
  1372. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1373. }
  1374. /**
  1375. * lpfc_sli_update_full_ring - Update the chip attention register
  1376. * @phba: Pointer to HBA context object.
  1377. * @pring: Pointer to driver SLI ring object.
  1378. *
  1379. * The caller is not required to hold any lock for calling this function.
  1380. * This function updates the chip attention bits for the ring to inform firmware
  1381. * that there are pending work to be done for this ring and requests an
  1382. * interrupt when there is space available in the ring. This function is
  1383. * called when the driver is unable to post more iocbs to the ring due
  1384. * to unavailability of space in the ring.
  1385. **/
  1386. static void
  1387. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1388. {
  1389. int ringno = pring->ringno;
  1390. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1391. wmb();
  1392. /*
  1393. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  1394. * The HBA will tell us when an IOCB entry is available.
  1395. */
  1396. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  1397. readl(phba->CAregaddr); /* flush */
  1398. pring->stats.iocb_cmd_full++;
  1399. }
  1400. /**
  1401. * lpfc_sli_update_ring - Update chip attention register
  1402. * @phba: Pointer to HBA context object.
  1403. * @pring: Pointer to driver SLI ring object.
  1404. *
  1405. * This function updates the chip attention register bit for the
  1406. * given ring to inform HBA that there is more work to be done
  1407. * in this ring. The caller is not required to hold any lock.
  1408. **/
  1409. static void
  1410. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1411. {
  1412. int ringno = pring->ringno;
  1413. /*
  1414. * Tell the HBA that there is work to do in this ring.
  1415. */
  1416. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  1417. wmb();
  1418. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  1419. readl(phba->CAregaddr); /* flush */
  1420. }
  1421. }
  1422. /**
  1423. * lpfc_sli_resume_iocb - Process iocbs in the txq
  1424. * @phba: Pointer to HBA context object.
  1425. * @pring: Pointer to driver SLI ring object.
  1426. *
  1427. * This function is called with hbalock held to post pending iocbs
  1428. * in the txq to the firmware. This function is called when driver
  1429. * detects space available in the ring.
  1430. **/
  1431. static void
  1432. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1433. {
  1434. IOCB_t *iocb;
  1435. struct lpfc_iocbq *nextiocb;
  1436. /*
  1437. * Check to see if:
  1438. * (a) there is anything on the txq to send
  1439. * (b) link is up
  1440. * (c) link attention events can be processed (fcp ring only)
  1441. * (d) IOCB processing is not blocked by the outstanding mbox command.
  1442. */
  1443. if (pring->txq_cnt &&
  1444. lpfc_is_link_up(phba) &&
  1445. (pring->ringno != phba->sli.fcp_ring ||
  1446. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  1447. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  1448. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  1449. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  1450. if (iocb)
  1451. lpfc_sli_update_ring(phba, pring);
  1452. else
  1453. lpfc_sli_update_full_ring(phba, pring);
  1454. }
  1455. return;
  1456. }
  1457. /**
  1458. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  1459. * @phba: Pointer to HBA context object.
  1460. * @hbqno: HBQ number.
  1461. *
  1462. * This function is called with hbalock held to get the next
  1463. * available slot for the given HBQ. If there is free slot
  1464. * available for the HBQ it will return pointer to the next available
  1465. * HBQ entry else it will return NULL.
  1466. **/
  1467. static struct lpfc_hbq_entry *
  1468. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  1469. {
  1470. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1471. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  1472. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  1473. hbqp->next_hbqPutIdx = 0;
  1474. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  1475. uint32_t raw_index = phba->hbq_get[hbqno];
  1476. uint32_t getidx = le32_to_cpu(raw_index);
  1477. hbqp->local_hbqGetIdx = getidx;
  1478. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  1479. lpfc_printf_log(phba, KERN_ERR,
  1480. LOG_SLI | LOG_VPORT,
  1481. "1802 HBQ %d: local_hbqGetIdx "
  1482. "%u is > than hbqp->entry_count %u\n",
  1483. hbqno, hbqp->local_hbqGetIdx,
  1484. hbqp->entry_count);
  1485. phba->link_state = LPFC_HBA_ERROR;
  1486. return NULL;
  1487. }
  1488. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  1489. return NULL;
  1490. }
  1491. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  1492. hbqp->hbqPutIdx;
  1493. }
  1494. /**
  1495. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  1496. * @phba: Pointer to HBA context object.
  1497. *
  1498. * This function is called with no lock held to free all the
  1499. * hbq buffers while uninitializing the SLI interface. It also
  1500. * frees the HBQ buffers returned by the firmware but not yet
  1501. * processed by the upper layers.
  1502. **/
  1503. void
  1504. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  1505. {
  1506. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  1507. struct hbq_dmabuf *hbq_buf;
  1508. unsigned long flags;
  1509. int i, hbq_count;
  1510. uint32_t hbqno;
  1511. hbq_count = lpfc_sli_hbq_count();
  1512. /* Return all memory used by all HBQs */
  1513. spin_lock_irqsave(&phba->hbalock, flags);
  1514. for (i = 0; i < hbq_count; ++i) {
  1515. list_for_each_entry_safe(dmabuf, next_dmabuf,
  1516. &phba->hbqs[i].hbq_buffer_list, list) {
  1517. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1518. list_del(&hbq_buf->dbuf.list);
  1519. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  1520. }
  1521. phba->hbqs[i].buffer_count = 0;
  1522. }
  1523. /* Return all HBQ buffer that are in-fly */
  1524. list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list,
  1525. list) {
  1526. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  1527. list_del(&hbq_buf->dbuf.list);
  1528. if (hbq_buf->tag == -1) {
  1529. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1530. (phba, hbq_buf);
  1531. } else {
  1532. hbqno = hbq_buf->tag >> 16;
  1533. if (hbqno >= LPFC_MAX_HBQS)
  1534. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  1535. (phba, hbq_buf);
  1536. else
  1537. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  1538. hbq_buf);
  1539. }
  1540. }
  1541. /* Mark the HBQs not in use */
  1542. phba->hbq_in_use = 0;
  1543. spin_unlock_irqrestore(&phba->hbalock, flags);
  1544. }
  1545. /**
  1546. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  1547. * @phba: Pointer to HBA context object.
  1548. * @hbqno: HBQ number.
  1549. * @hbq_buf: Pointer to HBQ buffer.
  1550. *
  1551. * This function is called with the hbalock held to post a
  1552. * hbq buffer to the firmware. If the function finds an empty
  1553. * slot in the HBQ, it will post the buffer. The function will return
  1554. * pointer to the hbq entry if it successfully post the buffer
  1555. * else it will return NULL.
  1556. **/
  1557. static int
  1558. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  1559. struct hbq_dmabuf *hbq_buf)
  1560. {
  1561. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  1562. }
  1563. /**
  1564. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  1565. * @phba: Pointer to HBA context object.
  1566. * @hbqno: HBQ number.
  1567. * @hbq_buf: Pointer to HBQ buffer.
  1568. *
  1569. * This function is called with the hbalock held to post a hbq buffer to the
  1570. * firmware. If the function finds an empty slot in the HBQ, it will post the
  1571. * buffer and place it on the hbq_buffer_list. The function will return zero if
  1572. * it successfully post the buffer else it will return an error.
  1573. **/
  1574. static int
  1575. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  1576. struct hbq_dmabuf *hbq_buf)
  1577. {
  1578. struct lpfc_hbq_entry *hbqe;
  1579. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  1580. /* Get next HBQ entry slot to use */
  1581. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  1582. if (hbqe) {
  1583. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  1584. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1585. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1586. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  1587. hbqe->bde.tus.f.bdeFlags = 0;
  1588. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  1589. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  1590. /* Sync SLIM */
  1591. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  1592. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  1593. /* flush */
  1594. readl(phba->hbq_put + hbqno);
  1595. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  1596. return 0;
  1597. } else
  1598. return -ENOMEM;
  1599. }
  1600. /**
  1601. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  1602. * @phba: Pointer to HBA context object.
  1603. * @hbqno: HBQ number.
  1604. * @hbq_buf: Pointer to HBQ buffer.
  1605. *
  1606. * This function is called with the hbalock held to post an RQE to the SLI4
  1607. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  1608. * the hbq_buffer_list and return zero, otherwise it will return an error.
  1609. **/
  1610. static int
  1611. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  1612. struct hbq_dmabuf *hbq_buf)
  1613. {
  1614. int rc;
  1615. struct lpfc_rqe hrqe;
  1616. struct lpfc_rqe drqe;
  1617. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  1618. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  1619. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  1620. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  1621. rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  1622. &hrqe, &drqe);
  1623. if (rc < 0)
  1624. return rc;
  1625. hbq_buf->tag = rc;
  1626. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  1627. return 0;
  1628. }
  1629. /* HBQ for ELS and CT traffic. */
  1630. static struct lpfc_hbq_init lpfc_els_hbq = {
  1631. .rn = 1,
  1632. .entry_count = 256,
  1633. .mask_count = 0,
  1634. .profile = 0,
  1635. .ring_mask = (1 << LPFC_ELS_RING),
  1636. .buffer_count = 0,
  1637. .init_count = 40,
  1638. .add_count = 40,
  1639. };
  1640. /* HBQ for the extra ring if needed */
  1641. static struct lpfc_hbq_init lpfc_extra_hbq = {
  1642. .rn = 1,
  1643. .entry_count = 200,
  1644. .mask_count = 0,
  1645. .profile = 0,
  1646. .ring_mask = (1 << LPFC_EXTRA_RING),
  1647. .buffer_count = 0,
  1648. .init_count = 0,
  1649. .add_count = 5,
  1650. };
  1651. /* Array of HBQs */
  1652. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  1653. &lpfc_els_hbq,
  1654. &lpfc_extra_hbq,
  1655. };
  1656. /**
  1657. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  1658. * @phba: Pointer to HBA context object.
  1659. * @hbqno: HBQ number.
  1660. * @count: Number of HBQ buffers to be posted.
  1661. *
  1662. * This function is called with no lock held to post more hbq buffers to the
  1663. * given HBQ. The function returns the number of HBQ buffers successfully
  1664. * posted.
  1665. **/
  1666. static int
  1667. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  1668. {
  1669. uint32_t i, posted = 0;
  1670. unsigned long flags;
  1671. struct hbq_dmabuf *hbq_buffer;
  1672. LIST_HEAD(hbq_buf_list);
  1673. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  1674. return 0;
  1675. if ((phba->hbqs[hbqno].buffer_count + count) >
  1676. lpfc_hbq_defs[hbqno]->entry_count)
  1677. count = lpfc_hbq_defs[hbqno]->entry_count -
  1678. phba->hbqs[hbqno].buffer_count;
  1679. if (!count)
  1680. return 0;
  1681. /* Allocate HBQ entries */
  1682. for (i = 0; i < count; i++) {
  1683. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  1684. if (!hbq_buffer)
  1685. break;
  1686. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  1687. }
  1688. /* Check whether HBQ is still in use */
  1689. spin_lock_irqsave(&phba->hbalock, flags);
  1690. if (!phba->hbq_in_use)
  1691. goto err;
  1692. while (!list_empty(&hbq_buf_list)) {
  1693. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1694. dbuf.list);
  1695. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  1696. (hbqno << 16));
  1697. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  1698. phba->hbqs[hbqno].buffer_count++;
  1699. posted++;
  1700. } else
  1701. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1702. }
  1703. spin_unlock_irqrestore(&phba->hbalock, flags);
  1704. return posted;
  1705. err:
  1706. spin_unlock_irqrestore(&phba->hbalock, flags);
  1707. while (!list_empty(&hbq_buf_list)) {
  1708. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  1709. dbuf.list);
  1710. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1711. }
  1712. return 0;
  1713. }
  1714. /**
  1715. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  1716. * @phba: Pointer to HBA context object.
  1717. * @qno: HBQ number.
  1718. *
  1719. * This function posts more buffers to the HBQ. This function
  1720. * is called with no lock held. The function returns the number of HBQ entries
  1721. * successfully allocated.
  1722. **/
  1723. int
  1724. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1725. {
  1726. if (phba->sli_rev == LPFC_SLI_REV4)
  1727. return 0;
  1728. else
  1729. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1730. lpfc_hbq_defs[qno]->add_count);
  1731. }
  1732. /**
  1733. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  1734. * @phba: Pointer to HBA context object.
  1735. * @qno: HBQ queue number.
  1736. *
  1737. * This function is called from SLI initialization code path with
  1738. * no lock held to post initial HBQ buffers to firmware. The
  1739. * function returns the number of HBQ entries successfully allocated.
  1740. **/
  1741. static int
  1742. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  1743. {
  1744. if (phba->sli_rev == LPFC_SLI_REV4)
  1745. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1746. lpfc_hbq_defs[qno]->entry_count);
  1747. else
  1748. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  1749. lpfc_hbq_defs[qno]->init_count);
  1750. }
  1751. /**
  1752. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  1753. * @phba: Pointer to HBA context object.
  1754. * @hbqno: HBQ number.
  1755. *
  1756. * This function removes the first hbq buffer on an hbq list and returns a
  1757. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  1758. **/
  1759. static struct hbq_dmabuf *
  1760. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  1761. {
  1762. struct lpfc_dmabuf *d_buf;
  1763. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  1764. if (!d_buf)
  1765. return NULL;
  1766. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  1767. }
  1768. /**
  1769. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  1770. * @phba: Pointer to HBA context object.
  1771. * @tag: Tag of the hbq buffer.
  1772. *
  1773. * This function is called with hbalock held. This function searches
  1774. * for the hbq buffer associated with the given tag in the hbq buffer
  1775. * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
  1776. * it returns NULL.
  1777. **/
  1778. static struct hbq_dmabuf *
  1779. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  1780. {
  1781. struct lpfc_dmabuf *d_buf;
  1782. struct hbq_dmabuf *hbq_buf;
  1783. uint32_t hbqno;
  1784. hbqno = tag >> 16;
  1785. if (hbqno >= LPFC_MAX_HBQS)
  1786. return NULL;
  1787. spin_lock_irq(&phba->hbalock);
  1788. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  1789. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  1790. if (hbq_buf->tag == tag) {
  1791. spin_unlock_irq(&phba->hbalock);
  1792. return hbq_buf;
  1793. }
  1794. }
  1795. spin_unlock_irq(&phba->hbalock);
  1796. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  1797. "1803 Bad hbq tag. Data: x%x x%x\n",
  1798. tag, phba->hbqs[tag >> 16].buffer_count);
  1799. return NULL;
  1800. }
  1801. /**
  1802. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  1803. * @phba: Pointer to HBA context object.
  1804. * @hbq_buffer: Pointer to HBQ buffer.
  1805. *
  1806. * This function is called with hbalock. This function gives back
  1807. * the hbq buffer to firmware. If the HBQ does not have space to
  1808. * post the buffer, it will free the buffer.
  1809. **/
  1810. void
  1811. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  1812. {
  1813. uint32_t hbqno;
  1814. if (hbq_buffer) {
  1815. hbqno = hbq_buffer->tag >> 16;
  1816. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  1817. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  1818. }
  1819. }
  1820. /**
  1821. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  1822. * @mbxCommand: mailbox command code.
  1823. *
  1824. * This function is called by the mailbox event handler function to verify
  1825. * that the completed mailbox command is a legitimate mailbox command. If the
  1826. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  1827. * and the mailbox event handler will take the HBA offline.
  1828. **/
  1829. static int
  1830. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  1831. {
  1832. uint8_t ret;
  1833. switch (mbxCommand) {
  1834. case MBX_LOAD_SM:
  1835. case MBX_READ_NV:
  1836. case MBX_WRITE_NV:
  1837. case MBX_WRITE_VPARMS:
  1838. case MBX_RUN_BIU_DIAG:
  1839. case MBX_INIT_LINK:
  1840. case MBX_DOWN_LINK:
  1841. case MBX_CONFIG_LINK:
  1842. case MBX_CONFIG_RING:
  1843. case MBX_RESET_RING:
  1844. case MBX_READ_CONFIG:
  1845. case MBX_READ_RCONFIG:
  1846. case MBX_READ_SPARM:
  1847. case MBX_READ_STATUS:
  1848. case MBX_READ_RPI:
  1849. case MBX_READ_XRI:
  1850. case MBX_READ_REV:
  1851. case MBX_READ_LNK_STAT:
  1852. case MBX_REG_LOGIN:
  1853. case MBX_UNREG_LOGIN:
  1854. case MBX_CLEAR_LA:
  1855. case MBX_DUMP_MEMORY:
  1856. case MBX_DUMP_CONTEXT:
  1857. case MBX_RUN_DIAGS:
  1858. case MBX_RESTART:
  1859. case MBX_UPDATE_CFG:
  1860. case MBX_DOWN_LOAD:
  1861. case MBX_DEL_LD_ENTRY:
  1862. case MBX_RUN_PROGRAM:
  1863. case MBX_SET_MASK:
  1864. case MBX_SET_VARIABLE:
  1865. case MBX_UNREG_D_ID:
  1866. case MBX_KILL_BOARD:
  1867. case MBX_CONFIG_FARP:
  1868. case MBX_BEACON:
  1869. case MBX_LOAD_AREA:
  1870. case MBX_RUN_BIU_DIAG64:
  1871. case MBX_CONFIG_PORT:
  1872. case MBX_READ_SPARM64:
  1873. case MBX_READ_RPI64:
  1874. case MBX_REG_LOGIN64:
  1875. case MBX_READ_TOPOLOGY:
  1876. case MBX_WRITE_WWN:
  1877. case MBX_SET_DEBUG:
  1878. case MBX_LOAD_EXP_ROM:
  1879. case MBX_ASYNCEVT_ENABLE:
  1880. case MBX_REG_VPI:
  1881. case MBX_UNREG_VPI:
  1882. case MBX_HEARTBEAT:
  1883. case MBX_PORT_CAPABILITIES:
  1884. case MBX_PORT_IOV_CONTROL:
  1885. case MBX_SLI4_CONFIG:
  1886. case MBX_SLI4_REQ_FTRS:
  1887. case MBX_REG_FCFI:
  1888. case MBX_UNREG_FCFI:
  1889. case MBX_REG_VFI:
  1890. case MBX_UNREG_VFI:
  1891. case MBX_INIT_VPI:
  1892. case MBX_INIT_VFI:
  1893. case MBX_RESUME_RPI:
  1894. case MBX_READ_EVENT_LOG_STATUS:
  1895. case MBX_READ_EVENT_LOG:
  1896. case MBX_SECURITY_MGMT:
  1897. case MBX_AUTH_PORT:
  1898. ret = mbxCommand;
  1899. break;
  1900. default:
  1901. ret = MBX_SHUTDOWN;
  1902. break;
  1903. }
  1904. return ret;
  1905. }
  1906. /**
  1907. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  1908. * @phba: Pointer to HBA context object.
  1909. * @pmboxq: Pointer to mailbox command.
  1910. *
  1911. * This is completion handler function for mailbox commands issued from
  1912. * lpfc_sli_issue_mbox_wait function. This function is called by the
  1913. * mailbox event handler function with no lock held. This function
  1914. * will wake up thread waiting on the wait queue pointed by context1
  1915. * of the mailbox.
  1916. **/
  1917. void
  1918. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  1919. {
  1920. wait_queue_head_t *pdone_q;
  1921. unsigned long drvr_flag;
  1922. /*
  1923. * If pdone_q is empty, the driver thread gave up waiting and
  1924. * continued running.
  1925. */
  1926. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  1927. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1928. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  1929. if (pdone_q)
  1930. wake_up_interruptible(pdone_q);
  1931. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1932. return;
  1933. }
  1934. /**
  1935. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  1936. * @phba: Pointer to HBA context object.
  1937. * @pmb: Pointer to mailbox object.
  1938. *
  1939. * This function is the default mailbox completion handler. It
  1940. * frees the memory resources associated with the completed mailbox
  1941. * command. If the completed command is a REG_LOGIN mailbox command,
  1942. * this function will issue a UREG_LOGIN to re-claim the RPI.
  1943. **/
  1944. void
  1945. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1946. {
  1947. struct lpfc_vport *vport = pmb->vport;
  1948. struct lpfc_dmabuf *mp;
  1949. struct lpfc_nodelist *ndlp;
  1950. struct Scsi_Host *shost;
  1951. uint16_t rpi, vpi;
  1952. int rc;
  1953. mp = (struct lpfc_dmabuf *) (pmb->context1);
  1954. if (mp) {
  1955. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1956. kfree(mp);
  1957. }
  1958. /*
  1959. * If a REG_LOGIN succeeded after node is destroyed or node
  1960. * is in re-discovery driver need to cleanup the RPI.
  1961. */
  1962. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  1963. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  1964. !pmb->u.mb.mbxStatus) {
  1965. rpi = pmb->u.mb.un.varWords[0];
  1966. vpi = pmb->u.mb.un.varRegLogin.vpi;
  1967. lpfc_unreg_login(phba, vpi, rpi, pmb);
  1968. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1969. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1970. if (rc != MBX_NOT_FINISHED)
  1971. return;
  1972. }
  1973. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  1974. !(phba->pport->load_flag & FC_UNLOADING) &&
  1975. !pmb->u.mb.mbxStatus) {
  1976. shost = lpfc_shost_from_vport(vport);
  1977. spin_lock_irq(shost->host_lock);
  1978. vport->vpi_state |= LPFC_VPI_REGISTERED;
  1979. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  1980. spin_unlock_irq(shost->host_lock);
  1981. }
  1982. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  1983. ndlp = (struct lpfc_nodelist *)pmb->context2;
  1984. lpfc_nlp_put(ndlp);
  1985. pmb->context2 = NULL;
  1986. }
  1987. /* Check security permission status on INIT_LINK mailbox command */
  1988. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  1989. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  1990. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1991. "2860 SLI authentication is required "
  1992. "for INIT_LINK but has not done yet\n");
  1993. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  1994. lpfc_sli4_mbox_cmd_free(phba, pmb);
  1995. else
  1996. mempool_free(pmb, phba->mbox_mem_pool);
  1997. }
  1998. /**
  1999. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2000. * @phba: Pointer to HBA context object.
  2001. *
  2002. * This function is called with no lock held. This function processes all
  2003. * the completed mailbox commands and gives it to upper layers. The interrupt
  2004. * service routine processes mailbox completion interrupt and adds completed
  2005. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2006. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2007. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2008. * function returns the mailbox commands to the upper layer by calling the
  2009. * completion handler function of each mailbox.
  2010. **/
  2011. int
  2012. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2013. {
  2014. MAILBOX_t *pmbox;
  2015. LPFC_MBOXQ_t *pmb;
  2016. int rc;
  2017. LIST_HEAD(cmplq);
  2018. phba->sli.slistat.mbox_event++;
  2019. /* Get all completed mailboxe buffers into the cmplq */
  2020. spin_lock_irq(&phba->hbalock);
  2021. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2022. spin_unlock_irq(&phba->hbalock);
  2023. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2024. do {
  2025. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2026. if (pmb == NULL)
  2027. break;
  2028. pmbox = &pmb->u.mb;
  2029. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2030. if (pmb->vport) {
  2031. lpfc_debugfs_disc_trc(pmb->vport,
  2032. LPFC_DISC_TRC_MBOX_VPORT,
  2033. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2034. (uint32_t)pmbox->mbxCommand,
  2035. pmbox->un.varWords[0],
  2036. pmbox->un.varWords[1]);
  2037. }
  2038. else {
  2039. lpfc_debugfs_disc_trc(phba->pport,
  2040. LPFC_DISC_TRC_MBOX,
  2041. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2042. (uint32_t)pmbox->mbxCommand,
  2043. pmbox->un.varWords[0],
  2044. pmbox->un.varWords[1]);
  2045. }
  2046. }
  2047. /*
  2048. * It is a fatal error if unknown mbox command completion.
  2049. */
  2050. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2051. MBX_SHUTDOWN) {
  2052. /* Unknown mailbox command compl */
  2053. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2054. "(%d):0323 Unknown Mailbox command "
  2055. "x%x (x%x/x%x) Cmpl\n",
  2056. pmb->vport ? pmb->vport->vpi : 0,
  2057. pmbox->mbxCommand,
  2058. lpfc_sli_config_mbox_subsys_get(phba,
  2059. pmb),
  2060. lpfc_sli_config_mbox_opcode_get(phba,
  2061. pmb));
  2062. phba->link_state = LPFC_HBA_ERROR;
  2063. phba->work_hs = HS_FFER3;
  2064. lpfc_handle_eratt(phba);
  2065. continue;
  2066. }
  2067. if (pmbox->mbxStatus) {
  2068. phba->sli.slistat.mbox_stat_err++;
  2069. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2070. /* Mbox cmd cmpl error - RETRYing */
  2071. lpfc_printf_log(phba, KERN_INFO,
  2072. LOG_MBOX | LOG_SLI,
  2073. "(%d):0305 Mbox cmd cmpl "
  2074. "error - RETRYing Data: x%x "
  2075. "(x%x/x%x) x%x x%x x%x\n",
  2076. pmb->vport ? pmb->vport->vpi : 0,
  2077. pmbox->mbxCommand,
  2078. lpfc_sli_config_mbox_subsys_get(phba,
  2079. pmb),
  2080. lpfc_sli_config_mbox_opcode_get(phba,
  2081. pmb),
  2082. pmbox->mbxStatus,
  2083. pmbox->un.varWords[0],
  2084. pmb->vport->port_state);
  2085. pmbox->mbxStatus = 0;
  2086. pmbox->mbxOwner = OWN_HOST;
  2087. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2088. if (rc != MBX_NOT_FINISHED)
  2089. continue;
  2090. }
  2091. }
  2092. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2093. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2094. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
  2095. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2096. pmb->vport ? pmb->vport->vpi : 0,
  2097. pmbox->mbxCommand,
  2098. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2099. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2100. pmb->mbox_cmpl,
  2101. *((uint32_t *) pmbox),
  2102. pmbox->un.varWords[0],
  2103. pmbox->un.varWords[1],
  2104. pmbox->un.varWords[2],
  2105. pmbox->un.varWords[3],
  2106. pmbox->un.varWords[4],
  2107. pmbox->un.varWords[5],
  2108. pmbox->un.varWords[6],
  2109. pmbox->un.varWords[7]);
  2110. if (pmb->mbox_cmpl)
  2111. pmb->mbox_cmpl(phba,pmb);
  2112. } while (1);
  2113. return 0;
  2114. }
  2115. /**
  2116. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2117. * @phba: Pointer to HBA context object.
  2118. * @pring: Pointer to driver SLI ring object.
  2119. * @tag: buffer tag.
  2120. *
  2121. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2122. * is set in the tag the buffer is posted for a particular exchange,
  2123. * the function will return the buffer without replacing the buffer.
  2124. * If the buffer is for unsolicited ELS or CT traffic, this function
  2125. * returns the buffer and also posts another buffer to the firmware.
  2126. **/
  2127. static struct lpfc_dmabuf *
  2128. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2129. struct lpfc_sli_ring *pring,
  2130. uint32_t tag)
  2131. {
  2132. struct hbq_dmabuf *hbq_entry;
  2133. if (tag & QUE_BUFTAG_BIT)
  2134. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2135. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2136. if (!hbq_entry)
  2137. return NULL;
  2138. return &hbq_entry->dbuf;
  2139. }
  2140. /**
  2141. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2142. * @phba: Pointer to HBA context object.
  2143. * @pring: Pointer to driver SLI ring object.
  2144. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2145. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2146. * @fch_type: the type for the first frame of the sequence.
  2147. *
  2148. * This function is called with no lock held. This function uses the r_ctl and
  2149. * type of the received sequence to find the correct callback function to call
  2150. * to process the sequence.
  2151. **/
  2152. static int
  2153. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2154. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  2155. uint32_t fch_type)
  2156. {
  2157. int i;
  2158. /* unSolicited Responses */
  2159. if (pring->prt[0].profile) {
  2160. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  2161. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  2162. saveq);
  2163. return 1;
  2164. }
  2165. /* We must search, based on rctl / type
  2166. for the right routine */
  2167. for (i = 0; i < pring->num_mask; i++) {
  2168. if ((pring->prt[i].rctl == fch_r_ctl) &&
  2169. (pring->prt[i].type == fch_type)) {
  2170. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2171. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  2172. (phba, pring, saveq);
  2173. return 1;
  2174. }
  2175. }
  2176. return 0;
  2177. }
  2178. /**
  2179. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  2180. * @phba: Pointer to HBA context object.
  2181. * @pring: Pointer to driver SLI ring object.
  2182. * @saveq: Pointer to the unsolicited iocb.
  2183. *
  2184. * This function is called with no lock held by the ring event handler
  2185. * when there is an unsolicited iocb posted to the response ring by the
  2186. * firmware. This function gets the buffer associated with the iocbs
  2187. * and calls the event handler for the ring. This function handles both
  2188. * qring buffers and hbq buffers.
  2189. * When the function returns 1 the caller can free the iocb object otherwise
  2190. * upper layer functions will free the iocb objects.
  2191. **/
  2192. static int
  2193. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2194. struct lpfc_iocbq *saveq)
  2195. {
  2196. IOCB_t * irsp;
  2197. WORD5 * w5p;
  2198. uint32_t Rctl, Type;
  2199. uint32_t match;
  2200. struct lpfc_iocbq *iocbq;
  2201. struct lpfc_dmabuf *dmzbuf;
  2202. match = 0;
  2203. irsp = &(saveq->iocb);
  2204. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  2205. if (pring->lpfc_sli_rcv_async_status)
  2206. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  2207. else
  2208. lpfc_printf_log(phba,
  2209. KERN_WARNING,
  2210. LOG_SLI,
  2211. "0316 Ring %d handler: unexpected "
  2212. "ASYNC_STATUS iocb received evt_code "
  2213. "0x%x\n",
  2214. pring->ringno,
  2215. irsp->un.asyncstat.evt_code);
  2216. return 1;
  2217. }
  2218. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  2219. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  2220. if (irsp->ulpBdeCount > 0) {
  2221. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2222. irsp->un.ulpWord[3]);
  2223. lpfc_in_buf_free(phba, dmzbuf);
  2224. }
  2225. if (irsp->ulpBdeCount > 1) {
  2226. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2227. irsp->unsli3.sli3Words[3]);
  2228. lpfc_in_buf_free(phba, dmzbuf);
  2229. }
  2230. if (irsp->ulpBdeCount > 2) {
  2231. dmzbuf = lpfc_sli_get_buff(phba, pring,
  2232. irsp->unsli3.sli3Words[7]);
  2233. lpfc_in_buf_free(phba, dmzbuf);
  2234. }
  2235. return 1;
  2236. }
  2237. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2238. if (irsp->ulpBdeCount != 0) {
  2239. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  2240. irsp->un.ulpWord[3]);
  2241. if (!saveq->context2)
  2242. lpfc_printf_log(phba,
  2243. KERN_ERR,
  2244. LOG_SLI,
  2245. "0341 Ring %d Cannot find buffer for "
  2246. "an unsolicited iocb. tag 0x%x\n",
  2247. pring->ringno,
  2248. irsp->un.ulpWord[3]);
  2249. }
  2250. if (irsp->ulpBdeCount == 2) {
  2251. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  2252. irsp->unsli3.sli3Words[7]);
  2253. if (!saveq->context3)
  2254. lpfc_printf_log(phba,
  2255. KERN_ERR,
  2256. LOG_SLI,
  2257. "0342 Ring %d Cannot find buffer for an"
  2258. " unsolicited iocb. tag 0x%x\n",
  2259. pring->ringno,
  2260. irsp->unsli3.sli3Words[7]);
  2261. }
  2262. list_for_each_entry(iocbq, &saveq->list, list) {
  2263. irsp = &(iocbq->iocb);
  2264. if (irsp->ulpBdeCount != 0) {
  2265. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  2266. irsp->un.ulpWord[3]);
  2267. if (!iocbq->context2)
  2268. lpfc_printf_log(phba,
  2269. KERN_ERR,
  2270. LOG_SLI,
  2271. "0343 Ring %d Cannot find "
  2272. "buffer for an unsolicited iocb"
  2273. ". tag 0x%x\n", pring->ringno,
  2274. irsp->un.ulpWord[3]);
  2275. }
  2276. if (irsp->ulpBdeCount == 2) {
  2277. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  2278. irsp->unsli3.sli3Words[7]);
  2279. if (!iocbq->context3)
  2280. lpfc_printf_log(phba,
  2281. KERN_ERR,
  2282. LOG_SLI,
  2283. "0344 Ring %d Cannot find "
  2284. "buffer for an unsolicited "
  2285. "iocb. tag 0x%x\n",
  2286. pring->ringno,
  2287. irsp->unsli3.sli3Words[7]);
  2288. }
  2289. }
  2290. }
  2291. if (irsp->ulpBdeCount != 0 &&
  2292. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  2293. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  2294. int found = 0;
  2295. /* search continue save q for same XRI */
  2296. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  2297. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  2298. saveq->iocb.unsli3.rcvsli3.ox_id) {
  2299. list_add_tail(&saveq->list, &iocbq->list);
  2300. found = 1;
  2301. break;
  2302. }
  2303. }
  2304. if (!found)
  2305. list_add_tail(&saveq->clist,
  2306. &pring->iocb_continue_saveq);
  2307. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  2308. list_del_init(&iocbq->clist);
  2309. saveq = iocbq;
  2310. irsp = &(saveq->iocb);
  2311. } else
  2312. return 0;
  2313. }
  2314. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  2315. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  2316. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  2317. Rctl = FC_RCTL_ELS_REQ;
  2318. Type = FC_TYPE_ELS;
  2319. } else {
  2320. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  2321. Rctl = w5p->hcsw.Rctl;
  2322. Type = w5p->hcsw.Type;
  2323. /* Firmware Workaround */
  2324. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  2325. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  2326. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  2327. Rctl = FC_RCTL_ELS_REQ;
  2328. Type = FC_TYPE_ELS;
  2329. w5p->hcsw.Rctl = Rctl;
  2330. w5p->hcsw.Type = Type;
  2331. }
  2332. }
  2333. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  2334. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2335. "0313 Ring %d handler: unexpected Rctl x%x "
  2336. "Type x%x received\n",
  2337. pring->ringno, Rctl, Type);
  2338. return 1;
  2339. }
  2340. /**
  2341. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  2342. * @phba: Pointer to HBA context object.
  2343. * @pring: Pointer to driver SLI ring object.
  2344. * @prspiocb: Pointer to response iocb object.
  2345. *
  2346. * This function looks up the iocb_lookup table to get the command iocb
  2347. * corresponding to the given response iocb using the iotag of the
  2348. * response iocb. This function is called with the hbalock held.
  2349. * This function returns the command iocb object if it finds the command
  2350. * iocb else returns NULL.
  2351. **/
  2352. static struct lpfc_iocbq *
  2353. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  2354. struct lpfc_sli_ring *pring,
  2355. struct lpfc_iocbq *prspiocb)
  2356. {
  2357. struct lpfc_iocbq *cmd_iocb = NULL;
  2358. uint16_t iotag;
  2359. iotag = prspiocb->iocb.ulpIoTag;
  2360. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2361. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2362. list_del_init(&cmd_iocb->list);
  2363. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2364. pring->txcmplq_cnt--;
  2365. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2366. }
  2367. return cmd_iocb;
  2368. }
  2369. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2370. "0317 iotag x%x is out off "
  2371. "range: max iotag x%x wd0 x%x\n",
  2372. iotag, phba->sli.last_iotag,
  2373. *(((uint32_t *) &prspiocb->iocb) + 7));
  2374. return NULL;
  2375. }
  2376. /**
  2377. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  2378. * @phba: Pointer to HBA context object.
  2379. * @pring: Pointer to driver SLI ring object.
  2380. * @iotag: IOCB tag.
  2381. *
  2382. * This function looks up the iocb_lookup table to get the command iocb
  2383. * corresponding to the given iotag. This function is called with the
  2384. * hbalock held.
  2385. * This function returns the command iocb object if it finds the command
  2386. * iocb else returns NULL.
  2387. **/
  2388. static struct lpfc_iocbq *
  2389. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  2390. struct lpfc_sli_ring *pring, uint16_t iotag)
  2391. {
  2392. struct lpfc_iocbq *cmd_iocb;
  2393. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  2394. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  2395. list_del_init(&cmd_iocb->list);
  2396. if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) {
  2397. cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q;
  2398. pring->txcmplq_cnt--;
  2399. }
  2400. return cmd_iocb;
  2401. }
  2402. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2403. "0372 iotag x%x is out off range: max iotag (x%x)\n",
  2404. iotag, phba->sli.last_iotag);
  2405. return NULL;
  2406. }
  2407. /**
  2408. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  2409. * @phba: Pointer to HBA context object.
  2410. * @pring: Pointer to driver SLI ring object.
  2411. * @saveq: Pointer to the response iocb to be processed.
  2412. *
  2413. * This function is called by the ring event handler for non-fcp
  2414. * rings when there is a new response iocb in the response ring.
  2415. * The caller is not required to hold any locks. This function
  2416. * gets the command iocb associated with the response iocb and
  2417. * calls the completion handler for the command iocb. If there
  2418. * is no completion handler, the function will free the resources
  2419. * associated with command iocb. If the response iocb is for
  2420. * an already aborted command iocb, the status of the completion
  2421. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  2422. * This function always returns 1.
  2423. **/
  2424. static int
  2425. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2426. struct lpfc_iocbq *saveq)
  2427. {
  2428. struct lpfc_iocbq *cmdiocbp;
  2429. int rc = 1;
  2430. unsigned long iflag;
  2431. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  2432. spin_lock_irqsave(&phba->hbalock, iflag);
  2433. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  2434. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2435. if (cmdiocbp) {
  2436. if (cmdiocbp->iocb_cmpl) {
  2437. /*
  2438. * If an ELS command failed send an event to mgmt
  2439. * application.
  2440. */
  2441. if (saveq->iocb.ulpStatus &&
  2442. (pring->ringno == LPFC_ELS_RING) &&
  2443. (cmdiocbp->iocb.ulpCommand ==
  2444. CMD_ELS_REQUEST64_CR))
  2445. lpfc_send_els_failure_event(phba,
  2446. cmdiocbp, saveq);
  2447. /*
  2448. * Post all ELS completions to the worker thread.
  2449. * All other are passed to the completion callback.
  2450. */
  2451. if (pring->ringno == LPFC_ELS_RING) {
  2452. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  2453. (cmdiocbp->iocb_flag &
  2454. LPFC_DRIVER_ABORTED)) {
  2455. spin_lock_irqsave(&phba->hbalock,
  2456. iflag);
  2457. cmdiocbp->iocb_flag &=
  2458. ~LPFC_DRIVER_ABORTED;
  2459. spin_unlock_irqrestore(&phba->hbalock,
  2460. iflag);
  2461. saveq->iocb.ulpStatus =
  2462. IOSTAT_LOCAL_REJECT;
  2463. saveq->iocb.un.ulpWord[4] =
  2464. IOERR_SLI_ABORTED;
  2465. /* Firmware could still be in progress
  2466. * of DMAing payload, so don't free data
  2467. * buffer till after a hbeat.
  2468. */
  2469. spin_lock_irqsave(&phba->hbalock,
  2470. iflag);
  2471. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  2472. spin_unlock_irqrestore(&phba->hbalock,
  2473. iflag);
  2474. }
  2475. if (phba->sli_rev == LPFC_SLI_REV4) {
  2476. if (saveq->iocb_flag &
  2477. LPFC_EXCHANGE_BUSY) {
  2478. /* Set cmdiocb flag for the
  2479. * exchange busy so sgl (xri)
  2480. * will not be released until
  2481. * the abort xri is received
  2482. * from hba.
  2483. */
  2484. spin_lock_irqsave(
  2485. &phba->hbalock, iflag);
  2486. cmdiocbp->iocb_flag |=
  2487. LPFC_EXCHANGE_BUSY;
  2488. spin_unlock_irqrestore(
  2489. &phba->hbalock, iflag);
  2490. }
  2491. if (cmdiocbp->iocb_flag &
  2492. LPFC_DRIVER_ABORTED) {
  2493. /*
  2494. * Clear LPFC_DRIVER_ABORTED
  2495. * bit in case it was driver
  2496. * initiated abort.
  2497. */
  2498. spin_lock_irqsave(
  2499. &phba->hbalock, iflag);
  2500. cmdiocbp->iocb_flag &=
  2501. ~LPFC_DRIVER_ABORTED;
  2502. spin_unlock_irqrestore(
  2503. &phba->hbalock, iflag);
  2504. cmdiocbp->iocb.ulpStatus =
  2505. IOSTAT_LOCAL_REJECT;
  2506. cmdiocbp->iocb.un.ulpWord[4] =
  2507. IOERR_ABORT_REQUESTED;
  2508. /*
  2509. * For SLI4, irsiocb contains
  2510. * NO_XRI in sli_xritag, it
  2511. * shall not affect releasing
  2512. * sgl (xri) process.
  2513. */
  2514. saveq->iocb.ulpStatus =
  2515. IOSTAT_LOCAL_REJECT;
  2516. saveq->iocb.un.ulpWord[4] =
  2517. IOERR_SLI_ABORTED;
  2518. spin_lock_irqsave(
  2519. &phba->hbalock, iflag);
  2520. saveq->iocb_flag |=
  2521. LPFC_DELAY_MEM_FREE;
  2522. spin_unlock_irqrestore(
  2523. &phba->hbalock, iflag);
  2524. }
  2525. }
  2526. }
  2527. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  2528. } else
  2529. lpfc_sli_release_iocbq(phba, cmdiocbp);
  2530. } else {
  2531. /*
  2532. * Unknown initiating command based on the response iotag.
  2533. * This could be the case on the ELS ring because of
  2534. * lpfc_els_abort().
  2535. */
  2536. if (pring->ringno != LPFC_ELS_RING) {
  2537. /*
  2538. * Ring <ringno> handler: unexpected completion IoTag
  2539. * <IoTag>
  2540. */
  2541. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2542. "0322 Ring %d handler: "
  2543. "unexpected completion IoTag x%x "
  2544. "Data: x%x x%x x%x x%x\n",
  2545. pring->ringno,
  2546. saveq->iocb.ulpIoTag,
  2547. saveq->iocb.ulpStatus,
  2548. saveq->iocb.un.ulpWord[4],
  2549. saveq->iocb.ulpCommand,
  2550. saveq->iocb.ulpContext);
  2551. }
  2552. }
  2553. return rc;
  2554. }
  2555. /**
  2556. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  2557. * @phba: Pointer to HBA context object.
  2558. * @pring: Pointer to driver SLI ring object.
  2559. *
  2560. * This function is called from the iocb ring event handlers when
  2561. * put pointer is ahead of the get pointer for a ring. This function signal
  2562. * an error attention condition to the worker thread and the worker
  2563. * thread will transition the HBA to offline state.
  2564. **/
  2565. static void
  2566. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2567. {
  2568. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2569. /*
  2570. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  2571. * rsp ring <portRspMax>
  2572. */
  2573. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2574. "0312 Ring %d handler: portRspPut %d "
  2575. "is bigger than rsp ring %d\n",
  2576. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  2577. pring->numRiocb);
  2578. phba->link_state = LPFC_HBA_ERROR;
  2579. /*
  2580. * All error attention handlers are posted to
  2581. * worker thread
  2582. */
  2583. phba->work_ha |= HA_ERATT;
  2584. phba->work_hs = HS_FFER3;
  2585. lpfc_worker_wake_up(phba);
  2586. return;
  2587. }
  2588. /**
  2589. * lpfc_poll_eratt - Error attention polling timer timeout handler
  2590. * @ptr: Pointer to address of HBA context object.
  2591. *
  2592. * This function is invoked by the Error Attention polling timer when the
  2593. * timer times out. It will check the SLI Error Attention register for
  2594. * possible attention events. If so, it will post an Error Attention event
  2595. * and wake up worker thread to process it. Otherwise, it will set up the
  2596. * Error Attention polling timer for the next poll.
  2597. **/
  2598. void lpfc_poll_eratt(unsigned long ptr)
  2599. {
  2600. struct lpfc_hba *phba;
  2601. uint32_t eratt = 0;
  2602. phba = (struct lpfc_hba *)ptr;
  2603. /* Check chip HA register for error event */
  2604. eratt = lpfc_sli_check_eratt(phba);
  2605. if (eratt)
  2606. /* Tell the worker thread there is work to do */
  2607. lpfc_worker_wake_up(phba);
  2608. else
  2609. /* Restart the timer for next eratt poll */
  2610. mod_timer(&phba->eratt_poll, jiffies +
  2611. HZ * LPFC_ERATT_POLL_INTERVAL);
  2612. return;
  2613. }
  2614. /**
  2615. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  2616. * @phba: Pointer to HBA context object.
  2617. * @pring: Pointer to driver SLI ring object.
  2618. * @mask: Host attention register mask for this ring.
  2619. *
  2620. * This function is called from the interrupt context when there is a ring
  2621. * event for the fcp ring. The caller does not hold any lock.
  2622. * The function processes each response iocb in the response ring until it
  2623. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  2624. * LE bit set. The function will call the completion handler of the command iocb
  2625. * if the response iocb indicates a completion for a command iocb or it is
  2626. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  2627. * function if this is an unsolicited iocb.
  2628. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  2629. * to check it explicitly.
  2630. */
  2631. int
  2632. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  2633. struct lpfc_sli_ring *pring, uint32_t mask)
  2634. {
  2635. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  2636. IOCB_t *irsp = NULL;
  2637. IOCB_t *entry = NULL;
  2638. struct lpfc_iocbq *cmdiocbq = NULL;
  2639. struct lpfc_iocbq rspiocbq;
  2640. uint32_t status;
  2641. uint32_t portRspPut, portRspMax;
  2642. int rc = 1;
  2643. lpfc_iocb_type type;
  2644. unsigned long iflag;
  2645. uint32_t rsp_cmpl = 0;
  2646. spin_lock_irqsave(&phba->hbalock, iflag);
  2647. pring->stats.iocb_event++;
  2648. /*
  2649. * The next available response entry should never exceed the maximum
  2650. * entries. If it does, treat it as an adapter hardware error.
  2651. */
  2652. portRspMax = pring->numRiocb;
  2653. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2654. if (unlikely(portRspPut >= portRspMax)) {
  2655. lpfc_sli_rsp_pointers_error(phba, pring);
  2656. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2657. return 1;
  2658. }
  2659. if (phba->fcp_ring_in_use) {
  2660. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2661. return 1;
  2662. } else
  2663. phba->fcp_ring_in_use = 1;
  2664. rmb();
  2665. while (pring->rspidx != portRspPut) {
  2666. /*
  2667. * Fetch an entry off the ring and copy it into a local data
  2668. * structure. The copy involves a byte-swap since the
  2669. * network byte order and pci byte orders are different.
  2670. */
  2671. entry = lpfc_resp_iocb(phba, pring);
  2672. phba->last_completion_time = jiffies;
  2673. if (++pring->rspidx >= portRspMax)
  2674. pring->rspidx = 0;
  2675. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  2676. (uint32_t *) &rspiocbq.iocb,
  2677. phba->iocb_rsp_size);
  2678. INIT_LIST_HEAD(&(rspiocbq.list));
  2679. irsp = &rspiocbq.iocb;
  2680. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  2681. pring->stats.iocb_rsp++;
  2682. rsp_cmpl++;
  2683. if (unlikely(irsp->ulpStatus)) {
  2684. /*
  2685. * If resource errors reported from HBA, reduce
  2686. * queuedepths of the SCSI device.
  2687. */
  2688. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2689. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2690. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2691. phba->lpfc_rampdown_queue_depth(phba);
  2692. spin_lock_irqsave(&phba->hbalock, iflag);
  2693. }
  2694. /* Rsp ring <ringno> error: IOCB */
  2695. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2696. "0336 Rsp Ring %d error: IOCB Data: "
  2697. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  2698. pring->ringno,
  2699. irsp->un.ulpWord[0],
  2700. irsp->un.ulpWord[1],
  2701. irsp->un.ulpWord[2],
  2702. irsp->un.ulpWord[3],
  2703. irsp->un.ulpWord[4],
  2704. irsp->un.ulpWord[5],
  2705. *(uint32_t *)&irsp->un1,
  2706. *((uint32_t *)&irsp->un1 + 1));
  2707. }
  2708. switch (type) {
  2709. case LPFC_ABORT_IOCB:
  2710. case LPFC_SOL_IOCB:
  2711. /*
  2712. * Idle exchange closed via ABTS from port. No iocb
  2713. * resources need to be recovered.
  2714. */
  2715. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  2716. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2717. "0333 IOCB cmd 0x%x"
  2718. " processed. Skipping"
  2719. " completion\n",
  2720. irsp->ulpCommand);
  2721. break;
  2722. }
  2723. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  2724. &rspiocbq);
  2725. if (unlikely(!cmdiocbq))
  2726. break;
  2727. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
  2728. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  2729. if (cmdiocbq->iocb_cmpl) {
  2730. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2731. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  2732. &rspiocbq);
  2733. spin_lock_irqsave(&phba->hbalock, iflag);
  2734. }
  2735. break;
  2736. case LPFC_UNSOL_IOCB:
  2737. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2738. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  2739. spin_lock_irqsave(&phba->hbalock, iflag);
  2740. break;
  2741. default:
  2742. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2743. char adaptermsg[LPFC_MAX_ADPTMSG];
  2744. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2745. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  2746. MAX_MSG_DATA);
  2747. dev_warn(&((phba->pcidev)->dev),
  2748. "lpfc%d: %s\n",
  2749. phba->brd_no, adaptermsg);
  2750. } else {
  2751. /* Unknown IOCB command */
  2752. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2753. "0334 Unknown IOCB command "
  2754. "Data: x%x, x%x x%x x%x x%x\n",
  2755. type, irsp->ulpCommand,
  2756. irsp->ulpStatus,
  2757. irsp->ulpIoTag,
  2758. irsp->ulpContext);
  2759. }
  2760. break;
  2761. }
  2762. /*
  2763. * The response IOCB has been processed. Update the ring
  2764. * pointer in SLIM. If the port response put pointer has not
  2765. * been updated, sync the pgp->rspPutInx and fetch the new port
  2766. * response put pointer.
  2767. */
  2768. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  2769. if (pring->rspidx == portRspPut)
  2770. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2771. }
  2772. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  2773. pring->stats.iocb_rsp_full++;
  2774. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  2775. writel(status, phba->CAregaddr);
  2776. readl(phba->CAregaddr);
  2777. }
  2778. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  2779. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  2780. pring->stats.iocb_cmd_empty++;
  2781. /* Force update of the local copy of cmdGetInx */
  2782. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  2783. lpfc_sli_resume_iocb(phba, pring);
  2784. if ((pring->lpfc_sli_cmd_available))
  2785. (pring->lpfc_sli_cmd_available) (phba, pring);
  2786. }
  2787. phba->fcp_ring_in_use = 0;
  2788. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2789. return rc;
  2790. }
  2791. /**
  2792. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  2793. * @phba: Pointer to HBA context object.
  2794. * @pring: Pointer to driver SLI ring object.
  2795. * @rspiocbp: Pointer to driver response IOCB object.
  2796. *
  2797. * This function is called from the worker thread when there is a slow-path
  2798. * response IOCB to process. This function chains all the response iocbs until
  2799. * seeing the iocb with the LE bit set. The function will call
  2800. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  2801. * completion of a command iocb. The function will call the
  2802. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  2803. * The function frees the resources or calls the completion handler if this
  2804. * iocb is an abort completion. The function returns NULL when the response
  2805. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  2806. * this function shall chain the iocb on to the iocb_continueq and return the
  2807. * response iocb passed in.
  2808. **/
  2809. static struct lpfc_iocbq *
  2810. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2811. struct lpfc_iocbq *rspiocbp)
  2812. {
  2813. struct lpfc_iocbq *saveq;
  2814. struct lpfc_iocbq *cmdiocbp;
  2815. struct lpfc_iocbq *next_iocb;
  2816. IOCB_t *irsp = NULL;
  2817. uint32_t free_saveq;
  2818. uint8_t iocb_cmd_type;
  2819. lpfc_iocb_type type;
  2820. unsigned long iflag;
  2821. int rc;
  2822. spin_lock_irqsave(&phba->hbalock, iflag);
  2823. /* First add the response iocb to the countinueq list */
  2824. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  2825. pring->iocb_continueq_cnt++;
  2826. /* Now, determine whether the list is completed for processing */
  2827. irsp = &rspiocbp->iocb;
  2828. if (irsp->ulpLe) {
  2829. /*
  2830. * By default, the driver expects to free all resources
  2831. * associated with this iocb completion.
  2832. */
  2833. free_saveq = 1;
  2834. saveq = list_get_first(&pring->iocb_continueq,
  2835. struct lpfc_iocbq, list);
  2836. irsp = &(saveq->iocb);
  2837. list_del_init(&pring->iocb_continueq);
  2838. pring->iocb_continueq_cnt = 0;
  2839. pring->stats.iocb_rsp++;
  2840. /*
  2841. * If resource errors reported from HBA, reduce
  2842. * queuedepths of the SCSI device.
  2843. */
  2844. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2845. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  2846. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2847. phba->lpfc_rampdown_queue_depth(phba);
  2848. spin_lock_irqsave(&phba->hbalock, iflag);
  2849. }
  2850. if (irsp->ulpStatus) {
  2851. /* Rsp ring <ringno> error: IOCB */
  2852. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  2853. "0328 Rsp Ring %d error: "
  2854. "IOCB Data: "
  2855. "x%x x%x x%x x%x "
  2856. "x%x x%x x%x x%x "
  2857. "x%x x%x x%x x%x "
  2858. "x%x x%x x%x x%x\n",
  2859. pring->ringno,
  2860. irsp->un.ulpWord[0],
  2861. irsp->un.ulpWord[1],
  2862. irsp->un.ulpWord[2],
  2863. irsp->un.ulpWord[3],
  2864. irsp->un.ulpWord[4],
  2865. irsp->un.ulpWord[5],
  2866. *(((uint32_t *) irsp) + 6),
  2867. *(((uint32_t *) irsp) + 7),
  2868. *(((uint32_t *) irsp) + 8),
  2869. *(((uint32_t *) irsp) + 9),
  2870. *(((uint32_t *) irsp) + 10),
  2871. *(((uint32_t *) irsp) + 11),
  2872. *(((uint32_t *) irsp) + 12),
  2873. *(((uint32_t *) irsp) + 13),
  2874. *(((uint32_t *) irsp) + 14),
  2875. *(((uint32_t *) irsp) + 15));
  2876. }
  2877. /*
  2878. * Fetch the IOCB command type and call the correct completion
  2879. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  2880. * get freed back to the lpfc_iocb_list by the discovery
  2881. * kernel thread.
  2882. */
  2883. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  2884. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  2885. switch (type) {
  2886. case LPFC_SOL_IOCB:
  2887. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2888. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  2889. spin_lock_irqsave(&phba->hbalock, iflag);
  2890. break;
  2891. case LPFC_UNSOL_IOCB:
  2892. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2893. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  2894. spin_lock_irqsave(&phba->hbalock, iflag);
  2895. if (!rc)
  2896. free_saveq = 0;
  2897. break;
  2898. case LPFC_ABORT_IOCB:
  2899. cmdiocbp = NULL;
  2900. if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
  2901. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
  2902. saveq);
  2903. if (cmdiocbp) {
  2904. /* Call the specified completion routine */
  2905. if (cmdiocbp->iocb_cmpl) {
  2906. spin_unlock_irqrestore(&phba->hbalock,
  2907. iflag);
  2908. (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
  2909. saveq);
  2910. spin_lock_irqsave(&phba->hbalock,
  2911. iflag);
  2912. } else
  2913. __lpfc_sli_release_iocbq(phba,
  2914. cmdiocbp);
  2915. }
  2916. break;
  2917. case LPFC_UNKNOWN_IOCB:
  2918. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  2919. char adaptermsg[LPFC_MAX_ADPTMSG];
  2920. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  2921. memcpy(&adaptermsg[0], (uint8_t *)irsp,
  2922. MAX_MSG_DATA);
  2923. dev_warn(&((phba->pcidev)->dev),
  2924. "lpfc%d: %s\n",
  2925. phba->brd_no, adaptermsg);
  2926. } else {
  2927. /* Unknown IOCB command */
  2928. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2929. "0335 Unknown IOCB "
  2930. "command Data: x%x "
  2931. "x%x x%x x%x\n",
  2932. irsp->ulpCommand,
  2933. irsp->ulpStatus,
  2934. irsp->ulpIoTag,
  2935. irsp->ulpContext);
  2936. }
  2937. break;
  2938. }
  2939. if (free_saveq) {
  2940. list_for_each_entry_safe(rspiocbp, next_iocb,
  2941. &saveq->list, list) {
  2942. list_del(&rspiocbp->list);
  2943. __lpfc_sli_release_iocbq(phba, rspiocbp);
  2944. }
  2945. __lpfc_sli_release_iocbq(phba, saveq);
  2946. }
  2947. rspiocbp = NULL;
  2948. }
  2949. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2950. return rspiocbp;
  2951. }
  2952. /**
  2953. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  2954. * @phba: Pointer to HBA context object.
  2955. * @pring: Pointer to driver SLI ring object.
  2956. * @mask: Host attention register mask for this ring.
  2957. *
  2958. * This routine wraps the actual slow_ring event process routine from the
  2959. * API jump table function pointer from the lpfc_hba struct.
  2960. **/
  2961. void
  2962. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  2963. struct lpfc_sli_ring *pring, uint32_t mask)
  2964. {
  2965. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  2966. }
  2967. /**
  2968. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  2969. * @phba: Pointer to HBA context object.
  2970. * @pring: Pointer to driver SLI ring object.
  2971. * @mask: Host attention register mask for this ring.
  2972. *
  2973. * This function is called from the worker thread when there is a ring event
  2974. * for non-fcp rings. The caller does not hold any lock. The function will
  2975. * remove each response iocb in the response ring and calls the handle
  2976. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  2977. **/
  2978. static void
  2979. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  2980. struct lpfc_sli_ring *pring, uint32_t mask)
  2981. {
  2982. struct lpfc_pgp *pgp;
  2983. IOCB_t *entry;
  2984. IOCB_t *irsp = NULL;
  2985. struct lpfc_iocbq *rspiocbp = NULL;
  2986. uint32_t portRspPut, portRspMax;
  2987. unsigned long iflag;
  2988. uint32_t status;
  2989. pgp = &phba->port_gp[pring->ringno];
  2990. spin_lock_irqsave(&phba->hbalock, iflag);
  2991. pring->stats.iocb_event++;
  2992. /*
  2993. * The next available response entry should never exceed the maximum
  2994. * entries. If it does, treat it as an adapter hardware error.
  2995. */
  2996. portRspMax = pring->numRiocb;
  2997. portRspPut = le32_to_cpu(pgp->rspPutInx);
  2998. if (portRspPut >= portRspMax) {
  2999. /*
  3000. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3001. * rsp ring <portRspMax>
  3002. */
  3003. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3004. "0303 Ring %d handler: portRspPut %d "
  3005. "is bigger than rsp ring %d\n",
  3006. pring->ringno, portRspPut, portRspMax);
  3007. phba->link_state = LPFC_HBA_ERROR;
  3008. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3009. phba->work_hs = HS_FFER3;
  3010. lpfc_handle_eratt(phba);
  3011. return;
  3012. }
  3013. rmb();
  3014. while (pring->rspidx != portRspPut) {
  3015. /*
  3016. * Build a completion list and call the appropriate handler.
  3017. * The process is to get the next available response iocb, get
  3018. * a free iocb from the list, copy the response data into the
  3019. * free iocb, insert to the continuation list, and update the
  3020. * next response index to slim. This process makes response
  3021. * iocb's in the ring available to DMA as fast as possible but
  3022. * pays a penalty for a copy operation. Since the iocb is
  3023. * only 32 bytes, this penalty is considered small relative to
  3024. * the PCI reads for register values and a slim write. When
  3025. * the ulpLe field is set, the entire Command has been
  3026. * received.
  3027. */
  3028. entry = lpfc_resp_iocb(phba, pring);
  3029. phba->last_completion_time = jiffies;
  3030. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3031. if (rspiocbp == NULL) {
  3032. printk(KERN_ERR "%s: out of buffers! Failing "
  3033. "completion.\n", __func__);
  3034. break;
  3035. }
  3036. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  3037. phba->iocb_rsp_size);
  3038. irsp = &rspiocbp->iocb;
  3039. if (++pring->rspidx >= portRspMax)
  3040. pring->rspidx = 0;
  3041. if (pring->ringno == LPFC_ELS_RING) {
  3042. lpfc_debugfs_slow_ring_trc(phba,
  3043. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  3044. *(((uint32_t *) irsp) + 4),
  3045. *(((uint32_t *) irsp) + 6),
  3046. *(((uint32_t *) irsp) + 7));
  3047. }
  3048. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  3049. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3050. /* Handle the response IOCB */
  3051. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  3052. spin_lock_irqsave(&phba->hbalock, iflag);
  3053. /*
  3054. * If the port response put pointer has not been updated, sync
  3055. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  3056. * response put pointer.
  3057. */
  3058. if (pring->rspidx == portRspPut) {
  3059. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3060. }
  3061. } /* while (pring->rspidx != portRspPut) */
  3062. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  3063. /* At least one response entry has been freed */
  3064. pring->stats.iocb_rsp_full++;
  3065. /* SET RxRE_RSP in Chip Att register */
  3066. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3067. writel(status, phba->CAregaddr);
  3068. readl(phba->CAregaddr); /* flush */
  3069. }
  3070. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3071. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3072. pring->stats.iocb_cmd_empty++;
  3073. /* Force update of the local copy of cmdGetInx */
  3074. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3075. lpfc_sli_resume_iocb(phba, pring);
  3076. if ((pring->lpfc_sli_cmd_available))
  3077. (pring->lpfc_sli_cmd_available) (phba, pring);
  3078. }
  3079. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3080. return;
  3081. }
  3082. /**
  3083. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  3084. * @phba: Pointer to HBA context object.
  3085. * @pring: Pointer to driver SLI ring object.
  3086. * @mask: Host attention register mask for this ring.
  3087. *
  3088. * This function is called from the worker thread when there is a pending
  3089. * ELS response iocb on the driver internal slow-path response iocb worker
  3090. * queue. The caller does not hold any lock. The function will remove each
  3091. * response iocb from the response worker queue and calls the handle
  3092. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3093. **/
  3094. static void
  3095. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  3096. struct lpfc_sli_ring *pring, uint32_t mask)
  3097. {
  3098. struct lpfc_iocbq *irspiocbq;
  3099. struct hbq_dmabuf *dmabuf;
  3100. struct lpfc_cq_event *cq_event;
  3101. unsigned long iflag;
  3102. spin_lock_irqsave(&phba->hbalock, iflag);
  3103. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  3104. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3105. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  3106. /* Get the response iocb from the head of work queue */
  3107. spin_lock_irqsave(&phba->hbalock, iflag);
  3108. list_remove_head(&phba->sli4_hba.sp_queue_event,
  3109. cq_event, struct lpfc_cq_event, list);
  3110. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3111. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  3112. case CQE_CODE_COMPL_WQE:
  3113. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  3114. cq_event);
  3115. /* Translate ELS WCQE to response IOCBQ */
  3116. irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
  3117. irspiocbq);
  3118. if (irspiocbq)
  3119. lpfc_sli_sp_handle_rspiocb(phba, pring,
  3120. irspiocbq);
  3121. break;
  3122. case CQE_CODE_RECEIVE:
  3123. case CQE_CODE_RECEIVE_V1:
  3124. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  3125. cq_event);
  3126. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  3127. break;
  3128. default:
  3129. break;
  3130. }
  3131. }
  3132. }
  3133. /**
  3134. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  3135. * @phba: Pointer to HBA context object.
  3136. * @pring: Pointer to driver SLI ring object.
  3137. *
  3138. * This function aborts all iocbs in the given ring and frees all the iocb
  3139. * objects in txq. This function issues an abort iocb for all the iocb commands
  3140. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  3141. * the return of this function. The caller is not required to hold any locks.
  3142. **/
  3143. void
  3144. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3145. {
  3146. LIST_HEAD(completions);
  3147. struct lpfc_iocbq *iocb, *next_iocb;
  3148. if (pring->ringno == LPFC_ELS_RING) {
  3149. lpfc_fabric_abort_hba(phba);
  3150. }
  3151. /* Error everything on txq and txcmplq
  3152. * First do the txq.
  3153. */
  3154. spin_lock_irq(&phba->hbalock);
  3155. list_splice_init(&pring->txq, &completions);
  3156. pring->txq_cnt = 0;
  3157. /* Next issue ABTS for everything on the txcmplq */
  3158. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  3159. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3160. spin_unlock_irq(&phba->hbalock);
  3161. /* Cancel all the IOCBs from the completions list */
  3162. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3163. IOERR_SLI_ABORTED);
  3164. }
  3165. /**
  3166. * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
  3167. * @phba: Pointer to HBA context object.
  3168. *
  3169. * This function flushes all iocbs in the fcp ring and frees all the iocb
  3170. * objects in txq and txcmplq. This function will not issue abort iocbs
  3171. * for all the iocb commands in txcmplq, they will just be returned with
  3172. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  3173. * slot has been permanently disabled.
  3174. **/
  3175. void
  3176. lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
  3177. {
  3178. LIST_HEAD(txq);
  3179. LIST_HEAD(txcmplq);
  3180. struct lpfc_sli *psli = &phba->sli;
  3181. struct lpfc_sli_ring *pring;
  3182. /* Currently, only one fcp ring */
  3183. pring = &psli->ring[psli->fcp_ring];
  3184. spin_lock_irq(&phba->hbalock);
  3185. /* Retrieve everything on txq */
  3186. list_splice_init(&pring->txq, &txq);
  3187. pring->txq_cnt = 0;
  3188. /* Retrieve everything on the txcmplq */
  3189. list_splice_init(&pring->txcmplq, &txcmplq);
  3190. pring->txcmplq_cnt = 0;
  3191. spin_unlock_irq(&phba->hbalock);
  3192. /* Flush the txq */
  3193. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  3194. IOERR_SLI_DOWN);
  3195. /* Flush the txcmpq */
  3196. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  3197. IOERR_SLI_DOWN);
  3198. }
  3199. /**
  3200. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  3201. * @phba: Pointer to HBA context object.
  3202. * @mask: Bit mask to be checked.
  3203. *
  3204. * This function reads the host status register and compares
  3205. * with the provided bit mask to check if HBA completed
  3206. * the restart. This function will wait in a loop for the
  3207. * HBA to complete restart. If the HBA does not restart within
  3208. * 15 iterations, the function will reset the HBA again. The
  3209. * function returns 1 when HBA fail to restart otherwise returns
  3210. * zero.
  3211. **/
  3212. static int
  3213. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  3214. {
  3215. uint32_t status;
  3216. int i = 0;
  3217. int retval = 0;
  3218. /* Read the HBA Host Status Register */
  3219. if (lpfc_readl(phba->HSregaddr, &status))
  3220. return 1;
  3221. /*
  3222. * Check status register every 100ms for 5 retries, then every
  3223. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  3224. * every 2.5 sec for 4.
  3225. * Break our of the loop if errors occurred during init.
  3226. */
  3227. while (((status & mask) != mask) &&
  3228. !(status & HS_FFERM) &&
  3229. i++ < 20) {
  3230. if (i <= 5)
  3231. msleep(10);
  3232. else if (i <= 10)
  3233. msleep(500);
  3234. else
  3235. msleep(2500);
  3236. if (i == 15) {
  3237. /* Do post */
  3238. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3239. lpfc_sli_brdrestart(phba);
  3240. }
  3241. /* Read the HBA Host Status Register */
  3242. if (lpfc_readl(phba->HSregaddr, &status)) {
  3243. retval = 1;
  3244. break;
  3245. }
  3246. }
  3247. /* Check to see if any errors occurred during init */
  3248. if ((status & HS_FFERM) || (i >= 20)) {
  3249. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3250. "2751 Adapter failed to restart, "
  3251. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  3252. status,
  3253. readl(phba->MBslimaddr + 0xa8),
  3254. readl(phba->MBslimaddr + 0xac));
  3255. phba->link_state = LPFC_HBA_ERROR;
  3256. retval = 1;
  3257. }
  3258. return retval;
  3259. }
  3260. /**
  3261. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  3262. * @phba: Pointer to HBA context object.
  3263. * @mask: Bit mask to be checked.
  3264. *
  3265. * This function checks the host status register to check if HBA is
  3266. * ready. This function will wait in a loop for the HBA to be ready
  3267. * If the HBA is not ready , the function will will reset the HBA PCI
  3268. * function again. The function returns 1 when HBA fail to be ready
  3269. * otherwise returns zero.
  3270. **/
  3271. static int
  3272. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  3273. {
  3274. uint32_t status;
  3275. int retval = 0;
  3276. /* Read the HBA Host Status Register */
  3277. status = lpfc_sli4_post_status_check(phba);
  3278. if (status) {
  3279. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3280. lpfc_sli_brdrestart(phba);
  3281. status = lpfc_sli4_post_status_check(phba);
  3282. }
  3283. /* Check to see if any errors occurred during init */
  3284. if (status) {
  3285. phba->link_state = LPFC_HBA_ERROR;
  3286. retval = 1;
  3287. } else
  3288. phba->sli4_hba.intr_enable = 0;
  3289. return retval;
  3290. }
  3291. /**
  3292. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  3293. * @phba: Pointer to HBA context object.
  3294. * @mask: Bit mask to be checked.
  3295. *
  3296. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  3297. * from the API jump table function pointer from the lpfc_hba struct.
  3298. **/
  3299. int
  3300. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  3301. {
  3302. return phba->lpfc_sli_brdready(phba, mask);
  3303. }
  3304. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  3305. /**
  3306. * lpfc_reset_barrier - Make HBA ready for HBA reset
  3307. * @phba: Pointer to HBA context object.
  3308. *
  3309. * This function is called before resetting an HBA. This function is called
  3310. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  3311. **/
  3312. void lpfc_reset_barrier(struct lpfc_hba *phba)
  3313. {
  3314. uint32_t __iomem *resp_buf;
  3315. uint32_t __iomem *mbox_buf;
  3316. volatile uint32_t mbox;
  3317. uint32_t hc_copy, ha_copy, resp_data;
  3318. int i;
  3319. uint8_t hdrtype;
  3320. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  3321. if (hdrtype != 0x80 ||
  3322. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  3323. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  3324. return;
  3325. /*
  3326. * Tell the other part of the chip to suspend temporarily all
  3327. * its DMA activity.
  3328. */
  3329. resp_buf = phba->MBslimaddr;
  3330. /* Disable the error attention */
  3331. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  3332. return;
  3333. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  3334. readl(phba->HCregaddr); /* flush */
  3335. phba->link_flag |= LS_IGNORE_ERATT;
  3336. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3337. return;
  3338. if (ha_copy & HA_ERATT) {
  3339. /* Clear Chip error bit */
  3340. writel(HA_ERATT, phba->HAregaddr);
  3341. phba->pport->stopped = 1;
  3342. }
  3343. mbox = 0;
  3344. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  3345. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  3346. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  3347. mbox_buf = phba->MBslimaddr;
  3348. writel(mbox, mbox_buf);
  3349. for (i = 0; i < 50; i++) {
  3350. if (lpfc_readl((resp_buf + 1), &resp_data))
  3351. return;
  3352. if (resp_data != ~(BARRIER_TEST_PATTERN))
  3353. mdelay(1);
  3354. else
  3355. break;
  3356. }
  3357. resp_data = 0;
  3358. if (lpfc_readl((resp_buf + 1), &resp_data))
  3359. return;
  3360. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  3361. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  3362. phba->pport->stopped)
  3363. goto restore_hc;
  3364. else
  3365. goto clear_errat;
  3366. }
  3367. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  3368. resp_data = 0;
  3369. for (i = 0; i < 500; i++) {
  3370. if (lpfc_readl(resp_buf, &resp_data))
  3371. return;
  3372. if (resp_data != mbox)
  3373. mdelay(1);
  3374. else
  3375. break;
  3376. }
  3377. clear_errat:
  3378. while (++i < 500) {
  3379. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3380. return;
  3381. if (!(ha_copy & HA_ERATT))
  3382. mdelay(1);
  3383. else
  3384. break;
  3385. }
  3386. if (readl(phba->HAregaddr) & HA_ERATT) {
  3387. writel(HA_ERATT, phba->HAregaddr);
  3388. phba->pport->stopped = 1;
  3389. }
  3390. restore_hc:
  3391. phba->link_flag &= ~LS_IGNORE_ERATT;
  3392. writel(hc_copy, phba->HCregaddr);
  3393. readl(phba->HCregaddr); /* flush */
  3394. }
  3395. /**
  3396. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  3397. * @phba: Pointer to HBA context object.
  3398. *
  3399. * This function issues a kill_board mailbox command and waits for
  3400. * the error attention interrupt. This function is called for stopping
  3401. * the firmware processing. The caller is not required to hold any
  3402. * locks. This function calls lpfc_hba_down_post function to free
  3403. * any pending commands after the kill. The function will return 1 when it
  3404. * fails to kill the board else will return 0.
  3405. **/
  3406. int
  3407. lpfc_sli_brdkill(struct lpfc_hba *phba)
  3408. {
  3409. struct lpfc_sli *psli;
  3410. LPFC_MBOXQ_t *pmb;
  3411. uint32_t status;
  3412. uint32_t ha_copy;
  3413. int retval;
  3414. int i = 0;
  3415. psli = &phba->sli;
  3416. /* Kill HBA */
  3417. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3418. "0329 Kill HBA Data: x%x x%x\n",
  3419. phba->pport->port_state, psli->sli_flag);
  3420. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3421. if (!pmb)
  3422. return 1;
  3423. /* Disable the error attention */
  3424. spin_lock_irq(&phba->hbalock);
  3425. if (lpfc_readl(phba->HCregaddr, &status)) {
  3426. spin_unlock_irq(&phba->hbalock);
  3427. mempool_free(pmb, phba->mbox_mem_pool);
  3428. return 1;
  3429. }
  3430. status &= ~HC_ERINT_ENA;
  3431. writel(status, phba->HCregaddr);
  3432. readl(phba->HCregaddr); /* flush */
  3433. phba->link_flag |= LS_IGNORE_ERATT;
  3434. spin_unlock_irq(&phba->hbalock);
  3435. lpfc_kill_board(phba, pmb);
  3436. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3437. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3438. if (retval != MBX_SUCCESS) {
  3439. if (retval != MBX_BUSY)
  3440. mempool_free(pmb, phba->mbox_mem_pool);
  3441. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3442. "2752 KILL_BOARD command failed retval %d\n",
  3443. retval);
  3444. spin_lock_irq(&phba->hbalock);
  3445. phba->link_flag &= ~LS_IGNORE_ERATT;
  3446. spin_unlock_irq(&phba->hbalock);
  3447. return 1;
  3448. }
  3449. spin_lock_irq(&phba->hbalock);
  3450. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  3451. spin_unlock_irq(&phba->hbalock);
  3452. mempool_free(pmb, phba->mbox_mem_pool);
  3453. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  3454. * attention every 100ms for 3 seconds. If we don't get ERATT after
  3455. * 3 seconds we still set HBA_ERROR state because the status of the
  3456. * board is now undefined.
  3457. */
  3458. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3459. return 1;
  3460. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  3461. mdelay(100);
  3462. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  3463. return 1;
  3464. }
  3465. del_timer_sync(&psli->mbox_tmo);
  3466. if (ha_copy & HA_ERATT) {
  3467. writel(HA_ERATT, phba->HAregaddr);
  3468. phba->pport->stopped = 1;
  3469. }
  3470. spin_lock_irq(&phba->hbalock);
  3471. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3472. psli->mbox_active = NULL;
  3473. phba->link_flag &= ~LS_IGNORE_ERATT;
  3474. spin_unlock_irq(&phba->hbalock);
  3475. lpfc_hba_down_post(phba);
  3476. phba->link_state = LPFC_HBA_ERROR;
  3477. return ha_copy & HA_ERATT ? 0 : 1;
  3478. }
  3479. /**
  3480. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  3481. * @phba: Pointer to HBA context object.
  3482. *
  3483. * This function resets the HBA by writing HC_INITFF to the control
  3484. * register. After the HBA resets, this function resets all the iocb ring
  3485. * indices. This function disables PCI layer parity checking during
  3486. * the reset.
  3487. * This function returns 0 always.
  3488. * The caller is not required to hold any locks.
  3489. **/
  3490. int
  3491. lpfc_sli_brdreset(struct lpfc_hba *phba)
  3492. {
  3493. struct lpfc_sli *psli;
  3494. struct lpfc_sli_ring *pring;
  3495. uint16_t cfg_value;
  3496. int i;
  3497. psli = &phba->sli;
  3498. /* Reset HBA */
  3499. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3500. "0325 Reset HBA Data: x%x x%x\n",
  3501. phba->pport->port_state, psli->sli_flag);
  3502. /* perform board reset */
  3503. phba->fc_eventTag = 0;
  3504. phba->link_events = 0;
  3505. phba->pport->fc_myDID = 0;
  3506. phba->pport->fc_prevDID = 0;
  3507. /* Turn off parity checking and serr during the physical reset */
  3508. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3509. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  3510. (cfg_value &
  3511. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3512. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  3513. /* Now toggle INITFF bit in the Host Control Register */
  3514. writel(HC_INITFF, phba->HCregaddr);
  3515. mdelay(1);
  3516. readl(phba->HCregaddr); /* flush */
  3517. writel(0, phba->HCregaddr);
  3518. readl(phba->HCregaddr); /* flush */
  3519. /* Restore PCI cmd register */
  3520. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3521. /* Initialize relevant SLI info */
  3522. for (i = 0; i < psli->num_rings; i++) {
  3523. pring = &psli->ring[i];
  3524. pring->flag = 0;
  3525. pring->rspidx = 0;
  3526. pring->next_cmdidx = 0;
  3527. pring->local_getidx = 0;
  3528. pring->cmdidx = 0;
  3529. pring->missbufcnt = 0;
  3530. }
  3531. phba->link_state = LPFC_WARM_START;
  3532. return 0;
  3533. }
  3534. /**
  3535. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  3536. * @phba: Pointer to HBA context object.
  3537. *
  3538. * This function resets a SLI4 HBA. This function disables PCI layer parity
  3539. * checking during resets the device. The caller is not required to hold
  3540. * any locks.
  3541. *
  3542. * This function returns 0 always.
  3543. **/
  3544. int
  3545. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  3546. {
  3547. struct lpfc_sli *psli = &phba->sli;
  3548. uint16_t cfg_value;
  3549. /* Reset HBA */
  3550. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3551. "0295 Reset HBA Data: x%x x%x\n",
  3552. phba->pport->port_state, psli->sli_flag);
  3553. /* perform board reset */
  3554. phba->fc_eventTag = 0;
  3555. phba->link_events = 0;
  3556. phba->pport->fc_myDID = 0;
  3557. phba->pport->fc_prevDID = 0;
  3558. spin_lock_irq(&phba->hbalock);
  3559. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  3560. phba->fcf.fcf_flag = 0;
  3561. spin_unlock_irq(&phba->hbalock);
  3562. /* Now physically reset the device */
  3563. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3564. "0389 Performing PCI function reset!\n");
  3565. /* Turn off parity checking and serr during the physical reset */
  3566. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  3567. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  3568. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  3569. /* Perform FCoE PCI function reset */
  3570. lpfc_sli4_queue_destroy(phba);
  3571. lpfc_pci_function_reset(phba);
  3572. /* Restore PCI cmd register */
  3573. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  3574. return 0;
  3575. }
  3576. /**
  3577. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  3578. * @phba: Pointer to HBA context object.
  3579. *
  3580. * This function is called in the SLI initialization code path to
  3581. * restart the HBA. The caller is not required to hold any lock.
  3582. * This function writes MBX_RESTART mailbox command to the SLIM and
  3583. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  3584. * function to free any pending commands. The function enables
  3585. * POST only during the first initialization. The function returns zero.
  3586. * The function does not guarantee completion of MBX_RESTART mailbox
  3587. * command before the return of this function.
  3588. **/
  3589. static int
  3590. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  3591. {
  3592. MAILBOX_t *mb;
  3593. struct lpfc_sli *psli;
  3594. volatile uint32_t word0;
  3595. void __iomem *to_slim;
  3596. uint32_t hba_aer_enabled;
  3597. spin_lock_irq(&phba->hbalock);
  3598. /* Take PCIe device Advanced Error Reporting (AER) state */
  3599. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3600. psli = &phba->sli;
  3601. /* Restart HBA */
  3602. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3603. "0337 Restart HBA Data: x%x x%x\n",
  3604. phba->pport->port_state, psli->sli_flag);
  3605. word0 = 0;
  3606. mb = (MAILBOX_t *) &word0;
  3607. mb->mbxCommand = MBX_RESTART;
  3608. mb->mbxHc = 1;
  3609. lpfc_reset_barrier(phba);
  3610. to_slim = phba->MBslimaddr;
  3611. writel(*(uint32_t *) mb, to_slim);
  3612. readl(to_slim); /* flush */
  3613. /* Only skip post after fc_ffinit is completed */
  3614. if (phba->pport->port_state)
  3615. word0 = 1; /* This is really setting up word1 */
  3616. else
  3617. word0 = 0; /* This is really setting up word1 */
  3618. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  3619. writel(*(uint32_t *) mb, to_slim);
  3620. readl(to_slim); /* flush */
  3621. lpfc_sli_brdreset(phba);
  3622. phba->pport->stopped = 0;
  3623. phba->link_state = LPFC_INIT_START;
  3624. phba->hba_flag = 0;
  3625. spin_unlock_irq(&phba->hbalock);
  3626. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3627. psli->stats_start = get_seconds();
  3628. /* Give the INITFF and Post time to settle. */
  3629. mdelay(100);
  3630. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3631. if (hba_aer_enabled)
  3632. pci_disable_pcie_error_reporting(phba->pcidev);
  3633. lpfc_hba_down_post(phba);
  3634. return 0;
  3635. }
  3636. /**
  3637. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  3638. * @phba: Pointer to HBA context object.
  3639. *
  3640. * This function is called in the SLI initialization code path to restart
  3641. * a SLI4 HBA. The caller is not required to hold any lock.
  3642. * At the end of the function, it calls lpfc_hba_down_post function to
  3643. * free any pending commands.
  3644. **/
  3645. static int
  3646. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  3647. {
  3648. struct lpfc_sli *psli = &phba->sli;
  3649. uint32_t hba_aer_enabled;
  3650. /* Restart HBA */
  3651. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3652. "0296 Restart HBA Data: x%x x%x\n",
  3653. phba->pport->port_state, psli->sli_flag);
  3654. /* Take PCIe device Advanced Error Reporting (AER) state */
  3655. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  3656. lpfc_sli4_brdreset(phba);
  3657. spin_lock_irq(&phba->hbalock);
  3658. phba->pport->stopped = 0;
  3659. phba->link_state = LPFC_INIT_START;
  3660. phba->hba_flag = 0;
  3661. spin_unlock_irq(&phba->hbalock);
  3662. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  3663. psli->stats_start = get_seconds();
  3664. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  3665. if (hba_aer_enabled)
  3666. pci_disable_pcie_error_reporting(phba->pcidev);
  3667. lpfc_hba_down_post(phba);
  3668. return 0;
  3669. }
  3670. /**
  3671. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  3672. * @phba: Pointer to HBA context object.
  3673. *
  3674. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  3675. * API jump table function pointer from the lpfc_hba struct.
  3676. **/
  3677. int
  3678. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  3679. {
  3680. return phba->lpfc_sli_brdrestart(phba);
  3681. }
  3682. /**
  3683. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  3684. * @phba: Pointer to HBA context object.
  3685. *
  3686. * This function is called after a HBA restart to wait for successful
  3687. * restart of the HBA. Successful restart of the HBA is indicated by
  3688. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  3689. * iteration, the function will restart the HBA again. The function returns
  3690. * zero if HBA successfully restarted else returns negative error code.
  3691. **/
  3692. static int
  3693. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  3694. {
  3695. uint32_t status, i = 0;
  3696. /* Read the HBA Host Status Register */
  3697. if (lpfc_readl(phba->HSregaddr, &status))
  3698. return -EIO;
  3699. /* Check status register to see what current state is */
  3700. i = 0;
  3701. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  3702. /* Check every 10ms for 10 retries, then every 100ms for 90
  3703. * retries, then every 1 sec for 50 retires for a total of
  3704. * ~60 seconds before reset the board again and check every
  3705. * 1 sec for 50 retries. The up to 60 seconds before the
  3706. * board ready is required by the Falcon FIPS zeroization
  3707. * complete, and any reset the board in between shall cause
  3708. * restart of zeroization, further delay the board ready.
  3709. */
  3710. if (i++ >= 200) {
  3711. /* Adapter failed to init, timeout, status reg
  3712. <status> */
  3713. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3714. "0436 Adapter failed to init, "
  3715. "timeout, status reg x%x, "
  3716. "FW Data: A8 x%x AC x%x\n", status,
  3717. readl(phba->MBslimaddr + 0xa8),
  3718. readl(phba->MBslimaddr + 0xac));
  3719. phba->link_state = LPFC_HBA_ERROR;
  3720. return -ETIMEDOUT;
  3721. }
  3722. /* Check to see if any errors occurred during init */
  3723. if (status & HS_FFERM) {
  3724. /* ERROR: During chipset initialization */
  3725. /* Adapter failed to init, chipset, status reg
  3726. <status> */
  3727. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3728. "0437 Adapter failed to init, "
  3729. "chipset, status reg x%x, "
  3730. "FW Data: A8 x%x AC x%x\n", status,
  3731. readl(phba->MBslimaddr + 0xa8),
  3732. readl(phba->MBslimaddr + 0xac));
  3733. phba->link_state = LPFC_HBA_ERROR;
  3734. return -EIO;
  3735. }
  3736. if (i <= 10)
  3737. msleep(10);
  3738. else if (i <= 100)
  3739. msleep(100);
  3740. else
  3741. msleep(1000);
  3742. if (i == 150) {
  3743. /* Do post */
  3744. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3745. lpfc_sli_brdrestart(phba);
  3746. }
  3747. /* Read the HBA Host Status Register */
  3748. if (lpfc_readl(phba->HSregaddr, &status))
  3749. return -EIO;
  3750. }
  3751. /* Check to see if any errors occurred during init */
  3752. if (status & HS_FFERM) {
  3753. /* ERROR: During chipset initialization */
  3754. /* Adapter failed to init, chipset, status reg <status> */
  3755. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3756. "0438 Adapter failed to init, chipset, "
  3757. "status reg x%x, "
  3758. "FW Data: A8 x%x AC x%x\n", status,
  3759. readl(phba->MBslimaddr + 0xa8),
  3760. readl(phba->MBslimaddr + 0xac));
  3761. phba->link_state = LPFC_HBA_ERROR;
  3762. return -EIO;
  3763. }
  3764. /* Clear all interrupt enable conditions */
  3765. writel(0, phba->HCregaddr);
  3766. readl(phba->HCregaddr); /* flush */
  3767. /* setup host attn register */
  3768. writel(0xffffffff, phba->HAregaddr);
  3769. readl(phba->HAregaddr); /* flush */
  3770. return 0;
  3771. }
  3772. /**
  3773. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  3774. *
  3775. * This function calculates and returns the number of HBQs required to be
  3776. * configured.
  3777. **/
  3778. int
  3779. lpfc_sli_hbq_count(void)
  3780. {
  3781. return ARRAY_SIZE(lpfc_hbq_defs);
  3782. }
  3783. /**
  3784. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  3785. *
  3786. * This function adds the number of hbq entries in every HBQ to get
  3787. * the total number of hbq entries required for the HBA and returns
  3788. * the total count.
  3789. **/
  3790. static int
  3791. lpfc_sli_hbq_entry_count(void)
  3792. {
  3793. int hbq_count = lpfc_sli_hbq_count();
  3794. int count = 0;
  3795. int i;
  3796. for (i = 0; i < hbq_count; ++i)
  3797. count += lpfc_hbq_defs[i]->entry_count;
  3798. return count;
  3799. }
  3800. /**
  3801. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  3802. *
  3803. * This function calculates amount of memory required for all hbq entries
  3804. * to be configured and returns the total memory required.
  3805. **/
  3806. int
  3807. lpfc_sli_hbq_size(void)
  3808. {
  3809. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  3810. }
  3811. /**
  3812. * lpfc_sli_hbq_setup - configure and initialize HBQs
  3813. * @phba: Pointer to HBA context object.
  3814. *
  3815. * This function is called during the SLI initialization to configure
  3816. * all the HBQs and post buffers to the HBQ. The caller is not
  3817. * required to hold any locks. This function will return zero if successful
  3818. * else it will return negative error code.
  3819. **/
  3820. static int
  3821. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  3822. {
  3823. int hbq_count = lpfc_sli_hbq_count();
  3824. LPFC_MBOXQ_t *pmb;
  3825. MAILBOX_t *pmbox;
  3826. uint32_t hbqno;
  3827. uint32_t hbq_entry_index;
  3828. /* Get a Mailbox buffer to setup mailbox
  3829. * commands for HBA initialization
  3830. */
  3831. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3832. if (!pmb)
  3833. return -ENOMEM;
  3834. pmbox = &pmb->u.mb;
  3835. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  3836. phba->link_state = LPFC_INIT_MBX_CMDS;
  3837. phba->hbq_in_use = 1;
  3838. hbq_entry_index = 0;
  3839. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  3840. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  3841. phba->hbqs[hbqno].hbqPutIdx = 0;
  3842. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  3843. phba->hbqs[hbqno].entry_count =
  3844. lpfc_hbq_defs[hbqno]->entry_count;
  3845. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  3846. hbq_entry_index, pmb);
  3847. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  3848. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  3849. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  3850. mbxStatus <status>, ring <num> */
  3851. lpfc_printf_log(phba, KERN_ERR,
  3852. LOG_SLI | LOG_VPORT,
  3853. "1805 Adapter failed to init. "
  3854. "Data: x%x x%x x%x\n",
  3855. pmbox->mbxCommand,
  3856. pmbox->mbxStatus, hbqno);
  3857. phba->link_state = LPFC_HBA_ERROR;
  3858. mempool_free(pmb, phba->mbox_mem_pool);
  3859. return -ENXIO;
  3860. }
  3861. }
  3862. phba->hbq_count = hbq_count;
  3863. mempool_free(pmb, phba->mbox_mem_pool);
  3864. /* Initially populate or replenish the HBQs */
  3865. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  3866. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  3867. return 0;
  3868. }
  3869. /**
  3870. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  3871. * @phba: Pointer to HBA context object.
  3872. *
  3873. * This function is called during the SLI initialization to configure
  3874. * all the HBQs and post buffers to the HBQ. The caller is not
  3875. * required to hold any locks. This function will return zero if successful
  3876. * else it will return negative error code.
  3877. **/
  3878. static int
  3879. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  3880. {
  3881. phba->hbq_in_use = 1;
  3882. phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count;
  3883. phba->hbq_count = 1;
  3884. /* Initially populate or replenish the HBQs */
  3885. lpfc_sli_hbqbuf_init_hbqs(phba, 0);
  3886. return 0;
  3887. }
  3888. /**
  3889. * lpfc_sli_config_port - Issue config port mailbox command
  3890. * @phba: Pointer to HBA context object.
  3891. * @sli_mode: sli mode - 2/3
  3892. *
  3893. * This function is called by the sli intialization code path
  3894. * to issue config_port mailbox command. This function restarts the
  3895. * HBA firmware and issues a config_port mailbox command to configure
  3896. * the SLI interface in the sli mode specified by sli_mode
  3897. * variable. The caller is not required to hold any locks.
  3898. * The function returns 0 if successful, else returns negative error
  3899. * code.
  3900. **/
  3901. int
  3902. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  3903. {
  3904. LPFC_MBOXQ_t *pmb;
  3905. uint32_t resetcount = 0, rc = 0, done = 0;
  3906. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3907. if (!pmb) {
  3908. phba->link_state = LPFC_HBA_ERROR;
  3909. return -ENOMEM;
  3910. }
  3911. phba->sli_rev = sli_mode;
  3912. while (resetcount < 2 && !done) {
  3913. spin_lock_irq(&phba->hbalock);
  3914. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  3915. spin_unlock_irq(&phba->hbalock);
  3916. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  3917. lpfc_sli_brdrestart(phba);
  3918. rc = lpfc_sli_chipset_init(phba);
  3919. if (rc)
  3920. break;
  3921. spin_lock_irq(&phba->hbalock);
  3922. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3923. spin_unlock_irq(&phba->hbalock);
  3924. resetcount++;
  3925. /* Call pre CONFIG_PORT mailbox command initialization. A
  3926. * value of 0 means the call was successful. Any other
  3927. * nonzero value is a failure, but if ERESTART is returned,
  3928. * the driver may reset the HBA and try again.
  3929. */
  3930. rc = lpfc_config_port_prep(phba);
  3931. if (rc == -ERESTART) {
  3932. phba->link_state = LPFC_LINK_UNKNOWN;
  3933. continue;
  3934. } else if (rc)
  3935. break;
  3936. phba->link_state = LPFC_INIT_MBX_CMDS;
  3937. lpfc_config_port(phba, pmb);
  3938. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  3939. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  3940. LPFC_SLI3_HBQ_ENABLED |
  3941. LPFC_SLI3_CRP_ENABLED |
  3942. LPFC_SLI3_BG_ENABLED |
  3943. LPFC_SLI3_DSS_ENABLED);
  3944. if (rc != MBX_SUCCESS) {
  3945. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3946. "0442 Adapter failed to init, mbxCmd x%x "
  3947. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  3948. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  3949. spin_lock_irq(&phba->hbalock);
  3950. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  3951. spin_unlock_irq(&phba->hbalock);
  3952. rc = -ENXIO;
  3953. } else {
  3954. /* Allow asynchronous mailbox command to go through */
  3955. spin_lock_irq(&phba->hbalock);
  3956. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  3957. spin_unlock_irq(&phba->hbalock);
  3958. done = 1;
  3959. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  3960. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  3961. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3962. "3110 Port did not grant ASABT\n");
  3963. }
  3964. }
  3965. if (!done) {
  3966. rc = -EINVAL;
  3967. goto do_prep_failed;
  3968. }
  3969. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  3970. if (!pmb->u.mb.un.varCfgPort.cMA) {
  3971. rc = -ENXIO;
  3972. goto do_prep_failed;
  3973. }
  3974. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  3975. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  3976. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  3977. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  3978. phba->max_vpi : phba->max_vports;
  3979. } else
  3980. phba->max_vpi = 0;
  3981. phba->fips_level = 0;
  3982. phba->fips_spec_rev = 0;
  3983. if (pmb->u.mb.un.varCfgPort.gdss) {
  3984. phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
  3985. phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
  3986. phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
  3987. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3988. "2850 Security Crypto Active. FIPS x%d "
  3989. "(Spec Rev: x%d)",
  3990. phba->fips_level, phba->fips_spec_rev);
  3991. }
  3992. if (pmb->u.mb.un.varCfgPort.sec_err) {
  3993. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3994. "2856 Config Port Security Crypto "
  3995. "Error: x%x ",
  3996. pmb->u.mb.un.varCfgPort.sec_err);
  3997. }
  3998. if (pmb->u.mb.un.varCfgPort.gerbm)
  3999. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  4000. if (pmb->u.mb.un.varCfgPort.gcrp)
  4001. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  4002. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  4003. phba->port_gp = phba->mbox->us.s3_pgp.port;
  4004. if (phba->cfg_enable_bg) {
  4005. if (pmb->u.mb.un.varCfgPort.gbg)
  4006. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  4007. else
  4008. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4009. "0443 Adapter did not grant "
  4010. "BlockGuard\n");
  4011. }
  4012. } else {
  4013. phba->hbq_get = NULL;
  4014. phba->port_gp = phba->mbox->us.s2.port;
  4015. phba->max_vpi = 0;
  4016. }
  4017. do_prep_failed:
  4018. mempool_free(pmb, phba->mbox_mem_pool);
  4019. return rc;
  4020. }
  4021. /**
  4022. * lpfc_sli_hba_setup - SLI intialization function
  4023. * @phba: Pointer to HBA context object.
  4024. *
  4025. * This function is the main SLI intialization function. This function
  4026. * is called by the HBA intialization code, HBA reset code and HBA
  4027. * error attention handler code. Caller is not required to hold any
  4028. * locks. This function issues config_port mailbox command to configure
  4029. * the SLI, setup iocb rings and HBQ rings. In the end the function
  4030. * calls the config_port_post function to issue init_link mailbox
  4031. * command and to start the discovery. The function will return zero
  4032. * if successful, else it will return negative error code.
  4033. **/
  4034. int
  4035. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  4036. {
  4037. uint32_t rc;
  4038. int mode = 3, i;
  4039. int longs;
  4040. switch (lpfc_sli_mode) {
  4041. case 2:
  4042. if (phba->cfg_enable_npiv) {
  4043. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4044. "1824 NPIV enabled: Override lpfc_sli_mode "
  4045. "parameter (%d) to auto (0).\n",
  4046. lpfc_sli_mode);
  4047. break;
  4048. }
  4049. mode = 2;
  4050. break;
  4051. case 0:
  4052. case 3:
  4053. break;
  4054. default:
  4055. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4056. "1819 Unrecognized lpfc_sli_mode "
  4057. "parameter: %d.\n", lpfc_sli_mode);
  4058. break;
  4059. }
  4060. rc = lpfc_sli_config_port(phba, mode);
  4061. if (rc && lpfc_sli_mode == 3)
  4062. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  4063. "1820 Unable to select SLI-3. "
  4064. "Not supported by adapter.\n");
  4065. if (rc && mode != 2)
  4066. rc = lpfc_sli_config_port(phba, 2);
  4067. if (rc)
  4068. goto lpfc_sli_hba_setup_error;
  4069. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  4070. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  4071. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  4072. if (!rc) {
  4073. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4074. "2709 This device supports "
  4075. "Advanced Error Reporting (AER)\n");
  4076. spin_lock_irq(&phba->hbalock);
  4077. phba->hba_flag |= HBA_AER_ENABLED;
  4078. spin_unlock_irq(&phba->hbalock);
  4079. } else {
  4080. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4081. "2708 This device does not support "
  4082. "Advanced Error Reporting (AER)\n");
  4083. phba->cfg_aer_support = 0;
  4084. }
  4085. }
  4086. if (phba->sli_rev == 3) {
  4087. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  4088. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  4089. } else {
  4090. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  4091. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  4092. phba->sli3_options = 0;
  4093. }
  4094. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4095. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  4096. phba->sli_rev, phba->max_vpi);
  4097. rc = lpfc_sli_ring_map(phba);
  4098. if (rc)
  4099. goto lpfc_sli_hba_setup_error;
  4100. /* Initialize VPIs. */
  4101. if (phba->sli_rev == LPFC_SLI_REV3) {
  4102. /*
  4103. * The VPI bitmask and physical ID array are allocated
  4104. * and initialized once only - at driver load. A port
  4105. * reset doesn't need to reinitialize this memory.
  4106. */
  4107. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  4108. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  4109. phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4110. GFP_KERNEL);
  4111. if (!phba->vpi_bmask) {
  4112. rc = -ENOMEM;
  4113. goto lpfc_sli_hba_setup_error;
  4114. }
  4115. phba->vpi_ids = kzalloc(
  4116. (phba->max_vpi+1) * sizeof(uint16_t),
  4117. GFP_KERNEL);
  4118. if (!phba->vpi_ids) {
  4119. kfree(phba->vpi_bmask);
  4120. rc = -ENOMEM;
  4121. goto lpfc_sli_hba_setup_error;
  4122. }
  4123. for (i = 0; i < phba->max_vpi; i++)
  4124. phba->vpi_ids[i] = i;
  4125. }
  4126. }
  4127. /* Init HBQs */
  4128. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  4129. rc = lpfc_sli_hbq_setup(phba);
  4130. if (rc)
  4131. goto lpfc_sli_hba_setup_error;
  4132. }
  4133. spin_lock_irq(&phba->hbalock);
  4134. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4135. spin_unlock_irq(&phba->hbalock);
  4136. rc = lpfc_config_port_post(phba);
  4137. if (rc)
  4138. goto lpfc_sli_hba_setup_error;
  4139. return rc;
  4140. lpfc_sli_hba_setup_error:
  4141. phba->link_state = LPFC_HBA_ERROR;
  4142. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4143. "0445 Firmware initialization failed\n");
  4144. return rc;
  4145. }
  4146. /**
  4147. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  4148. * @phba: Pointer to HBA context object.
  4149. * @mboxq: mailbox pointer.
  4150. * This function issue a dump mailbox command to read config region
  4151. * 23 and parse the records in the region and populate driver
  4152. * data structure.
  4153. **/
  4154. static int
  4155. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  4156. {
  4157. LPFC_MBOXQ_t *mboxq;
  4158. struct lpfc_dmabuf *mp;
  4159. struct lpfc_mqe *mqe;
  4160. uint32_t data_length;
  4161. int rc;
  4162. /* Program the default value of vlan_id and fc_map */
  4163. phba->valid_vlan = 0;
  4164. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  4165. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  4166. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  4167. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4168. if (!mboxq)
  4169. return -ENOMEM;
  4170. mqe = &mboxq->u.mqe;
  4171. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  4172. rc = -ENOMEM;
  4173. goto out_free_mboxq;
  4174. }
  4175. mp = (struct lpfc_dmabuf *) mboxq->context1;
  4176. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4177. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  4178. "(%d):2571 Mailbox cmd x%x Status x%x "
  4179. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4180. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  4181. "CQ: x%x x%x x%x x%x\n",
  4182. mboxq->vport ? mboxq->vport->vpi : 0,
  4183. bf_get(lpfc_mqe_command, mqe),
  4184. bf_get(lpfc_mqe_status, mqe),
  4185. mqe->un.mb_words[0], mqe->un.mb_words[1],
  4186. mqe->un.mb_words[2], mqe->un.mb_words[3],
  4187. mqe->un.mb_words[4], mqe->un.mb_words[5],
  4188. mqe->un.mb_words[6], mqe->un.mb_words[7],
  4189. mqe->un.mb_words[8], mqe->un.mb_words[9],
  4190. mqe->un.mb_words[10], mqe->un.mb_words[11],
  4191. mqe->un.mb_words[12], mqe->un.mb_words[13],
  4192. mqe->un.mb_words[14], mqe->un.mb_words[15],
  4193. mqe->un.mb_words[16], mqe->un.mb_words[50],
  4194. mboxq->mcqe.word0,
  4195. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  4196. mboxq->mcqe.trailer);
  4197. if (rc) {
  4198. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4199. kfree(mp);
  4200. rc = -EIO;
  4201. goto out_free_mboxq;
  4202. }
  4203. data_length = mqe->un.mb_words[5];
  4204. if (data_length > DMP_RGN23_SIZE) {
  4205. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4206. kfree(mp);
  4207. rc = -EIO;
  4208. goto out_free_mboxq;
  4209. }
  4210. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  4211. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4212. kfree(mp);
  4213. rc = 0;
  4214. out_free_mboxq:
  4215. mempool_free(mboxq, phba->mbox_mem_pool);
  4216. return rc;
  4217. }
  4218. /**
  4219. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  4220. * @phba: pointer to lpfc hba data structure.
  4221. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  4222. * @vpd: pointer to the memory to hold resulting port vpd data.
  4223. * @vpd_size: On input, the number of bytes allocated to @vpd.
  4224. * On output, the number of data bytes in @vpd.
  4225. *
  4226. * This routine executes a READ_REV SLI4 mailbox command. In
  4227. * addition, this routine gets the port vpd data.
  4228. *
  4229. * Return codes
  4230. * 0 - successful
  4231. * -ENOMEM - could not allocated memory.
  4232. **/
  4233. static int
  4234. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  4235. uint8_t *vpd, uint32_t *vpd_size)
  4236. {
  4237. int rc = 0;
  4238. uint32_t dma_size;
  4239. struct lpfc_dmabuf *dmabuf;
  4240. struct lpfc_mqe *mqe;
  4241. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4242. if (!dmabuf)
  4243. return -ENOMEM;
  4244. /*
  4245. * Get a DMA buffer for the vpd data resulting from the READ_REV
  4246. * mailbox command.
  4247. */
  4248. dma_size = *vpd_size;
  4249. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4250. dma_size,
  4251. &dmabuf->phys,
  4252. GFP_KERNEL);
  4253. if (!dmabuf->virt) {
  4254. kfree(dmabuf);
  4255. return -ENOMEM;
  4256. }
  4257. memset(dmabuf->virt, 0, dma_size);
  4258. /*
  4259. * The SLI4 implementation of READ_REV conflicts at word1,
  4260. * bits 31:16 and SLI4 adds vpd functionality not present
  4261. * in SLI3. This code corrects the conflicts.
  4262. */
  4263. lpfc_read_rev(phba, mboxq);
  4264. mqe = &mboxq->u.mqe;
  4265. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  4266. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  4267. mqe->un.read_rev.word1 &= 0x0000FFFF;
  4268. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  4269. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  4270. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4271. if (rc) {
  4272. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4273. dmabuf->virt, dmabuf->phys);
  4274. kfree(dmabuf);
  4275. return -EIO;
  4276. }
  4277. /*
  4278. * The available vpd length cannot be bigger than the
  4279. * DMA buffer passed to the port. Catch the less than
  4280. * case and update the caller's size.
  4281. */
  4282. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  4283. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  4284. memcpy(vpd, dmabuf->virt, *vpd_size);
  4285. dma_free_coherent(&phba->pcidev->dev, dma_size,
  4286. dmabuf->virt, dmabuf->phys);
  4287. kfree(dmabuf);
  4288. return 0;
  4289. }
  4290. /**
  4291. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  4292. * @phba: pointer to lpfc hba data structure.
  4293. *
  4294. * This routine retrieves SLI4 device physical port name this PCI function
  4295. * is attached to.
  4296. *
  4297. * Return codes
  4298. * 0 - sucessful
  4299. * otherwise - failed to retrieve physical port name
  4300. **/
  4301. static int
  4302. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  4303. {
  4304. LPFC_MBOXQ_t *mboxq;
  4305. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  4306. struct lpfc_controller_attribute *cntl_attr;
  4307. struct lpfc_mbx_get_port_name *get_port_name;
  4308. void *virtaddr = NULL;
  4309. uint32_t alloclen, reqlen;
  4310. uint32_t shdr_status, shdr_add_status;
  4311. union lpfc_sli4_cfg_shdr *shdr;
  4312. char cport_name = 0;
  4313. int rc;
  4314. /* We assume nothing at this point */
  4315. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4316. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  4317. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4318. if (!mboxq)
  4319. return -ENOMEM;
  4320. /* obtain link type and link number via READ_CONFIG */
  4321. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  4322. lpfc_sli4_read_config(phba);
  4323. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  4324. goto retrieve_ppname;
  4325. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  4326. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  4327. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4328. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  4329. LPFC_SLI4_MBX_NEMBED);
  4330. if (alloclen < reqlen) {
  4331. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4332. "3084 Allocated DMA memory size (%d) is "
  4333. "less than the requested DMA memory size "
  4334. "(%d)\n", alloclen, reqlen);
  4335. rc = -ENOMEM;
  4336. goto out_free_mboxq;
  4337. }
  4338. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4339. virtaddr = mboxq->sge_array->addr[0];
  4340. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  4341. shdr = &mbx_cntl_attr->cfg_shdr;
  4342. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4343. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4344. if (shdr_status || shdr_add_status || rc) {
  4345. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4346. "3085 Mailbox x%x (x%x/x%x) failed, "
  4347. "rc:x%x, status:x%x, add_status:x%x\n",
  4348. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4349. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4350. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4351. rc, shdr_status, shdr_add_status);
  4352. rc = -ENXIO;
  4353. goto out_free_mboxq;
  4354. }
  4355. cntl_attr = &mbx_cntl_attr->cntl_attr;
  4356. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  4357. phba->sli4_hba.lnk_info.lnk_tp =
  4358. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  4359. phba->sli4_hba.lnk_info.lnk_no =
  4360. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  4361. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4362. "3086 lnk_type:%d, lnk_numb:%d\n",
  4363. phba->sli4_hba.lnk_info.lnk_tp,
  4364. phba->sli4_hba.lnk_info.lnk_no);
  4365. retrieve_ppname:
  4366. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  4367. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  4368. sizeof(struct lpfc_mbx_get_port_name) -
  4369. sizeof(struct lpfc_sli4_cfg_mhdr),
  4370. LPFC_SLI4_MBX_EMBED);
  4371. get_port_name = &mboxq->u.mqe.un.get_port_name;
  4372. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  4373. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  4374. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  4375. phba->sli4_hba.lnk_info.lnk_tp);
  4376. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4377. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  4378. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  4379. if (shdr_status || shdr_add_status || rc) {
  4380. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  4381. "3087 Mailbox x%x (x%x/x%x) failed: "
  4382. "rc:x%x, status:x%x, add_status:x%x\n",
  4383. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  4384. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  4385. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  4386. rc, shdr_status, shdr_add_status);
  4387. rc = -ENXIO;
  4388. goto out_free_mboxq;
  4389. }
  4390. switch (phba->sli4_hba.lnk_info.lnk_no) {
  4391. case LPFC_LINK_NUMBER_0:
  4392. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  4393. &get_port_name->u.response);
  4394. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4395. break;
  4396. case LPFC_LINK_NUMBER_1:
  4397. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  4398. &get_port_name->u.response);
  4399. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4400. break;
  4401. case LPFC_LINK_NUMBER_2:
  4402. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  4403. &get_port_name->u.response);
  4404. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4405. break;
  4406. case LPFC_LINK_NUMBER_3:
  4407. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  4408. &get_port_name->u.response);
  4409. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  4410. break;
  4411. default:
  4412. break;
  4413. }
  4414. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  4415. phba->Port[0] = cport_name;
  4416. phba->Port[1] = '\0';
  4417. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4418. "3091 SLI get port name: %s\n", phba->Port);
  4419. }
  4420. out_free_mboxq:
  4421. if (rc != MBX_TIMEOUT) {
  4422. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  4423. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  4424. else
  4425. mempool_free(mboxq, phba->mbox_mem_pool);
  4426. }
  4427. return rc;
  4428. }
  4429. /**
  4430. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  4431. * @phba: pointer to lpfc hba data structure.
  4432. *
  4433. * This routine is called to explicitly arm the SLI4 device's completion and
  4434. * event queues
  4435. **/
  4436. static void
  4437. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  4438. {
  4439. uint8_t fcp_eqidx;
  4440. lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
  4441. lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
  4442. fcp_eqidx = 0;
  4443. if (phba->sli4_hba.fcp_cq) {
  4444. do
  4445. lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx],
  4446. LPFC_QUEUE_REARM);
  4447. while (++fcp_eqidx < phba->cfg_fcp_eq_count);
  4448. }
  4449. lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM);
  4450. if (phba->sli4_hba.fp_eq) {
  4451. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count;
  4452. fcp_eqidx++)
  4453. lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx],
  4454. LPFC_QUEUE_REARM);
  4455. }
  4456. }
  4457. /**
  4458. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  4459. * @phba: Pointer to HBA context object.
  4460. * @type: The resource extent type.
  4461. * @extnt_count: buffer to hold port available extent count.
  4462. * @extnt_size: buffer to hold element count per extent.
  4463. *
  4464. * This function calls the port and retrievs the number of available
  4465. * extents and their size for a particular extent type.
  4466. *
  4467. * Returns: 0 if successful. Nonzero otherwise.
  4468. **/
  4469. int
  4470. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  4471. uint16_t *extnt_count, uint16_t *extnt_size)
  4472. {
  4473. int rc = 0;
  4474. uint32_t length;
  4475. uint32_t mbox_tmo;
  4476. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  4477. LPFC_MBOXQ_t *mbox;
  4478. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4479. if (!mbox)
  4480. return -ENOMEM;
  4481. /* Find out how many extents are available for this resource type */
  4482. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  4483. sizeof(struct lpfc_sli4_cfg_mhdr));
  4484. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4485. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  4486. length, LPFC_SLI4_MBX_EMBED);
  4487. /* Send an extents count of 0 - the GET doesn't use it. */
  4488. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4489. LPFC_SLI4_MBX_EMBED);
  4490. if (unlikely(rc)) {
  4491. rc = -EIO;
  4492. goto err_exit;
  4493. }
  4494. if (!phba->sli4_hba.intr_enable)
  4495. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4496. else {
  4497. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4498. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4499. }
  4500. if (unlikely(rc)) {
  4501. rc = -EIO;
  4502. goto err_exit;
  4503. }
  4504. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  4505. if (bf_get(lpfc_mbox_hdr_status,
  4506. &rsrc_info->header.cfg_shdr.response)) {
  4507. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4508. "2930 Failed to get resource extents "
  4509. "Status 0x%x Add'l Status 0x%x\n",
  4510. bf_get(lpfc_mbox_hdr_status,
  4511. &rsrc_info->header.cfg_shdr.response),
  4512. bf_get(lpfc_mbox_hdr_add_status,
  4513. &rsrc_info->header.cfg_shdr.response));
  4514. rc = -EIO;
  4515. goto err_exit;
  4516. }
  4517. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  4518. &rsrc_info->u.rsp);
  4519. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  4520. &rsrc_info->u.rsp);
  4521. err_exit:
  4522. mempool_free(mbox, phba->mbox_mem_pool);
  4523. return rc;
  4524. }
  4525. /**
  4526. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  4527. * @phba: Pointer to HBA context object.
  4528. * @type: The extent type to check.
  4529. *
  4530. * This function reads the current available extents from the port and checks
  4531. * if the extent count or extent size has changed since the last access.
  4532. * Callers use this routine post port reset to understand if there is a
  4533. * extent reprovisioning requirement.
  4534. *
  4535. * Returns:
  4536. * -Error: error indicates problem.
  4537. * 1: Extent count or size has changed.
  4538. * 0: No changes.
  4539. **/
  4540. static int
  4541. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  4542. {
  4543. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  4544. uint16_t size_diff, rsrc_ext_size;
  4545. int rc = 0;
  4546. struct lpfc_rsrc_blks *rsrc_entry;
  4547. struct list_head *rsrc_blk_list = NULL;
  4548. size_diff = 0;
  4549. curr_ext_cnt = 0;
  4550. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4551. &rsrc_ext_cnt,
  4552. &rsrc_ext_size);
  4553. if (unlikely(rc))
  4554. return -EIO;
  4555. switch (type) {
  4556. case LPFC_RSC_TYPE_FCOE_RPI:
  4557. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4558. break;
  4559. case LPFC_RSC_TYPE_FCOE_VPI:
  4560. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  4561. break;
  4562. case LPFC_RSC_TYPE_FCOE_XRI:
  4563. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4564. break;
  4565. case LPFC_RSC_TYPE_FCOE_VFI:
  4566. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4567. break;
  4568. default:
  4569. break;
  4570. }
  4571. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  4572. curr_ext_cnt++;
  4573. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  4574. size_diff++;
  4575. }
  4576. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  4577. rc = 1;
  4578. return rc;
  4579. }
  4580. /**
  4581. * lpfc_sli4_cfg_post_extnts -
  4582. * @phba: Pointer to HBA context object.
  4583. * @extnt_cnt - number of available extents.
  4584. * @type - the extent type (rpi, xri, vfi, vpi).
  4585. * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  4586. * @mbox - pointer to the caller's allocated mailbox structure.
  4587. *
  4588. * This function executes the extents allocation request. It also
  4589. * takes care of the amount of memory needed to allocate or get the
  4590. * allocated extents. It is the caller's responsibility to evaluate
  4591. * the response.
  4592. *
  4593. * Returns:
  4594. * -Error: Error value describes the condition found.
  4595. * 0: if successful
  4596. **/
  4597. static int
  4598. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t *extnt_cnt,
  4599. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  4600. {
  4601. int rc = 0;
  4602. uint32_t req_len;
  4603. uint32_t emb_len;
  4604. uint32_t alloc_len, mbox_tmo;
  4605. /* Calculate the total requested length of the dma memory */
  4606. req_len = *extnt_cnt * sizeof(uint16_t);
  4607. /*
  4608. * Calculate the size of an embedded mailbox. The uint32_t
  4609. * accounts for extents-specific word.
  4610. */
  4611. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  4612. sizeof(uint32_t);
  4613. /*
  4614. * Presume the allocation and response will fit into an embedded
  4615. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  4616. */
  4617. *emb = LPFC_SLI4_MBX_EMBED;
  4618. if (req_len > emb_len) {
  4619. req_len = *extnt_cnt * sizeof(uint16_t) +
  4620. sizeof(union lpfc_sli4_cfg_shdr) +
  4621. sizeof(uint32_t);
  4622. *emb = LPFC_SLI4_MBX_NEMBED;
  4623. }
  4624. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4625. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  4626. req_len, *emb);
  4627. if (alloc_len < req_len) {
  4628. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4629. "2982 Allocated DMA memory size (x%x) is "
  4630. "less than the requested DMA memory "
  4631. "size (x%x)\n", alloc_len, req_len);
  4632. return -ENOMEM;
  4633. }
  4634. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, *extnt_cnt, type, *emb);
  4635. if (unlikely(rc))
  4636. return -EIO;
  4637. if (!phba->sli4_hba.intr_enable)
  4638. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4639. else {
  4640. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4641. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4642. }
  4643. if (unlikely(rc))
  4644. rc = -EIO;
  4645. return rc;
  4646. }
  4647. /**
  4648. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  4649. * @phba: Pointer to HBA context object.
  4650. * @type: The resource extent type to allocate.
  4651. *
  4652. * This function allocates the number of elements for the specified
  4653. * resource type.
  4654. **/
  4655. static int
  4656. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  4657. {
  4658. bool emb = false;
  4659. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  4660. uint16_t rsrc_id, rsrc_start, j, k;
  4661. uint16_t *ids;
  4662. int i, rc;
  4663. unsigned long longs;
  4664. unsigned long *bmask;
  4665. struct lpfc_rsrc_blks *rsrc_blks;
  4666. LPFC_MBOXQ_t *mbox;
  4667. uint32_t length;
  4668. struct lpfc_id_range *id_array = NULL;
  4669. void *virtaddr = NULL;
  4670. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  4671. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  4672. struct list_head *ext_blk_list;
  4673. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  4674. &rsrc_cnt,
  4675. &rsrc_size);
  4676. if (unlikely(rc))
  4677. return -EIO;
  4678. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  4679. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4680. "3009 No available Resource Extents "
  4681. "for resource type 0x%x: Count: 0x%x, "
  4682. "Size 0x%x\n", type, rsrc_cnt,
  4683. rsrc_size);
  4684. return -ENOMEM;
  4685. }
  4686. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT,
  4687. "2903 Available Resource Extents "
  4688. "for resource type 0x%x: Count: 0x%x, "
  4689. "Size 0x%x\n", type, rsrc_cnt,
  4690. rsrc_size);
  4691. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4692. if (!mbox)
  4693. return -ENOMEM;
  4694. rc = lpfc_sli4_cfg_post_extnts(phba, &rsrc_cnt, type, &emb, mbox);
  4695. if (unlikely(rc)) {
  4696. rc = -EIO;
  4697. goto err_exit;
  4698. }
  4699. /*
  4700. * Figure out where the response is located. Then get local pointers
  4701. * to the response data. The port does not guarantee to respond to
  4702. * all extents counts request so update the local variable with the
  4703. * allocated count from the port.
  4704. */
  4705. if (emb == LPFC_SLI4_MBX_EMBED) {
  4706. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  4707. id_array = &rsrc_ext->u.rsp.id[0];
  4708. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  4709. } else {
  4710. virtaddr = mbox->sge_array->addr[0];
  4711. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  4712. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  4713. id_array = &n_rsrc->id;
  4714. }
  4715. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4716. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  4717. /*
  4718. * Based on the resource size and count, correct the base and max
  4719. * resource values.
  4720. */
  4721. length = sizeof(struct lpfc_rsrc_blks);
  4722. switch (type) {
  4723. case LPFC_RSC_TYPE_FCOE_RPI:
  4724. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  4725. sizeof(unsigned long),
  4726. GFP_KERNEL);
  4727. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  4728. rc = -ENOMEM;
  4729. goto err_exit;
  4730. }
  4731. phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
  4732. sizeof(uint16_t),
  4733. GFP_KERNEL);
  4734. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  4735. kfree(phba->sli4_hba.rpi_bmask);
  4736. rc = -ENOMEM;
  4737. goto err_exit;
  4738. }
  4739. /*
  4740. * The next_rpi was initialized with the maximum available
  4741. * count but the port may allocate a smaller number. Catch
  4742. * that case and update the next_rpi.
  4743. */
  4744. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  4745. /* Initialize local ptrs for common extent processing later. */
  4746. bmask = phba->sli4_hba.rpi_bmask;
  4747. ids = phba->sli4_hba.rpi_ids;
  4748. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  4749. break;
  4750. case LPFC_RSC_TYPE_FCOE_VPI:
  4751. phba->vpi_bmask = kzalloc(longs *
  4752. sizeof(unsigned long),
  4753. GFP_KERNEL);
  4754. if (unlikely(!phba->vpi_bmask)) {
  4755. rc = -ENOMEM;
  4756. goto err_exit;
  4757. }
  4758. phba->vpi_ids = kzalloc(rsrc_id_cnt *
  4759. sizeof(uint16_t),
  4760. GFP_KERNEL);
  4761. if (unlikely(!phba->vpi_ids)) {
  4762. kfree(phba->vpi_bmask);
  4763. rc = -ENOMEM;
  4764. goto err_exit;
  4765. }
  4766. /* Initialize local ptrs for common extent processing later. */
  4767. bmask = phba->vpi_bmask;
  4768. ids = phba->vpi_ids;
  4769. ext_blk_list = &phba->lpfc_vpi_blk_list;
  4770. break;
  4771. case LPFC_RSC_TYPE_FCOE_XRI:
  4772. phba->sli4_hba.xri_bmask = kzalloc(longs *
  4773. sizeof(unsigned long),
  4774. GFP_KERNEL);
  4775. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  4776. rc = -ENOMEM;
  4777. goto err_exit;
  4778. }
  4779. phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
  4780. sizeof(uint16_t),
  4781. GFP_KERNEL);
  4782. if (unlikely(!phba->sli4_hba.xri_ids)) {
  4783. kfree(phba->sli4_hba.xri_bmask);
  4784. rc = -ENOMEM;
  4785. goto err_exit;
  4786. }
  4787. /* Initialize local ptrs for common extent processing later. */
  4788. bmask = phba->sli4_hba.xri_bmask;
  4789. ids = phba->sli4_hba.xri_ids;
  4790. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  4791. break;
  4792. case LPFC_RSC_TYPE_FCOE_VFI:
  4793. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  4794. sizeof(unsigned long),
  4795. GFP_KERNEL);
  4796. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  4797. rc = -ENOMEM;
  4798. goto err_exit;
  4799. }
  4800. phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
  4801. sizeof(uint16_t),
  4802. GFP_KERNEL);
  4803. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  4804. kfree(phba->sli4_hba.vfi_bmask);
  4805. rc = -ENOMEM;
  4806. goto err_exit;
  4807. }
  4808. /* Initialize local ptrs for common extent processing later. */
  4809. bmask = phba->sli4_hba.vfi_bmask;
  4810. ids = phba->sli4_hba.vfi_ids;
  4811. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  4812. break;
  4813. default:
  4814. /* Unsupported Opcode. Fail call. */
  4815. id_array = NULL;
  4816. bmask = NULL;
  4817. ids = NULL;
  4818. ext_blk_list = NULL;
  4819. goto err_exit;
  4820. }
  4821. /*
  4822. * Complete initializing the extent configuration with the
  4823. * allocated ids assigned to this function. The bitmask serves
  4824. * as an index into the array and manages the available ids. The
  4825. * array just stores the ids communicated to the port via the wqes.
  4826. */
  4827. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  4828. if ((i % 2) == 0)
  4829. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  4830. &id_array[k]);
  4831. else
  4832. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  4833. &id_array[k]);
  4834. rsrc_blks = kzalloc(length, GFP_KERNEL);
  4835. if (unlikely(!rsrc_blks)) {
  4836. rc = -ENOMEM;
  4837. kfree(bmask);
  4838. kfree(ids);
  4839. goto err_exit;
  4840. }
  4841. rsrc_blks->rsrc_start = rsrc_id;
  4842. rsrc_blks->rsrc_size = rsrc_size;
  4843. list_add_tail(&rsrc_blks->list, ext_blk_list);
  4844. rsrc_start = rsrc_id;
  4845. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0))
  4846. phba->sli4_hba.scsi_xri_start = rsrc_start +
  4847. lpfc_sli4_get_els_iocb_cnt(phba);
  4848. while (rsrc_id < (rsrc_start + rsrc_size)) {
  4849. ids[j] = rsrc_id;
  4850. rsrc_id++;
  4851. j++;
  4852. }
  4853. /* Entire word processed. Get next word.*/
  4854. if ((i % 2) == 1)
  4855. k++;
  4856. }
  4857. err_exit:
  4858. lpfc_sli4_mbox_cmd_free(phba, mbox);
  4859. return rc;
  4860. }
  4861. /**
  4862. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  4863. * @phba: Pointer to HBA context object.
  4864. * @type: the extent's type.
  4865. *
  4866. * This function deallocates all extents of a particular resource type.
  4867. * SLI4 does not allow for deallocating a particular extent range. It
  4868. * is the caller's responsibility to release all kernel memory resources.
  4869. **/
  4870. static int
  4871. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  4872. {
  4873. int rc;
  4874. uint32_t length, mbox_tmo = 0;
  4875. LPFC_MBOXQ_t *mbox;
  4876. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  4877. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  4878. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4879. if (!mbox)
  4880. return -ENOMEM;
  4881. /*
  4882. * This function sends an embedded mailbox because it only sends the
  4883. * the resource type. All extents of this type are released by the
  4884. * port.
  4885. */
  4886. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  4887. sizeof(struct lpfc_sli4_cfg_mhdr));
  4888. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  4889. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  4890. length, LPFC_SLI4_MBX_EMBED);
  4891. /* Send an extents count of 0 - the dealloc doesn't use it. */
  4892. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  4893. LPFC_SLI4_MBX_EMBED);
  4894. if (unlikely(rc)) {
  4895. rc = -EIO;
  4896. goto out_free_mbox;
  4897. }
  4898. if (!phba->sli4_hba.intr_enable)
  4899. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  4900. else {
  4901. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  4902. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  4903. }
  4904. if (unlikely(rc)) {
  4905. rc = -EIO;
  4906. goto out_free_mbox;
  4907. }
  4908. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  4909. if (bf_get(lpfc_mbox_hdr_status,
  4910. &dealloc_rsrc->header.cfg_shdr.response)) {
  4911. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  4912. "2919 Failed to release resource extents "
  4913. "for type %d - Status 0x%x Add'l Status 0x%x. "
  4914. "Resource memory not released.\n",
  4915. type,
  4916. bf_get(lpfc_mbox_hdr_status,
  4917. &dealloc_rsrc->header.cfg_shdr.response),
  4918. bf_get(lpfc_mbox_hdr_add_status,
  4919. &dealloc_rsrc->header.cfg_shdr.response));
  4920. rc = -EIO;
  4921. goto out_free_mbox;
  4922. }
  4923. /* Release kernel memory resources for the specific type. */
  4924. switch (type) {
  4925. case LPFC_RSC_TYPE_FCOE_VPI:
  4926. kfree(phba->vpi_bmask);
  4927. kfree(phba->vpi_ids);
  4928. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4929. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4930. &phba->lpfc_vpi_blk_list, list) {
  4931. list_del_init(&rsrc_blk->list);
  4932. kfree(rsrc_blk);
  4933. }
  4934. break;
  4935. case LPFC_RSC_TYPE_FCOE_XRI:
  4936. kfree(phba->sli4_hba.xri_bmask);
  4937. kfree(phba->sli4_hba.xri_ids);
  4938. bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4939. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4940. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  4941. list_del_init(&rsrc_blk->list);
  4942. kfree(rsrc_blk);
  4943. }
  4944. break;
  4945. case LPFC_RSC_TYPE_FCOE_VFI:
  4946. kfree(phba->sli4_hba.vfi_bmask);
  4947. kfree(phba->sli4_hba.vfi_ids);
  4948. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4949. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4950. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  4951. list_del_init(&rsrc_blk->list);
  4952. kfree(rsrc_blk);
  4953. }
  4954. break;
  4955. case LPFC_RSC_TYPE_FCOE_RPI:
  4956. /* RPI bitmask and physical id array are cleaned up earlier. */
  4957. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  4958. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  4959. list_del_init(&rsrc_blk->list);
  4960. kfree(rsrc_blk);
  4961. }
  4962. break;
  4963. default:
  4964. break;
  4965. }
  4966. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  4967. out_free_mbox:
  4968. mempool_free(mbox, phba->mbox_mem_pool);
  4969. return rc;
  4970. }
  4971. /**
  4972. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  4973. * @phba: Pointer to HBA context object.
  4974. *
  4975. * This function allocates all SLI4 resource identifiers.
  4976. **/
  4977. int
  4978. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  4979. {
  4980. int i, rc, error = 0;
  4981. uint16_t count, base;
  4982. unsigned long longs;
  4983. if (!phba->sli4_hba.rpi_hdrs_in_use)
  4984. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  4985. if (phba->sli4_hba.extents_in_use) {
  4986. /*
  4987. * The port supports resource extents. The XRI, VPI, VFI, RPI
  4988. * resource extent count must be read and allocated before
  4989. * provisioning the resource id arrays.
  4990. */
  4991. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  4992. LPFC_IDX_RSRC_RDY) {
  4993. /*
  4994. * Extent-based resources are set - the driver could
  4995. * be in a port reset. Figure out if any corrective
  4996. * actions need to be taken.
  4997. */
  4998. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  4999. LPFC_RSC_TYPE_FCOE_VFI);
  5000. if (rc != 0)
  5001. error++;
  5002. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5003. LPFC_RSC_TYPE_FCOE_VPI);
  5004. if (rc != 0)
  5005. error++;
  5006. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5007. LPFC_RSC_TYPE_FCOE_XRI);
  5008. if (rc != 0)
  5009. error++;
  5010. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  5011. LPFC_RSC_TYPE_FCOE_RPI);
  5012. if (rc != 0)
  5013. error++;
  5014. /*
  5015. * It's possible that the number of resources
  5016. * provided to this port instance changed between
  5017. * resets. Detect this condition and reallocate
  5018. * resources. Otherwise, there is no action.
  5019. */
  5020. if (error) {
  5021. lpfc_printf_log(phba, KERN_INFO,
  5022. LOG_MBOX | LOG_INIT,
  5023. "2931 Detected extent resource "
  5024. "change. Reallocating all "
  5025. "extents.\n");
  5026. rc = lpfc_sli4_dealloc_extent(phba,
  5027. LPFC_RSC_TYPE_FCOE_VFI);
  5028. rc = lpfc_sli4_dealloc_extent(phba,
  5029. LPFC_RSC_TYPE_FCOE_VPI);
  5030. rc = lpfc_sli4_dealloc_extent(phba,
  5031. LPFC_RSC_TYPE_FCOE_XRI);
  5032. rc = lpfc_sli4_dealloc_extent(phba,
  5033. LPFC_RSC_TYPE_FCOE_RPI);
  5034. } else
  5035. return 0;
  5036. }
  5037. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5038. if (unlikely(rc))
  5039. goto err_exit;
  5040. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5041. if (unlikely(rc))
  5042. goto err_exit;
  5043. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5044. if (unlikely(rc))
  5045. goto err_exit;
  5046. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5047. if (unlikely(rc))
  5048. goto err_exit;
  5049. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5050. LPFC_IDX_RSRC_RDY);
  5051. return rc;
  5052. } else {
  5053. /*
  5054. * The port does not support resource extents. The XRI, VPI,
  5055. * VFI, RPI resource ids were determined from READ_CONFIG.
  5056. * Just allocate the bitmasks and provision the resource id
  5057. * arrays. If a port reset is active, the resources don't
  5058. * need any action - just exit.
  5059. */
  5060. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  5061. LPFC_IDX_RSRC_RDY) {
  5062. lpfc_sli4_dealloc_resource_identifiers(phba);
  5063. lpfc_sli4_remove_rpis(phba);
  5064. }
  5065. /* RPIs. */
  5066. count = phba->sli4_hba.max_cfg_param.max_rpi;
  5067. base = phba->sli4_hba.max_cfg_param.rpi_base;
  5068. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5069. phba->sli4_hba.rpi_bmask = kzalloc(longs *
  5070. sizeof(unsigned long),
  5071. GFP_KERNEL);
  5072. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5073. rc = -ENOMEM;
  5074. goto err_exit;
  5075. }
  5076. phba->sli4_hba.rpi_ids = kzalloc(count *
  5077. sizeof(uint16_t),
  5078. GFP_KERNEL);
  5079. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5080. rc = -ENOMEM;
  5081. goto free_rpi_bmask;
  5082. }
  5083. for (i = 0; i < count; i++)
  5084. phba->sli4_hba.rpi_ids[i] = base + i;
  5085. lpfc_sli4_node_prep(phba);
  5086. /* VPIs. */
  5087. count = phba->sli4_hba.max_cfg_param.max_vpi;
  5088. base = phba->sli4_hba.max_cfg_param.vpi_base;
  5089. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5090. phba->vpi_bmask = kzalloc(longs *
  5091. sizeof(unsigned long),
  5092. GFP_KERNEL);
  5093. if (unlikely(!phba->vpi_bmask)) {
  5094. rc = -ENOMEM;
  5095. goto free_rpi_ids;
  5096. }
  5097. phba->vpi_ids = kzalloc(count *
  5098. sizeof(uint16_t),
  5099. GFP_KERNEL);
  5100. if (unlikely(!phba->vpi_ids)) {
  5101. rc = -ENOMEM;
  5102. goto free_vpi_bmask;
  5103. }
  5104. for (i = 0; i < count; i++)
  5105. phba->vpi_ids[i] = base + i;
  5106. /* XRIs. */
  5107. count = phba->sli4_hba.max_cfg_param.max_xri;
  5108. base = phba->sli4_hba.max_cfg_param.xri_base;
  5109. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5110. phba->sli4_hba.xri_bmask = kzalloc(longs *
  5111. sizeof(unsigned long),
  5112. GFP_KERNEL);
  5113. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5114. rc = -ENOMEM;
  5115. goto free_vpi_ids;
  5116. }
  5117. phba->sli4_hba.xri_ids = kzalloc(count *
  5118. sizeof(uint16_t),
  5119. GFP_KERNEL);
  5120. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5121. rc = -ENOMEM;
  5122. goto free_xri_bmask;
  5123. }
  5124. for (i = 0; i < count; i++)
  5125. phba->sli4_hba.xri_ids[i] = base + i;
  5126. /* VFIs. */
  5127. count = phba->sli4_hba.max_cfg_param.max_vfi;
  5128. base = phba->sli4_hba.max_cfg_param.vfi_base;
  5129. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5130. phba->sli4_hba.vfi_bmask = kzalloc(longs *
  5131. sizeof(unsigned long),
  5132. GFP_KERNEL);
  5133. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5134. rc = -ENOMEM;
  5135. goto free_xri_ids;
  5136. }
  5137. phba->sli4_hba.vfi_ids = kzalloc(count *
  5138. sizeof(uint16_t),
  5139. GFP_KERNEL);
  5140. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5141. rc = -ENOMEM;
  5142. goto free_vfi_bmask;
  5143. }
  5144. for (i = 0; i < count; i++)
  5145. phba->sli4_hba.vfi_ids[i] = base + i;
  5146. /*
  5147. * Mark all resources ready. An HBA reset doesn't need
  5148. * to reset the initialization.
  5149. */
  5150. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  5151. LPFC_IDX_RSRC_RDY);
  5152. return 0;
  5153. }
  5154. free_vfi_bmask:
  5155. kfree(phba->sli4_hba.vfi_bmask);
  5156. free_xri_ids:
  5157. kfree(phba->sli4_hba.xri_ids);
  5158. free_xri_bmask:
  5159. kfree(phba->sli4_hba.xri_bmask);
  5160. free_vpi_ids:
  5161. kfree(phba->vpi_ids);
  5162. free_vpi_bmask:
  5163. kfree(phba->vpi_bmask);
  5164. free_rpi_ids:
  5165. kfree(phba->sli4_hba.rpi_ids);
  5166. free_rpi_bmask:
  5167. kfree(phba->sli4_hba.rpi_bmask);
  5168. err_exit:
  5169. return rc;
  5170. }
  5171. /**
  5172. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  5173. * @phba: Pointer to HBA context object.
  5174. *
  5175. * This function allocates the number of elements for the specified
  5176. * resource type.
  5177. **/
  5178. int
  5179. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  5180. {
  5181. if (phba->sli4_hba.extents_in_use) {
  5182. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  5183. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  5184. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  5185. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  5186. } else {
  5187. kfree(phba->vpi_bmask);
  5188. kfree(phba->vpi_ids);
  5189. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5190. kfree(phba->sli4_hba.xri_bmask);
  5191. kfree(phba->sli4_hba.xri_ids);
  5192. bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5193. kfree(phba->sli4_hba.vfi_bmask);
  5194. kfree(phba->sli4_hba.vfi_ids);
  5195. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5196. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  5197. }
  5198. return 0;
  5199. }
  5200. /**
  5201. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  5202. * @phba: Pointer to HBA context object.
  5203. * @type: The resource extent type.
  5204. * @extnt_count: buffer to hold port extent count response
  5205. * @extnt_size: buffer to hold port extent size response.
  5206. *
  5207. * This function calls the port to read the host allocated extents
  5208. * for a particular type.
  5209. **/
  5210. int
  5211. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  5212. uint16_t *extnt_cnt, uint16_t *extnt_size)
  5213. {
  5214. bool emb;
  5215. int rc = 0;
  5216. uint16_t curr_blks = 0;
  5217. uint32_t req_len, emb_len;
  5218. uint32_t alloc_len, mbox_tmo;
  5219. struct list_head *blk_list_head;
  5220. struct lpfc_rsrc_blks *rsrc_blk;
  5221. LPFC_MBOXQ_t *mbox;
  5222. void *virtaddr = NULL;
  5223. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5224. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5225. union lpfc_sli4_cfg_shdr *shdr;
  5226. switch (type) {
  5227. case LPFC_RSC_TYPE_FCOE_VPI:
  5228. blk_list_head = &phba->lpfc_vpi_blk_list;
  5229. break;
  5230. case LPFC_RSC_TYPE_FCOE_XRI:
  5231. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  5232. break;
  5233. case LPFC_RSC_TYPE_FCOE_VFI:
  5234. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  5235. break;
  5236. case LPFC_RSC_TYPE_FCOE_RPI:
  5237. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  5238. break;
  5239. default:
  5240. return -EIO;
  5241. }
  5242. /* Count the number of extents currently allocatd for this type. */
  5243. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  5244. if (curr_blks == 0) {
  5245. /*
  5246. * The GET_ALLOCATED mailbox does not return the size,
  5247. * just the count. The size should be just the size
  5248. * stored in the current allocated block and all sizes
  5249. * for an extent type are the same so set the return
  5250. * value now.
  5251. */
  5252. *extnt_size = rsrc_blk->rsrc_size;
  5253. }
  5254. curr_blks++;
  5255. }
  5256. /* Calculate the total requested length of the dma memory. */
  5257. req_len = curr_blks * sizeof(uint16_t);
  5258. /*
  5259. * Calculate the size of an embedded mailbox. The uint32_t
  5260. * accounts for extents-specific word.
  5261. */
  5262. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5263. sizeof(uint32_t);
  5264. /*
  5265. * Presume the allocation and response will fit into an embedded
  5266. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5267. */
  5268. emb = LPFC_SLI4_MBX_EMBED;
  5269. req_len = emb_len;
  5270. if (req_len > emb_len) {
  5271. req_len = curr_blks * sizeof(uint16_t) +
  5272. sizeof(union lpfc_sli4_cfg_shdr) +
  5273. sizeof(uint32_t);
  5274. emb = LPFC_SLI4_MBX_NEMBED;
  5275. }
  5276. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5277. if (!mbox)
  5278. return -ENOMEM;
  5279. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  5280. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5281. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  5282. req_len, emb);
  5283. if (alloc_len < req_len) {
  5284. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5285. "2983 Allocated DMA memory size (x%x) is "
  5286. "less than the requested DMA memory "
  5287. "size (x%x)\n", alloc_len, req_len);
  5288. rc = -ENOMEM;
  5289. goto err_exit;
  5290. }
  5291. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  5292. if (unlikely(rc)) {
  5293. rc = -EIO;
  5294. goto err_exit;
  5295. }
  5296. if (!phba->sli4_hba.intr_enable)
  5297. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5298. else {
  5299. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5300. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5301. }
  5302. if (unlikely(rc)) {
  5303. rc = -EIO;
  5304. goto err_exit;
  5305. }
  5306. /*
  5307. * Figure out where the response is located. Then get local pointers
  5308. * to the response data. The port does not guarantee to respond to
  5309. * all extents counts request so update the local variable with the
  5310. * allocated count from the port.
  5311. */
  5312. if (emb == LPFC_SLI4_MBX_EMBED) {
  5313. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5314. shdr = &rsrc_ext->header.cfg_shdr;
  5315. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5316. } else {
  5317. virtaddr = mbox->sge_array->addr[0];
  5318. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5319. shdr = &n_rsrc->cfg_shdr;
  5320. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5321. }
  5322. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  5323. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  5324. "2984 Failed to read allocated resources "
  5325. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  5326. type,
  5327. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  5328. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  5329. rc = -EIO;
  5330. goto err_exit;
  5331. }
  5332. err_exit:
  5333. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5334. return rc;
  5335. }
  5336. /**
  5337. * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
  5338. * @phba: Pointer to HBA context object.
  5339. *
  5340. * This function is the main SLI4 device intialization PCI function. This
  5341. * function is called by the HBA intialization code, HBA reset code and
  5342. * HBA error attention handler code. Caller is not required to hold any
  5343. * locks.
  5344. **/
  5345. int
  5346. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  5347. {
  5348. int rc;
  5349. LPFC_MBOXQ_t *mboxq;
  5350. struct lpfc_mqe *mqe;
  5351. uint8_t *vpd;
  5352. uint32_t vpd_size;
  5353. uint32_t ftr_rsp = 0;
  5354. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  5355. struct lpfc_vport *vport = phba->pport;
  5356. struct lpfc_dmabuf *mp;
  5357. /* Perform a PCI function reset to start from clean */
  5358. rc = lpfc_pci_function_reset(phba);
  5359. if (unlikely(rc))
  5360. return -ENODEV;
  5361. /* Check the HBA Host Status Register for readyness */
  5362. rc = lpfc_sli4_post_status_check(phba);
  5363. if (unlikely(rc))
  5364. return -ENODEV;
  5365. else {
  5366. spin_lock_irq(&phba->hbalock);
  5367. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  5368. spin_unlock_irq(&phba->hbalock);
  5369. }
  5370. /*
  5371. * Allocate a single mailbox container for initializing the
  5372. * port.
  5373. */
  5374. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5375. if (!mboxq)
  5376. return -ENOMEM;
  5377. /* Issue READ_REV to collect vpd and FW information. */
  5378. vpd_size = SLI4_PAGE_SIZE;
  5379. vpd = kzalloc(vpd_size, GFP_KERNEL);
  5380. if (!vpd) {
  5381. rc = -ENOMEM;
  5382. goto out_free_mbox;
  5383. }
  5384. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  5385. if (unlikely(rc)) {
  5386. kfree(vpd);
  5387. goto out_free_mbox;
  5388. }
  5389. mqe = &mboxq->u.mqe;
  5390. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  5391. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev))
  5392. phba->hba_flag |= HBA_FCOE_MODE;
  5393. else
  5394. phba->hba_flag &= ~HBA_FCOE_MODE;
  5395. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  5396. LPFC_DCBX_CEE_MODE)
  5397. phba->hba_flag |= HBA_FIP_SUPPORT;
  5398. else
  5399. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  5400. if (phba->sli_rev != LPFC_SLI_REV4) {
  5401. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5402. "0376 READ_REV Error. SLI Level %d "
  5403. "FCoE enabled %d\n",
  5404. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  5405. rc = -EIO;
  5406. kfree(vpd);
  5407. goto out_free_mbox;
  5408. }
  5409. /*
  5410. * Continue initialization with default values even if driver failed
  5411. * to read FCoE param config regions, only read parameters if the
  5412. * board is FCoE
  5413. */
  5414. if (phba->hba_flag & HBA_FCOE_MODE &&
  5415. lpfc_sli4_read_fcoe_params(phba))
  5416. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  5417. "2570 Failed to read FCoE parameters\n");
  5418. /*
  5419. * Retrieve sli4 device physical port name, failure of doing it
  5420. * is considered as non-fatal.
  5421. */
  5422. rc = lpfc_sli4_retrieve_pport_name(phba);
  5423. if (!rc)
  5424. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5425. "3080 Successful retrieving SLI4 device "
  5426. "physical port name: %s.\n", phba->Port);
  5427. /*
  5428. * Evaluate the read rev and vpd data. Populate the driver
  5429. * state with the results. If this routine fails, the failure
  5430. * is not fatal as the driver will use generic values.
  5431. */
  5432. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  5433. if (unlikely(!rc)) {
  5434. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5435. "0377 Error %d parsing vpd. "
  5436. "Using defaults.\n", rc);
  5437. rc = 0;
  5438. }
  5439. kfree(vpd);
  5440. /* Save information as VPD data */
  5441. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  5442. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  5443. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  5444. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  5445. &mqe->un.read_rev);
  5446. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  5447. &mqe->un.read_rev);
  5448. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  5449. &mqe->un.read_rev);
  5450. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  5451. &mqe->un.read_rev);
  5452. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  5453. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  5454. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  5455. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  5456. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  5457. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  5458. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5459. "(%d):0380 READ_REV Status x%x "
  5460. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  5461. mboxq->vport ? mboxq->vport->vpi : 0,
  5462. bf_get(lpfc_mqe_status, mqe),
  5463. phba->vpd.rev.opFwName,
  5464. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  5465. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  5466. /*
  5467. * Discover the port's supported feature set and match it against the
  5468. * hosts requests.
  5469. */
  5470. lpfc_request_features(phba, mboxq);
  5471. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5472. if (unlikely(rc)) {
  5473. rc = -EIO;
  5474. goto out_free_mbox;
  5475. }
  5476. /*
  5477. * The port must support FCP initiator mode as this is the
  5478. * only mode running in the host.
  5479. */
  5480. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  5481. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5482. "0378 No support for fcpi mode.\n");
  5483. ftr_rsp++;
  5484. }
  5485. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  5486. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  5487. else
  5488. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  5489. /*
  5490. * If the port cannot support the host's requested features
  5491. * then turn off the global config parameters to disable the
  5492. * feature in the driver. This is not a fatal error.
  5493. */
  5494. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5495. if (phba->cfg_enable_bg) {
  5496. if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
  5497. phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
  5498. else
  5499. ftr_rsp++;
  5500. }
  5501. if (phba->max_vpi && phba->cfg_enable_npiv &&
  5502. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5503. ftr_rsp++;
  5504. if (ftr_rsp) {
  5505. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  5506. "0379 Feature Mismatch Data: x%08x %08x "
  5507. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  5508. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  5509. phba->cfg_enable_npiv, phba->max_vpi);
  5510. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  5511. phba->cfg_enable_bg = 0;
  5512. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  5513. phba->cfg_enable_npiv = 0;
  5514. }
  5515. /* These SLI3 features are assumed in SLI4 */
  5516. spin_lock_irq(&phba->hbalock);
  5517. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  5518. spin_unlock_irq(&phba->hbalock);
  5519. /*
  5520. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  5521. * calls depends on these resources to complete port setup.
  5522. */
  5523. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  5524. if (rc) {
  5525. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5526. "2920 Failed to alloc Resource IDs "
  5527. "rc = x%x\n", rc);
  5528. goto out_free_mbox;
  5529. }
  5530. /* update physical xri mappings in the scsi buffers */
  5531. lpfc_scsi_buf_update(phba);
  5532. /* Read the port's service parameters. */
  5533. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  5534. if (rc) {
  5535. phba->link_state = LPFC_HBA_ERROR;
  5536. rc = -ENOMEM;
  5537. goto out_free_mbox;
  5538. }
  5539. mboxq->vport = vport;
  5540. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5541. mp = (struct lpfc_dmabuf *) mboxq->context1;
  5542. if (rc == MBX_SUCCESS) {
  5543. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  5544. rc = 0;
  5545. }
  5546. /*
  5547. * This memory was allocated by the lpfc_read_sparam routine. Release
  5548. * it to the mbuf pool.
  5549. */
  5550. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  5551. kfree(mp);
  5552. mboxq->context1 = NULL;
  5553. if (unlikely(rc)) {
  5554. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5555. "0382 READ_SPARAM command failed "
  5556. "status %d, mbxStatus x%x\n",
  5557. rc, bf_get(lpfc_mqe_status, mqe));
  5558. phba->link_state = LPFC_HBA_ERROR;
  5559. rc = -EIO;
  5560. goto out_free_mbox;
  5561. }
  5562. lpfc_update_vport_wwn(vport);
  5563. /* Update the fc_host data structures with new wwn. */
  5564. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  5565. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  5566. /* Register SGL pool to the device using non-embedded mailbox command */
  5567. if (!phba->sli4_hba.extents_in_use) {
  5568. rc = lpfc_sli4_post_els_sgl_list(phba);
  5569. if (unlikely(rc)) {
  5570. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5571. "0582 Error %d during els sgl post "
  5572. "operation\n", rc);
  5573. rc = -ENODEV;
  5574. goto out_free_mbox;
  5575. }
  5576. } else {
  5577. rc = lpfc_sli4_post_els_sgl_list_ext(phba);
  5578. if (unlikely(rc)) {
  5579. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5580. "2560 Error %d during els sgl post "
  5581. "operation\n", rc);
  5582. rc = -ENODEV;
  5583. goto out_free_mbox;
  5584. }
  5585. }
  5586. /* Register SCSI SGL pool to the device */
  5587. rc = lpfc_sli4_repost_scsi_sgl_list(phba);
  5588. if (unlikely(rc)) {
  5589. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5590. "0383 Error %d during scsi sgl post "
  5591. "operation\n", rc);
  5592. /* Some Scsi buffers were moved to the abort scsi list */
  5593. /* A pci function reset will repost them */
  5594. rc = -ENODEV;
  5595. goto out_free_mbox;
  5596. }
  5597. /* Post the rpi header region to the device. */
  5598. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  5599. if (unlikely(rc)) {
  5600. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5601. "0393 Error %d during rpi post operation\n",
  5602. rc);
  5603. rc = -ENODEV;
  5604. goto out_free_mbox;
  5605. }
  5606. /* Create all the SLI4 queues */
  5607. rc = lpfc_sli4_queue_create(phba);
  5608. if (rc) {
  5609. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5610. "3089 Failed to allocate queues\n");
  5611. rc = -ENODEV;
  5612. goto out_stop_timers;
  5613. }
  5614. /* Set up all the queues to the device */
  5615. rc = lpfc_sli4_queue_setup(phba);
  5616. if (unlikely(rc)) {
  5617. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5618. "0381 Error %d during queue setup.\n ", rc);
  5619. goto out_destroy_queue;
  5620. }
  5621. /* Arm the CQs and then EQs on device */
  5622. lpfc_sli4_arm_cqeq_intr(phba);
  5623. /* Indicate device interrupt mode */
  5624. phba->sli4_hba.intr_enable = 1;
  5625. /* Allow asynchronous mailbox command to go through */
  5626. spin_lock_irq(&phba->hbalock);
  5627. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5628. spin_unlock_irq(&phba->hbalock);
  5629. /* Post receive buffers to the device */
  5630. lpfc_sli4_rb_setup(phba);
  5631. /* Reset HBA FCF states after HBA reset */
  5632. phba->fcf.fcf_flag = 0;
  5633. phba->fcf.current_rec.flag = 0;
  5634. /* Start the ELS watchdog timer */
  5635. mod_timer(&vport->els_tmofunc,
  5636. jiffies + HZ * (phba->fc_ratov * 2));
  5637. /* Start heart beat timer */
  5638. mod_timer(&phba->hb_tmofunc,
  5639. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  5640. phba->hb_outstanding = 0;
  5641. phba->last_completion_time = jiffies;
  5642. /* Start error attention (ERATT) polling timer */
  5643. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  5644. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5645. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5646. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5647. if (!rc) {
  5648. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5649. "2829 This device supports "
  5650. "Advanced Error Reporting (AER)\n");
  5651. spin_lock_irq(&phba->hbalock);
  5652. phba->hba_flag |= HBA_AER_ENABLED;
  5653. spin_unlock_irq(&phba->hbalock);
  5654. } else {
  5655. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5656. "2830 This device does not support "
  5657. "Advanced Error Reporting (AER)\n");
  5658. phba->cfg_aer_support = 0;
  5659. }
  5660. rc = 0;
  5661. }
  5662. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  5663. /*
  5664. * The FC Port needs to register FCFI (index 0)
  5665. */
  5666. lpfc_reg_fcfi(phba, mboxq);
  5667. mboxq->vport = phba->pport;
  5668. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5669. if (rc != MBX_SUCCESS)
  5670. goto out_unset_queue;
  5671. rc = 0;
  5672. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  5673. &mboxq->u.mqe.un.reg_fcfi);
  5674. /* Check if the port is configured to be disabled */
  5675. lpfc_sli_read_link_ste(phba);
  5676. }
  5677. /*
  5678. * The port is ready, set the host's link state to LINK_DOWN
  5679. * in preparation for link interrupts.
  5680. */
  5681. spin_lock_irq(&phba->hbalock);
  5682. phba->link_state = LPFC_LINK_DOWN;
  5683. spin_unlock_irq(&phba->hbalock);
  5684. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  5685. (phba->hba_flag & LINK_DISABLED)) {
  5686. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5687. "3103 Adapter Link is disabled.\n");
  5688. lpfc_down_link(phba, mboxq);
  5689. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5690. if (rc != MBX_SUCCESS) {
  5691. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
  5692. "3104 Adapter failed to issue "
  5693. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  5694. goto out_unset_queue;
  5695. }
  5696. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  5697. /* don't perform init_link on SLI4 FC port loopback test */
  5698. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  5699. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  5700. if (rc)
  5701. goto out_unset_queue;
  5702. }
  5703. }
  5704. mempool_free(mboxq, phba->mbox_mem_pool);
  5705. return rc;
  5706. out_unset_queue:
  5707. /* Unset all the queues set up in this routine when error out */
  5708. lpfc_sli4_queue_unset(phba);
  5709. out_destroy_queue:
  5710. lpfc_sli4_queue_destroy(phba);
  5711. out_stop_timers:
  5712. lpfc_stop_hba_timers(phba);
  5713. out_free_mbox:
  5714. mempool_free(mboxq, phba->mbox_mem_pool);
  5715. return rc;
  5716. }
  5717. /**
  5718. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  5719. * @ptr: context object - pointer to hba structure.
  5720. *
  5721. * This is the callback function for mailbox timer. The mailbox
  5722. * timer is armed when a new mailbox command is issued and the timer
  5723. * is deleted when the mailbox complete. The function is called by
  5724. * the kernel timer code when a mailbox does not complete within
  5725. * expected time. This function wakes up the worker thread to
  5726. * process the mailbox timeout and returns. All the processing is
  5727. * done by the worker thread function lpfc_mbox_timeout_handler.
  5728. **/
  5729. void
  5730. lpfc_mbox_timeout(unsigned long ptr)
  5731. {
  5732. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  5733. unsigned long iflag;
  5734. uint32_t tmo_posted;
  5735. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  5736. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  5737. if (!tmo_posted)
  5738. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  5739. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  5740. if (!tmo_posted)
  5741. lpfc_worker_wake_up(phba);
  5742. return;
  5743. }
  5744. /**
  5745. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  5746. * @phba: Pointer to HBA context object.
  5747. *
  5748. * This function is called from worker thread when a mailbox command times out.
  5749. * The caller is not required to hold any locks. This function will reset the
  5750. * HBA and recover all the pending commands.
  5751. **/
  5752. void
  5753. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  5754. {
  5755. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  5756. MAILBOX_t *mb = &pmbox->u.mb;
  5757. struct lpfc_sli *psli = &phba->sli;
  5758. struct lpfc_sli_ring *pring;
  5759. /* Check the pmbox pointer first. There is a race condition
  5760. * between the mbox timeout handler getting executed in the
  5761. * worklist and the mailbox actually completing. When this
  5762. * race condition occurs, the mbox_active will be NULL.
  5763. */
  5764. spin_lock_irq(&phba->hbalock);
  5765. if (pmbox == NULL) {
  5766. lpfc_printf_log(phba, KERN_WARNING,
  5767. LOG_MBOX | LOG_SLI,
  5768. "0353 Active Mailbox cleared - mailbox timeout "
  5769. "exiting\n");
  5770. spin_unlock_irq(&phba->hbalock);
  5771. return;
  5772. }
  5773. /* Mbox cmd <mbxCommand> timeout */
  5774. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5775. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  5776. mb->mbxCommand,
  5777. phba->pport->port_state,
  5778. phba->sli.sli_flag,
  5779. phba->sli.mbox_active);
  5780. spin_unlock_irq(&phba->hbalock);
  5781. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  5782. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  5783. * it to fail all outstanding SCSI IO.
  5784. */
  5785. spin_lock_irq(&phba->pport->work_port_lock);
  5786. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  5787. spin_unlock_irq(&phba->pport->work_port_lock);
  5788. spin_lock_irq(&phba->hbalock);
  5789. phba->link_state = LPFC_LINK_UNKNOWN;
  5790. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  5791. spin_unlock_irq(&phba->hbalock);
  5792. pring = &psli->ring[psli->fcp_ring];
  5793. lpfc_sli_abort_iocb_ring(phba, pring);
  5794. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5795. "0345 Resetting board due to mailbox timeout\n");
  5796. /* Reset the HBA device */
  5797. lpfc_reset_hba(phba);
  5798. }
  5799. /**
  5800. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  5801. * @phba: Pointer to HBA context object.
  5802. * @pmbox: Pointer to mailbox object.
  5803. * @flag: Flag indicating how the mailbox need to be processed.
  5804. *
  5805. * This function is called by discovery code and HBA management code
  5806. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  5807. * function gets the hbalock to protect the data structures.
  5808. * The mailbox command can be submitted in polling mode, in which case
  5809. * this function will wait in a polling loop for the completion of the
  5810. * mailbox.
  5811. * If the mailbox is submitted in no_wait mode (not polling) the
  5812. * function will submit the command and returns immediately without waiting
  5813. * for the mailbox completion. The no_wait is supported only when HBA
  5814. * is in SLI2/SLI3 mode - interrupts are enabled.
  5815. * The SLI interface allows only one mailbox pending at a time. If the
  5816. * mailbox is issued in polling mode and there is already a mailbox
  5817. * pending, then the function will return an error. If the mailbox is issued
  5818. * in NO_WAIT mode and there is a mailbox pending already, the function
  5819. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  5820. * The sli layer owns the mailbox object until the completion of mailbox
  5821. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  5822. * return codes the caller owns the mailbox command after the return of
  5823. * the function.
  5824. **/
  5825. static int
  5826. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  5827. uint32_t flag)
  5828. {
  5829. MAILBOX_t *mb;
  5830. struct lpfc_sli *psli = &phba->sli;
  5831. uint32_t status, evtctr;
  5832. uint32_t ha_copy, hc_copy;
  5833. int i;
  5834. unsigned long timeout;
  5835. unsigned long drvr_flag = 0;
  5836. uint32_t word0, ldata;
  5837. void __iomem *to_slim;
  5838. int processing_queue = 0;
  5839. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  5840. if (!pmbox) {
  5841. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5842. /* processing mbox queue from intr_handler */
  5843. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  5844. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5845. return MBX_SUCCESS;
  5846. }
  5847. processing_queue = 1;
  5848. pmbox = lpfc_mbox_get(phba);
  5849. if (!pmbox) {
  5850. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5851. return MBX_SUCCESS;
  5852. }
  5853. }
  5854. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  5855. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  5856. if(!pmbox->vport) {
  5857. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5858. lpfc_printf_log(phba, KERN_ERR,
  5859. LOG_MBOX | LOG_VPORT,
  5860. "1806 Mbox x%x failed. No vport\n",
  5861. pmbox->u.mb.mbxCommand);
  5862. dump_stack();
  5863. goto out_not_finished;
  5864. }
  5865. }
  5866. /* If the PCI channel is in offline state, do not post mbox. */
  5867. if (unlikely(pci_channel_offline(phba->pcidev))) {
  5868. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5869. goto out_not_finished;
  5870. }
  5871. /* If HBA has a deferred error attention, fail the iocb. */
  5872. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  5873. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5874. goto out_not_finished;
  5875. }
  5876. psli = &phba->sli;
  5877. mb = &pmbox->u.mb;
  5878. status = MBX_SUCCESS;
  5879. if (phba->link_state == LPFC_HBA_ERROR) {
  5880. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5881. /* Mbox command <mbxCommand> cannot issue */
  5882. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5883. "(%d):0311 Mailbox command x%x cannot "
  5884. "issue Data: x%x x%x\n",
  5885. pmbox->vport ? pmbox->vport->vpi : 0,
  5886. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  5887. goto out_not_finished;
  5888. }
  5889. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  5890. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  5891. !(hc_copy & HC_MBINT_ENA)) {
  5892. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5893. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5894. "(%d):2528 Mailbox command x%x cannot "
  5895. "issue Data: x%x x%x\n",
  5896. pmbox->vport ? pmbox->vport->vpi : 0,
  5897. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  5898. goto out_not_finished;
  5899. }
  5900. }
  5901. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  5902. /* Polling for a mbox command when another one is already active
  5903. * is not allowed in SLI. Also, the driver must have established
  5904. * SLI2 mode to queue and process multiple mbox commands.
  5905. */
  5906. if (flag & MBX_POLL) {
  5907. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5908. /* Mbox command <mbxCommand> cannot issue */
  5909. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5910. "(%d):2529 Mailbox command x%x "
  5911. "cannot issue Data: x%x x%x\n",
  5912. pmbox->vport ? pmbox->vport->vpi : 0,
  5913. pmbox->u.mb.mbxCommand,
  5914. psli->sli_flag, flag);
  5915. goto out_not_finished;
  5916. }
  5917. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  5918. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5919. /* Mbox command <mbxCommand> cannot issue */
  5920. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5921. "(%d):2530 Mailbox command x%x "
  5922. "cannot issue Data: x%x x%x\n",
  5923. pmbox->vport ? pmbox->vport->vpi : 0,
  5924. pmbox->u.mb.mbxCommand,
  5925. psli->sli_flag, flag);
  5926. goto out_not_finished;
  5927. }
  5928. /* Another mailbox command is still being processed, queue this
  5929. * command to be processed later.
  5930. */
  5931. lpfc_mbox_put(phba, pmbox);
  5932. /* Mbox cmd issue - BUSY */
  5933. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5934. "(%d):0308 Mbox cmd issue - BUSY Data: "
  5935. "x%x x%x x%x x%x\n",
  5936. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  5937. mb->mbxCommand, phba->pport->port_state,
  5938. psli->sli_flag, flag);
  5939. psli->slistat.mbox_busy++;
  5940. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5941. if (pmbox->vport) {
  5942. lpfc_debugfs_disc_trc(pmbox->vport,
  5943. LPFC_DISC_TRC_MBOX_VPORT,
  5944. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  5945. (uint32_t)mb->mbxCommand,
  5946. mb->un.varWords[0], mb->un.varWords[1]);
  5947. }
  5948. else {
  5949. lpfc_debugfs_disc_trc(phba->pport,
  5950. LPFC_DISC_TRC_MBOX,
  5951. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  5952. (uint32_t)mb->mbxCommand,
  5953. mb->un.varWords[0], mb->un.varWords[1]);
  5954. }
  5955. return MBX_BUSY;
  5956. }
  5957. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5958. /* If we are not polling, we MUST be in SLI2 mode */
  5959. if (flag != MBX_POLL) {
  5960. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  5961. (mb->mbxCommand != MBX_KILL_BOARD)) {
  5962. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5963. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  5964. /* Mbox command <mbxCommand> cannot issue */
  5965. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  5966. "(%d):2531 Mailbox command x%x "
  5967. "cannot issue Data: x%x x%x\n",
  5968. pmbox->vport ? pmbox->vport->vpi : 0,
  5969. pmbox->u.mb.mbxCommand,
  5970. psli->sli_flag, flag);
  5971. goto out_not_finished;
  5972. }
  5973. /* timeout active mbox command */
  5974. mod_timer(&psli->mbox_tmo, (jiffies +
  5975. (HZ * lpfc_mbox_tmo_val(phba, pmbox))));
  5976. }
  5977. /* Mailbox cmd <cmd> issue */
  5978. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5979. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  5980. "x%x\n",
  5981. pmbox->vport ? pmbox->vport->vpi : 0,
  5982. mb->mbxCommand, phba->pport->port_state,
  5983. psli->sli_flag, flag);
  5984. if (mb->mbxCommand != MBX_HEARTBEAT) {
  5985. if (pmbox->vport) {
  5986. lpfc_debugfs_disc_trc(pmbox->vport,
  5987. LPFC_DISC_TRC_MBOX_VPORT,
  5988. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  5989. (uint32_t)mb->mbxCommand,
  5990. mb->un.varWords[0], mb->un.varWords[1]);
  5991. }
  5992. else {
  5993. lpfc_debugfs_disc_trc(phba->pport,
  5994. LPFC_DISC_TRC_MBOX,
  5995. "MBOX Send: cmd:x%x mb:x%x x%x",
  5996. (uint32_t)mb->mbxCommand,
  5997. mb->un.varWords[0], mb->un.varWords[1]);
  5998. }
  5999. }
  6000. psli->slistat.mbox_cmd++;
  6001. evtctr = psli->slistat.mbox_event;
  6002. /* next set own bit for the adapter and copy over command word */
  6003. mb->mbxOwner = OWN_CHIP;
  6004. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6005. /* Populate mbox extension offset word. */
  6006. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  6007. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6008. = (uint8_t *)phba->mbox_ext
  6009. - (uint8_t *)phba->mbox;
  6010. }
  6011. /* Copy the mailbox extension data */
  6012. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6013. lpfc_sli_pcimem_bcopy(pmbox->context2,
  6014. (uint8_t *)phba->mbox_ext,
  6015. pmbox->in_ext_byte_len);
  6016. }
  6017. /* Copy command data to host SLIM area */
  6018. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6019. } else {
  6020. /* Populate mbox extension offset word. */
  6021. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  6022. *(((uint32_t *)mb) + pmbox->mbox_offset_word)
  6023. = MAILBOX_HBA_EXT_OFFSET;
  6024. /* Copy the mailbox extension data */
  6025. if (pmbox->in_ext_byte_len && pmbox->context2) {
  6026. lpfc_memcpy_to_slim(phba->MBslimaddr +
  6027. MAILBOX_HBA_EXT_OFFSET,
  6028. pmbox->context2, pmbox->in_ext_byte_len);
  6029. }
  6030. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6031. /* copy command data into host mbox for cmpl */
  6032. lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
  6033. }
  6034. /* First copy mbox command data to HBA SLIM, skip past first
  6035. word */
  6036. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  6037. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  6038. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  6039. /* Next copy over first word, with mbxOwner set */
  6040. ldata = *((uint32_t *)mb);
  6041. to_slim = phba->MBslimaddr;
  6042. writel(ldata, to_slim);
  6043. readl(to_slim); /* flush */
  6044. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6045. /* switch over to host mailbox */
  6046. psli->sli_flag |= LPFC_SLI_ACTIVE;
  6047. }
  6048. }
  6049. wmb();
  6050. switch (flag) {
  6051. case MBX_NOWAIT:
  6052. /* Set up reference to mailbox command */
  6053. psli->mbox_active = pmbox;
  6054. /* Interrupt board to do it */
  6055. writel(CA_MBATT, phba->CAregaddr);
  6056. readl(phba->CAregaddr); /* flush */
  6057. /* Don't wait for it to finish, just return */
  6058. break;
  6059. case MBX_POLL:
  6060. /* Set up null reference to mailbox command */
  6061. psli->mbox_active = NULL;
  6062. /* Interrupt board to do it */
  6063. writel(CA_MBATT, phba->CAregaddr);
  6064. readl(phba->CAregaddr); /* flush */
  6065. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6066. /* First read mbox status word */
  6067. word0 = *((uint32_t *)phba->mbox);
  6068. word0 = le32_to_cpu(word0);
  6069. } else {
  6070. /* First read mbox status word */
  6071. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  6072. spin_unlock_irqrestore(&phba->hbalock,
  6073. drvr_flag);
  6074. goto out_not_finished;
  6075. }
  6076. }
  6077. /* Read the HBA Host Attention Register */
  6078. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6079. spin_unlock_irqrestore(&phba->hbalock,
  6080. drvr_flag);
  6081. goto out_not_finished;
  6082. }
  6083. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  6084. 1000) + jiffies;
  6085. i = 0;
  6086. /* Wait for command to complete */
  6087. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  6088. (!(ha_copy & HA_MBATT) &&
  6089. (phba->link_state > LPFC_WARM_START))) {
  6090. if (time_after(jiffies, timeout)) {
  6091. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6092. spin_unlock_irqrestore(&phba->hbalock,
  6093. drvr_flag);
  6094. goto out_not_finished;
  6095. }
  6096. /* Check if we took a mbox interrupt while we were
  6097. polling */
  6098. if (((word0 & OWN_CHIP) != OWN_CHIP)
  6099. && (evtctr != psli->slistat.mbox_event))
  6100. break;
  6101. if (i++ > 10) {
  6102. spin_unlock_irqrestore(&phba->hbalock,
  6103. drvr_flag);
  6104. msleep(1);
  6105. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  6106. }
  6107. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6108. /* First copy command data */
  6109. word0 = *((uint32_t *)phba->mbox);
  6110. word0 = le32_to_cpu(word0);
  6111. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  6112. MAILBOX_t *slimmb;
  6113. uint32_t slimword0;
  6114. /* Check real SLIM for any errors */
  6115. slimword0 = readl(phba->MBslimaddr);
  6116. slimmb = (MAILBOX_t *) & slimword0;
  6117. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  6118. && slimmb->mbxStatus) {
  6119. psli->sli_flag &=
  6120. ~LPFC_SLI_ACTIVE;
  6121. word0 = slimword0;
  6122. }
  6123. }
  6124. } else {
  6125. /* First copy command data */
  6126. word0 = readl(phba->MBslimaddr);
  6127. }
  6128. /* Read the HBA Host Attention Register */
  6129. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  6130. spin_unlock_irqrestore(&phba->hbalock,
  6131. drvr_flag);
  6132. goto out_not_finished;
  6133. }
  6134. }
  6135. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  6136. /* copy results back to user */
  6137. lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
  6138. /* Copy the mailbox extension data */
  6139. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6140. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  6141. pmbox->context2,
  6142. pmbox->out_ext_byte_len);
  6143. }
  6144. } else {
  6145. /* First copy command data */
  6146. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  6147. MAILBOX_CMD_SIZE);
  6148. /* Copy the mailbox extension data */
  6149. if (pmbox->out_ext_byte_len && pmbox->context2) {
  6150. lpfc_memcpy_from_slim(pmbox->context2,
  6151. phba->MBslimaddr +
  6152. MAILBOX_HBA_EXT_OFFSET,
  6153. pmbox->out_ext_byte_len);
  6154. }
  6155. }
  6156. writel(HA_MBATT, phba->HAregaddr);
  6157. readl(phba->HAregaddr); /* flush */
  6158. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6159. status = mb->mbxStatus;
  6160. }
  6161. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  6162. return status;
  6163. out_not_finished:
  6164. if (processing_queue) {
  6165. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6166. lpfc_mbox_cmpl_put(phba, pmbox);
  6167. }
  6168. return MBX_NOT_FINISHED;
  6169. }
  6170. /**
  6171. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  6172. * @phba: Pointer to HBA context object.
  6173. *
  6174. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  6175. * the driver internal pending mailbox queue. It will then try to wait out the
  6176. * possible outstanding mailbox command before return.
  6177. *
  6178. * Returns:
  6179. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  6180. * the outstanding mailbox command timed out.
  6181. **/
  6182. static int
  6183. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  6184. {
  6185. struct lpfc_sli *psli = &phba->sli;
  6186. int rc = 0;
  6187. unsigned long timeout = 0;
  6188. /* Mark the asynchronous mailbox command posting as blocked */
  6189. spin_lock_irq(&phba->hbalock);
  6190. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6191. /* Determine how long we might wait for the active mailbox
  6192. * command to be gracefully completed by firmware.
  6193. */
  6194. if (phba->sli.mbox_active)
  6195. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  6196. phba->sli.mbox_active) *
  6197. 1000) + jiffies;
  6198. spin_unlock_irq(&phba->hbalock);
  6199. /* Wait for the outstnading mailbox command to complete */
  6200. while (phba->sli.mbox_active) {
  6201. /* Check active mailbox complete status every 2ms */
  6202. msleep(2);
  6203. if (time_after(jiffies, timeout)) {
  6204. /* Timeout, marked the outstanding cmd not complete */
  6205. rc = 1;
  6206. break;
  6207. }
  6208. }
  6209. /* Can not cleanly block async mailbox command, fails it */
  6210. if (rc) {
  6211. spin_lock_irq(&phba->hbalock);
  6212. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6213. spin_unlock_irq(&phba->hbalock);
  6214. }
  6215. return rc;
  6216. }
  6217. /**
  6218. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  6219. * @phba: Pointer to HBA context object.
  6220. *
  6221. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  6222. * commands from the driver internal pending mailbox queue. It makes sure
  6223. * that there is no outstanding mailbox command before resuming posting
  6224. * asynchronous mailbox commands. If, for any reason, there is outstanding
  6225. * mailbox command, it will try to wait it out before resuming asynchronous
  6226. * mailbox command posting.
  6227. **/
  6228. static void
  6229. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  6230. {
  6231. struct lpfc_sli *psli = &phba->sli;
  6232. spin_lock_irq(&phba->hbalock);
  6233. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6234. /* Asynchronous mailbox posting is not blocked, do nothing */
  6235. spin_unlock_irq(&phba->hbalock);
  6236. return;
  6237. }
  6238. /* Outstanding synchronous mailbox command is guaranteed to be done,
  6239. * successful or timeout, after timing-out the outstanding mailbox
  6240. * command shall always be removed, so just unblock posting async
  6241. * mailbox command and resume
  6242. */
  6243. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  6244. spin_unlock_irq(&phba->hbalock);
  6245. /* wake up worker thread to post asynchronlous mailbox command */
  6246. lpfc_worker_wake_up(phba);
  6247. }
  6248. /**
  6249. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  6250. * @phba: Pointer to HBA context object.
  6251. * @mboxq: Pointer to mailbox object.
  6252. *
  6253. * The function posts a mailbox to the port. The mailbox is expected
  6254. * to be comletely filled in and ready for the port to operate on it.
  6255. * This routine executes a synchronous completion operation on the
  6256. * mailbox by polling for its completion.
  6257. *
  6258. * The caller must not be holding any locks when calling this routine.
  6259. *
  6260. * Returns:
  6261. * MBX_SUCCESS - mailbox posted successfully
  6262. * Any of the MBX error values.
  6263. **/
  6264. static int
  6265. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  6266. {
  6267. int rc = MBX_SUCCESS;
  6268. unsigned long iflag;
  6269. uint32_t db_ready;
  6270. uint32_t mcqe_status;
  6271. uint32_t mbx_cmnd;
  6272. unsigned long timeout;
  6273. struct lpfc_sli *psli = &phba->sli;
  6274. struct lpfc_mqe *mb = &mboxq->u.mqe;
  6275. struct lpfc_bmbx_create *mbox_rgn;
  6276. struct dma_address *dma_address;
  6277. struct lpfc_register bmbx_reg;
  6278. /*
  6279. * Only one mailbox can be active to the bootstrap mailbox region
  6280. * at a time and there is no queueing provided.
  6281. */
  6282. spin_lock_irqsave(&phba->hbalock, iflag);
  6283. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6284. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6285. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6286. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  6287. "cannot issue Data: x%x x%x\n",
  6288. mboxq->vport ? mboxq->vport->vpi : 0,
  6289. mboxq->u.mb.mbxCommand,
  6290. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6291. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6292. psli->sli_flag, MBX_POLL);
  6293. return MBXERR_ERROR;
  6294. }
  6295. /* The server grabs the token and owns it until release */
  6296. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6297. phba->sli.mbox_active = mboxq;
  6298. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6299. /*
  6300. * Initialize the bootstrap memory region to avoid stale data areas
  6301. * in the mailbox post. Then copy the caller's mailbox contents to
  6302. * the bmbx mailbox region.
  6303. */
  6304. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  6305. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  6306. lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  6307. sizeof(struct lpfc_mqe));
  6308. /* Post the high mailbox dma address to the port and wait for ready. */
  6309. dma_address = &phba->sli4_hba.bmbx.dma_address;
  6310. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  6311. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6312. * 1000) + jiffies;
  6313. do {
  6314. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6315. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6316. if (!db_ready)
  6317. msleep(2);
  6318. if (time_after(jiffies, timeout)) {
  6319. rc = MBXERR_ERROR;
  6320. goto exit;
  6321. }
  6322. } while (!db_ready);
  6323. /* Post the low mailbox dma address to the port. */
  6324. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  6325. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  6326. * 1000) + jiffies;
  6327. do {
  6328. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  6329. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  6330. if (!db_ready)
  6331. msleep(2);
  6332. if (time_after(jiffies, timeout)) {
  6333. rc = MBXERR_ERROR;
  6334. goto exit;
  6335. }
  6336. } while (!db_ready);
  6337. /*
  6338. * Read the CQ to ensure the mailbox has completed.
  6339. * If so, update the mailbox status so that the upper layers
  6340. * can complete the request normally.
  6341. */
  6342. lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  6343. sizeof(struct lpfc_mqe));
  6344. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  6345. lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  6346. sizeof(struct lpfc_mcqe));
  6347. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  6348. /*
  6349. * When the CQE status indicates a failure and the mailbox status
  6350. * indicates success then copy the CQE status into the mailbox status
  6351. * (and prefix it with x4000).
  6352. */
  6353. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  6354. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  6355. bf_set(lpfc_mqe_status, mb,
  6356. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  6357. rc = MBXERR_ERROR;
  6358. } else
  6359. lpfc_sli4_swap_str(phba, mboxq);
  6360. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6361. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  6362. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  6363. " x%x x%x CQ: x%x x%x x%x x%x\n",
  6364. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6365. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6366. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6367. bf_get(lpfc_mqe_status, mb),
  6368. mb->un.mb_words[0], mb->un.mb_words[1],
  6369. mb->un.mb_words[2], mb->un.mb_words[3],
  6370. mb->un.mb_words[4], mb->un.mb_words[5],
  6371. mb->un.mb_words[6], mb->un.mb_words[7],
  6372. mb->un.mb_words[8], mb->un.mb_words[9],
  6373. mb->un.mb_words[10], mb->un.mb_words[11],
  6374. mb->un.mb_words[12], mboxq->mcqe.word0,
  6375. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  6376. mboxq->mcqe.trailer);
  6377. exit:
  6378. /* We are holding the token, no needed for lock when release */
  6379. spin_lock_irqsave(&phba->hbalock, iflag);
  6380. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6381. phba->sli.mbox_active = NULL;
  6382. spin_unlock_irqrestore(&phba->hbalock, iflag);
  6383. return rc;
  6384. }
  6385. /**
  6386. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  6387. * @phba: Pointer to HBA context object.
  6388. * @pmbox: Pointer to mailbox object.
  6389. * @flag: Flag indicating how the mailbox need to be processed.
  6390. *
  6391. * This function is called by discovery code and HBA management code to submit
  6392. * a mailbox command to firmware with SLI-4 interface spec.
  6393. *
  6394. * Return codes the caller owns the mailbox command after the return of the
  6395. * function.
  6396. **/
  6397. static int
  6398. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  6399. uint32_t flag)
  6400. {
  6401. struct lpfc_sli *psli = &phba->sli;
  6402. unsigned long iflags;
  6403. int rc;
  6404. /* dump from issue mailbox command if setup */
  6405. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  6406. rc = lpfc_mbox_dev_check(phba);
  6407. if (unlikely(rc)) {
  6408. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6409. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  6410. "cannot issue Data: x%x x%x\n",
  6411. mboxq->vport ? mboxq->vport->vpi : 0,
  6412. mboxq->u.mb.mbxCommand,
  6413. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6414. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6415. psli->sli_flag, flag);
  6416. goto out_not_finished;
  6417. }
  6418. /* Detect polling mode and jump to a handler */
  6419. if (!phba->sli4_hba.intr_enable) {
  6420. if (flag == MBX_POLL)
  6421. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6422. else
  6423. rc = -EIO;
  6424. if (rc != MBX_SUCCESS)
  6425. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6426. "(%d):2541 Mailbox command x%x "
  6427. "(x%x/x%x) cannot issue Data: "
  6428. "x%x x%x\n",
  6429. mboxq->vport ? mboxq->vport->vpi : 0,
  6430. mboxq->u.mb.mbxCommand,
  6431. lpfc_sli_config_mbox_subsys_get(phba,
  6432. mboxq),
  6433. lpfc_sli_config_mbox_opcode_get(phba,
  6434. mboxq),
  6435. psli->sli_flag, flag);
  6436. return rc;
  6437. } else if (flag == MBX_POLL) {
  6438. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  6439. "(%d):2542 Try to issue mailbox command "
  6440. "x%x (x%x/x%x) synchronously ahead of async"
  6441. "mailbox command queue: x%x x%x\n",
  6442. mboxq->vport ? mboxq->vport->vpi : 0,
  6443. mboxq->u.mb.mbxCommand,
  6444. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6445. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6446. psli->sli_flag, flag);
  6447. /* Try to block the asynchronous mailbox posting */
  6448. rc = lpfc_sli4_async_mbox_block(phba);
  6449. if (!rc) {
  6450. /* Successfully blocked, now issue sync mbox cmd */
  6451. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  6452. if (rc != MBX_SUCCESS)
  6453. lpfc_printf_log(phba, KERN_ERR,
  6454. LOG_MBOX | LOG_SLI,
  6455. "(%d):2597 Mailbox command "
  6456. "x%x (x%x/x%x) cannot issue "
  6457. "Data: x%x x%x\n",
  6458. mboxq->vport ?
  6459. mboxq->vport->vpi : 0,
  6460. mboxq->u.mb.mbxCommand,
  6461. lpfc_sli_config_mbox_subsys_get(phba,
  6462. mboxq),
  6463. lpfc_sli_config_mbox_opcode_get(phba,
  6464. mboxq),
  6465. psli->sli_flag, flag);
  6466. /* Unblock the async mailbox posting afterward */
  6467. lpfc_sli4_async_mbox_unblock(phba);
  6468. }
  6469. return rc;
  6470. }
  6471. /* Now, interrupt mode asynchrous mailbox command */
  6472. rc = lpfc_mbox_cmd_check(phba, mboxq);
  6473. if (rc) {
  6474. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6475. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  6476. "cannot issue Data: x%x x%x\n",
  6477. mboxq->vport ? mboxq->vport->vpi : 0,
  6478. mboxq->u.mb.mbxCommand,
  6479. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6480. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6481. psli->sli_flag, flag);
  6482. goto out_not_finished;
  6483. }
  6484. /* Put the mailbox command to the driver internal FIFO */
  6485. psli->slistat.mbox_busy++;
  6486. spin_lock_irqsave(&phba->hbalock, iflags);
  6487. lpfc_mbox_put(phba, mboxq);
  6488. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6489. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6490. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  6491. "x%x (x%x/x%x) x%x x%x x%x\n",
  6492. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  6493. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  6494. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6495. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6496. phba->pport->port_state,
  6497. psli->sli_flag, MBX_NOWAIT);
  6498. /* Wake up worker thread to transport mailbox command from head */
  6499. lpfc_worker_wake_up(phba);
  6500. return MBX_BUSY;
  6501. out_not_finished:
  6502. return MBX_NOT_FINISHED;
  6503. }
  6504. /**
  6505. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  6506. * @phba: Pointer to HBA context object.
  6507. *
  6508. * This function is called by worker thread to send a mailbox command to
  6509. * SLI4 HBA firmware.
  6510. *
  6511. **/
  6512. int
  6513. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  6514. {
  6515. struct lpfc_sli *psli = &phba->sli;
  6516. LPFC_MBOXQ_t *mboxq;
  6517. int rc = MBX_SUCCESS;
  6518. unsigned long iflags;
  6519. struct lpfc_mqe *mqe;
  6520. uint32_t mbx_cmnd;
  6521. /* Check interrupt mode before post async mailbox command */
  6522. if (unlikely(!phba->sli4_hba.intr_enable))
  6523. return MBX_NOT_FINISHED;
  6524. /* Check for mailbox command service token */
  6525. spin_lock_irqsave(&phba->hbalock, iflags);
  6526. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  6527. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6528. return MBX_NOT_FINISHED;
  6529. }
  6530. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6531. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6532. return MBX_NOT_FINISHED;
  6533. }
  6534. if (unlikely(phba->sli.mbox_active)) {
  6535. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6536. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6537. "0384 There is pending active mailbox cmd\n");
  6538. return MBX_NOT_FINISHED;
  6539. }
  6540. /* Take the mailbox command service token */
  6541. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  6542. /* Get the next mailbox command from head of queue */
  6543. mboxq = lpfc_mbox_get(phba);
  6544. /* If no more mailbox command waiting for post, we're done */
  6545. if (!mboxq) {
  6546. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6547. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6548. return MBX_SUCCESS;
  6549. }
  6550. phba->sli.mbox_active = mboxq;
  6551. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6552. /* Check device readiness for posting mailbox command */
  6553. rc = lpfc_mbox_dev_check(phba);
  6554. if (unlikely(rc))
  6555. /* Driver clean routine will clean up pending mailbox */
  6556. goto out_not_finished;
  6557. /* Prepare the mbox command to be posted */
  6558. mqe = &mboxq->u.mqe;
  6559. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  6560. /* Start timer for the mbox_tmo and log some mailbox post messages */
  6561. mod_timer(&psli->mbox_tmo, (jiffies +
  6562. (HZ * lpfc_mbox_tmo_val(phba, mboxq))));
  6563. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  6564. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  6565. "x%x x%x\n",
  6566. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  6567. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6568. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6569. phba->pport->port_state, psli->sli_flag);
  6570. if (mbx_cmnd != MBX_HEARTBEAT) {
  6571. if (mboxq->vport) {
  6572. lpfc_debugfs_disc_trc(mboxq->vport,
  6573. LPFC_DISC_TRC_MBOX_VPORT,
  6574. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  6575. mbx_cmnd, mqe->un.mb_words[0],
  6576. mqe->un.mb_words[1]);
  6577. } else {
  6578. lpfc_debugfs_disc_trc(phba->pport,
  6579. LPFC_DISC_TRC_MBOX,
  6580. "MBOX Send: cmd:x%x mb:x%x x%x",
  6581. mbx_cmnd, mqe->un.mb_words[0],
  6582. mqe->un.mb_words[1]);
  6583. }
  6584. }
  6585. psli->slistat.mbox_cmd++;
  6586. /* Post the mailbox command to the port */
  6587. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  6588. if (rc != MBX_SUCCESS) {
  6589. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  6590. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  6591. "cannot issue Data: x%x x%x\n",
  6592. mboxq->vport ? mboxq->vport->vpi : 0,
  6593. mboxq->u.mb.mbxCommand,
  6594. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  6595. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  6596. psli->sli_flag, MBX_NOWAIT);
  6597. goto out_not_finished;
  6598. }
  6599. return rc;
  6600. out_not_finished:
  6601. spin_lock_irqsave(&phba->hbalock, iflags);
  6602. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6603. __lpfc_mbox_cmpl_put(phba, mboxq);
  6604. /* Release the token */
  6605. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6606. phba->sli.mbox_active = NULL;
  6607. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6608. return MBX_NOT_FINISHED;
  6609. }
  6610. /**
  6611. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  6612. * @phba: Pointer to HBA context object.
  6613. * @pmbox: Pointer to mailbox object.
  6614. * @flag: Flag indicating how the mailbox need to be processed.
  6615. *
  6616. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  6617. * the API jump table function pointer from the lpfc_hba struct.
  6618. *
  6619. * Return codes the caller owns the mailbox command after the return of the
  6620. * function.
  6621. **/
  6622. int
  6623. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  6624. {
  6625. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  6626. }
  6627. /**
  6628. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  6629. * @phba: The hba struct for which this call is being executed.
  6630. * @dev_grp: The HBA PCI-Device group number.
  6631. *
  6632. * This routine sets up the mbox interface API function jump table in @phba
  6633. * struct.
  6634. * Returns: 0 - success, -ENODEV - failure.
  6635. **/
  6636. int
  6637. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  6638. {
  6639. switch (dev_grp) {
  6640. case LPFC_PCI_DEV_LP:
  6641. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  6642. phba->lpfc_sli_handle_slow_ring_event =
  6643. lpfc_sli_handle_slow_ring_event_s3;
  6644. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  6645. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  6646. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  6647. break;
  6648. case LPFC_PCI_DEV_OC:
  6649. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  6650. phba->lpfc_sli_handle_slow_ring_event =
  6651. lpfc_sli_handle_slow_ring_event_s4;
  6652. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  6653. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  6654. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  6655. break;
  6656. default:
  6657. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6658. "1420 Invalid HBA PCI-device group: 0x%x\n",
  6659. dev_grp);
  6660. return -ENODEV;
  6661. break;
  6662. }
  6663. return 0;
  6664. }
  6665. /**
  6666. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  6667. * @phba: Pointer to HBA context object.
  6668. * @pring: Pointer to driver SLI ring object.
  6669. * @piocb: Pointer to address of newly added command iocb.
  6670. *
  6671. * This function is called with hbalock held to add a command
  6672. * iocb to the txq when SLI layer cannot submit the command iocb
  6673. * to the ring.
  6674. **/
  6675. void
  6676. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6677. struct lpfc_iocbq *piocb)
  6678. {
  6679. /* Insert the caller's iocb in the txq tail for later processing. */
  6680. list_add_tail(&piocb->list, &pring->txq);
  6681. pring->txq_cnt++;
  6682. }
  6683. /**
  6684. * lpfc_sli_next_iocb - Get the next iocb in the txq
  6685. * @phba: Pointer to HBA context object.
  6686. * @pring: Pointer to driver SLI ring object.
  6687. * @piocb: Pointer to address of newly added command iocb.
  6688. *
  6689. * This function is called with hbalock held before a new
  6690. * iocb is submitted to the firmware. This function checks
  6691. * txq to flush the iocbs in txq to Firmware before
  6692. * submitting new iocbs to the Firmware.
  6693. * If there are iocbs in the txq which need to be submitted
  6694. * to firmware, lpfc_sli_next_iocb returns the first element
  6695. * of the txq after dequeuing it from txq.
  6696. * If there is no iocb in the txq then the function will return
  6697. * *piocb and *piocb is set to NULL. Caller needs to check
  6698. * *piocb to find if there are more commands in the txq.
  6699. **/
  6700. static struct lpfc_iocbq *
  6701. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6702. struct lpfc_iocbq **piocb)
  6703. {
  6704. struct lpfc_iocbq * nextiocb;
  6705. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  6706. if (!nextiocb) {
  6707. nextiocb = *piocb;
  6708. *piocb = NULL;
  6709. }
  6710. return nextiocb;
  6711. }
  6712. /**
  6713. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  6714. * @phba: Pointer to HBA context object.
  6715. * @ring_number: SLI ring number to issue iocb on.
  6716. * @piocb: Pointer to command iocb.
  6717. * @flag: Flag indicating if this command can be put into txq.
  6718. *
  6719. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  6720. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  6721. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  6722. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  6723. * this function allows only iocbs for posting buffers. This function finds
  6724. * next available slot in the command ring and posts the command to the
  6725. * available slot and writes the port attention register to request HBA start
  6726. * processing new iocb. If there is no slot available in the ring and
  6727. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  6728. * the function returns IOCB_BUSY.
  6729. *
  6730. * This function is called with hbalock held. The function will return success
  6731. * after it successfully submit the iocb to firmware or after adding to the
  6732. * txq.
  6733. **/
  6734. static int
  6735. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  6736. struct lpfc_iocbq *piocb, uint32_t flag)
  6737. {
  6738. struct lpfc_iocbq *nextiocb;
  6739. IOCB_t *iocb;
  6740. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  6741. if (piocb->iocb_cmpl && (!piocb->vport) &&
  6742. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  6743. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  6744. lpfc_printf_log(phba, KERN_ERR,
  6745. LOG_SLI | LOG_VPORT,
  6746. "1807 IOCB x%x failed. No vport\n",
  6747. piocb->iocb.ulpCommand);
  6748. dump_stack();
  6749. return IOCB_ERROR;
  6750. }
  6751. /* If the PCI channel is in offline state, do not post iocbs. */
  6752. if (unlikely(pci_channel_offline(phba->pcidev)))
  6753. return IOCB_ERROR;
  6754. /* If HBA has a deferred error attention, fail the iocb. */
  6755. if (unlikely(phba->hba_flag & DEFER_ERATT))
  6756. return IOCB_ERROR;
  6757. /*
  6758. * We should never get an IOCB if we are in a < LINK_DOWN state
  6759. */
  6760. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  6761. return IOCB_ERROR;
  6762. /*
  6763. * Check to see if we are blocking IOCB processing because of a
  6764. * outstanding event.
  6765. */
  6766. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  6767. goto iocb_busy;
  6768. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  6769. /*
  6770. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  6771. * can be issued if the link is not up.
  6772. */
  6773. switch (piocb->iocb.ulpCommand) {
  6774. case CMD_GEN_REQUEST64_CR:
  6775. case CMD_GEN_REQUEST64_CX:
  6776. if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
  6777. (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
  6778. FC_RCTL_DD_UNSOL_CMD) ||
  6779. (piocb->iocb.un.genreq64.w5.hcsw.Type !=
  6780. MENLO_TRANSPORT_TYPE))
  6781. goto iocb_busy;
  6782. break;
  6783. case CMD_QUE_RING_BUF_CN:
  6784. case CMD_QUE_RING_BUF64_CN:
  6785. /*
  6786. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  6787. * completion, iocb_cmpl MUST be 0.
  6788. */
  6789. if (piocb->iocb_cmpl)
  6790. piocb->iocb_cmpl = NULL;
  6791. /*FALLTHROUGH*/
  6792. case CMD_CREATE_XRI_CR:
  6793. case CMD_CLOSE_XRI_CN:
  6794. case CMD_CLOSE_XRI_CX:
  6795. break;
  6796. default:
  6797. goto iocb_busy;
  6798. }
  6799. /*
  6800. * For FCP commands, we must be in a state where we can process link
  6801. * attention events.
  6802. */
  6803. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  6804. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  6805. goto iocb_busy;
  6806. }
  6807. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  6808. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  6809. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  6810. if (iocb)
  6811. lpfc_sli_update_ring(phba, pring);
  6812. else
  6813. lpfc_sli_update_full_ring(phba, pring);
  6814. if (!piocb)
  6815. return IOCB_SUCCESS;
  6816. goto out_busy;
  6817. iocb_busy:
  6818. pring->stats.iocb_cmd_delay++;
  6819. out_busy:
  6820. if (!(flag & SLI_IOCB_RET_IOCB)) {
  6821. __lpfc_sli_ringtx_put(phba, pring, piocb);
  6822. return IOCB_SUCCESS;
  6823. }
  6824. return IOCB_BUSY;
  6825. }
  6826. /**
  6827. * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
  6828. * @phba: Pointer to HBA context object.
  6829. * @piocb: Pointer to command iocb.
  6830. * @sglq: Pointer to the scatter gather queue object.
  6831. *
  6832. * This routine converts the bpl or bde that is in the IOCB
  6833. * to a sgl list for the sli4 hardware. The physical address
  6834. * of the bpl/bde is converted back to a virtual address.
  6835. * If the IOCB contains a BPL then the list of BDE's is
  6836. * converted to sli4_sge's. If the IOCB contains a single
  6837. * BDE then it is converted to a single sli_sge.
  6838. * The IOCB is still in cpu endianess so the contents of
  6839. * the bpl can be used without byte swapping.
  6840. *
  6841. * Returns valid XRI = Success, NO_XRI = Failure.
  6842. **/
  6843. static uint16_t
  6844. lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  6845. struct lpfc_sglq *sglq)
  6846. {
  6847. uint16_t xritag = NO_XRI;
  6848. struct ulp_bde64 *bpl = NULL;
  6849. struct ulp_bde64 bde;
  6850. struct sli4_sge *sgl = NULL;
  6851. struct lpfc_dmabuf *dmabuf;
  6852. IOCB_t *icmd;
  6853. int numBdes = 0;
  6854. int i = 0;
  6855. uint32_t offset = 0; /* accumulated offset in the sg request list */
  6856. int inbound = 0; /* number of sg reply entries inbound from firmware */
  6857. if (!piocbq || !sglq)
  6858. return xritag;
  6859. sgl = (struct sli4_sge *)sglq->sgl;
  6860. icmd = &piocbq->iocb;
  6861. if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
  6862. return sglq->sli4_xritag;
  6863. if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  6864. numBdes = icmd->un.genreq64.bdl.bdeSize /
  6865. sizeof(struct ulp_bde64);
  6866. /* The addrHigh and addrLow fields within the IOCB
  6867. * have not been byteswapped yet so there is no
  6868. * need to swap them back.
  6869. */
  6870. if (piocbq->context3)
  6871. dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
  6872. else
  6873. return xritag;
  6874. bpl = (struct ulp_bde64 *)dmabuf->virt;
  6875. if (!bpl)
  6876. return xritag;
  6877. for (i = 0; i < numBdes; i++) {
  6878. /* Should already be byte swapped. */
  6879. sgl->addr_hi = bpl->addrHigh;
  6880. sgl->addr_lo = bpl->addrLow;
  6881. sgl->word2 = le32_to_cpu(sgl->word2);
  6882. if ((i+1) == numBdes)
  6883. bf_set(lpfc_sli4_sge_last, sgl, 1);
  6884. else
  6885. bf_set(lpfc_sli4_sge_last, sgl, 0);
  6886. /* swap the size field back to the cpu so we
  6887. * can assign it to the sgl.
  6888. */
  6889. bde.tus.w = le32_to_cpu(bpl->tus.w);
  6890. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  6891. /* The offsets in the sgl need to be accumulated
  6892. * separately for the request and reply lists.
  6893. * The request is always first, the reply follows.
  6894. */
  6895. if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
  6896. /* add up the reply sg entries */
  6897. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  6898. inbound++;
  6899. /* first inbound? reset the offset */
  6900. if (inbound == 1)
  6901. offset = 0;
  6902. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  6903. bf_set(lpfc_sli4_sge_type, sgl,
  6904. LPFC_SGE_TYPE_DATA);
  6905. offset += bde.tus.f.bdeSize;
  6906. }
  6907. sgl->word2 = cpu_to_le32(sgl->word2);
  6908. bpl++;
  6909. sgl++;
  6910. }
  6911. } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
  6912. /* The addrHigh and addrLow fields of the BDE have not
  6913. * been byteswapped yet so they need to be swapped
  6914. * before putting them in the sgl.
  6915. */
  6916. sgl->addr_hi =
  6917. cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
  6918. sgl->addr_lo =
  6919. cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
  6920. sgl->word2 = le32_to_cpu(sgl->word2);
  6921. bf_set(lpfc_sli4_sge_last, sgl, 1);
  6922. sgl->word2 = cpu_to_le32(sgl->word2);
  6923. sgl->sge_len =
  6924. cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
  6925. }
  6926. return sglq->sli4_xritag;
  6927. }
  6928. /**
  6929. * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
  6930. * @phba: Pointer to HBA context object.
  6931. *
  6932. * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
  6933. * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
  6934. * held.
  6935. *
  6936. * Return: index into SLI4 fast-path FCP queue index.
  6937. **/
  6938. static uint32_t
  6939. lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba)
  6940. {
  6941. ++phba->fcp_qidx;
  6942. if (phba->fcp_qidx >= phba->cfg_fcp_wq_count)
  6943. phba->fcp_qidx = 0;
  6944. return phba->fcp_qidx;
  6945. }
  6946. /**
  6947. * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
  6948. * @phba: Pointer to HBA context object.
  6949. * @piocb: Pointer to command iocb.
  6950. * @wqe: Pointer to the work queue entry.
  6951. *
  6952. * This routine converts the iocb command to its Work Queue Entry
  6953. * equivalent. The wqe pointer should not have any fields set when
  6954. * this routine is called because it will memcpy over them.
  6955. * This routine does not set the CQ_ID or the WQEC bits in the
  6956. * wqe.
  6957. *
  6958. * Returns: 0 = Success, IOCB_ERROR = Failure.
  6959. **/
  6960. static int
  6961. lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
  6962. union lpfc_wqe *wqe)
  6963. {
  6964. uint32_t xmit_len = 0, total_len = 0;
  6965. uint8_t ct = 0;
  6966. uint32_t fip;
  6967. uint32_t abort_tag;
  6968. uint8_t command_type = ELS_COMMAND_NON_FIP;
  6969. uint8_t cmnd;
  6970. uint16_t xritag;
  6971. uint16_t abrt_iotag;
  6972. struct lpfc_iocbq *abrtiocbq;
  6973. struct ulp_bde64 *bpl = NULL;
  6974. uint32_t els_id = LPFC_ELS_ID_DEFAULT;
  6975. int numBdes, i;
  6976. struct ulp_bde64 bde;
  6977. struct lpfc_nodelist *ndlp;
  6978. uint32_t *pcmd;
  6979. uint32_t if_type;
  6980. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  6981. /* The fcp commands will set command type */
  6982. if (iocbq->iocb_flag & LPFC_IO_FCP)
  6983. command_type = FCP_COMMAND;
  6984. else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
  6985. command_type = ELS_COMMAND_FIP;
  6986. else
  6987. command_type = ELS_COMMAND_NON_FIP;
  6988. /* Some of the fields are in the right position already */
  6989. memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
  6990. abort_tag = (uint32_t) iocbq->iotag;
  6991. xritag = iocbq->sli4_xritag;
  6992. wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
  6993. /* words0-2 bpl convert bde */
  6994. if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
  6995. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  6996. sizeof(struct ulp_bde64);
  6997. bpl = (struct ulp_bde64 *)
  6998. ((struct lpfc_dmabuf *)iocbq->context3)->virt;
  6999. if (!bpl)
  7000. return IOCB_ERROR;
  7001. /* Should already be byte swapped. */
  7002. wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
  7003. wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
  7004. /* swap the size field back to the cpu so we
  7005. * can assign it to the sgl.
  7006. */
  7007. wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
  7008. xmit_len = wqe->generic.bde.tus.f.bdeSize;
  7009. total_len = 0;
  7010. for (i = 0; i < numBdes; i++) {
  7011. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7012. total_len += bde.tus.f.bdeSize;
  7013. }
  7014. } else
  7015. xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
  7016. iocbq->iocb.ulpIoTag = iocbq->iotag;
  7017. cmnd = iocbq->iocb.ulpCommand;
  7018. switch (iocbq->iocb.ulpCommand) {
  7019. case CMD_ELS_REQUEST64_CR:
  7020. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7021. if (!iocbq->iocb.ulpLe) {
  7022. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7023. "2007 Only Limited Edition cmd Format"
  7024. " supported 0x%x\n",
  7025. iocbq->iocb.ulpCommand);
  7026. return IOCB_ERROR;
  7027. }
  7028. wqe->els_req.payload_len = xmit_len;
  7029. /* Els_reguest64 has a TMO */
  7030. bf_set(wqe_tmo, &wqe->els_req.wqe_com,
  7031. iocbq->iocb.ulpTimeout);
  7032. /* Need a VF for word 4 set the vf bit*/
  7033. bf_set(els_req64_vf, &wqe->els_req, 0);
  7034. /* And a VFID for word 12 */
  7035. bf_set(els_req64_vfid, &wqe->els_req, 0);
  7036. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7037. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7038. iocbq->iocb.ulpContext);
  7039. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  7040. bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
  7041. /* CCP CCPE PV PRI in word10 were set in the memcpy */
  7042. if (command_type == ELS_COMMAND_FIP)
  7043. els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
  7044. >> LPFC_FIP_ELS_ID_SHIFT);
  7045. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7046. iocbq->context2)->virt);
  7047. if_type = bf_get(lpfc_sli_intf_if_type,
  7048. &phba->sli4_hba.sli_intf);
  7049. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  7050. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  7051. *pcmd == ELS_CMD_SCR ||
  7052. *pcmd == ELS_CMD_FDISC ||
  7053. *pcmd == ELS_CMD_PLOGI)) {
  7054. bf_set(els_req64_sp, &wqe->els_req, 1);
  7055. bf_set(els_req64_sid, &wqe->els_req,
  7056. iocbq->vport->fc_myDID);
  7057. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7058. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7059. phba->vpi_ids[phba->pport->vpi]);
  7060. } else if (pcmd && iocbq->context1) {
  7061. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  7062. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7063. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7064. }
  7065. }
  7066. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  7067. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7068. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  7069. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  7070. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  7071. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  7072. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7073. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  7074. break;
  7075. case CMD_XMIT_SEQUENCE64_CX:
  7076. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
  7077. iocbq->iocb.un.ulpWord[3]);
  7078. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
  7079. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7080. /* The entire sequence is transmitted for this IOCB */
  7081. xmit_len = total_len;
  7082. cmnd = CMD_XMIT_SEQUENCE64_CR;
  7083. if (phba->link_flag & LS_LOOPBACK_MODE)
  7084. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  7085. case CMD_XMIT_SEQUENCE64_CR:
  7086. /* word3 iocb=io_tag32 wqe=reserved */
  7087. wqe->xmit_sequence.rsvd3 = 0;
  7088. /* word4 relative_offset memcpy */
  7089. /* word5 r_ctl/df_ctl memcpy */
  7090. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  7091. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  7092. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  7093. LPFC_WQE_IOD_WRITE);
  7094. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  7095. LPFC_WQE_LENLOC_WORD12);
  7096. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  7097. wqe->xmit_sequence.xmit_len = xmit_len;
  7098. command_type = OTHER_COMMAND;
  7099. break;
  7100. case CMD_XMIT_BCAST64_CN:
  7101. /* word3 iocb=iotag32 wqe=seq_payload_len */
  7102. wqe->xmit_bcast64.seq_payload_len = xmit_len;
  7103. /* word4 iocb=rsvd wqe=rsvd */
  7104. /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
  7105. /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
  7106. bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
  7107. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7108. bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
  7109. bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
  7110. bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
  7111. LPFC_WQE_LENLOC_WORD3);
  7112. bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
  7113. break;
  7114. case CMD_FCP_IWRITE64_CR:
  7115. command_type = FCP_COMMAND_DATA_OUT;
  7116. /* word3 iocb=iotag wqe=payload_offset_len */
  7117. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7118. wqe->fcp_iwrite.payload_offset_len =
  7119. xmit_len + sizeof(struct fcp_rsp);
  7120. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7121. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7122. bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
  7123. iocbq->iocb.ulpFCP2Rcvy);
  7124. bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
  7125. /* Always open the exchange */
  7126. bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0);
  7127. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
  7128. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  7129. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
  7130. LPFC_WQE_LENLOC_WORD4);
  7131. bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0);
  7132. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
  7133. break;
  7134. case CMD_FCP_IREAD64_CR:
  7135. /* word3 iocb=iotag wqe=payload_offset_len */
  7136. /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
  7137. wqe->fcp_iread.payload_offset_len =
  7138. xmit_len + sizeof(struct fcp_rsp);
  7139. /* word4 iocb=parameter wqe=total_xfer_length memcpy */
  7140. /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
  7141. bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
  7142. iocbq->iocb.ulpFCP2Rcvy);
  7143. bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
  7144. /* Always open the exchange */
  7145. bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0);
  7146. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
  7147. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  7148. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
  7149. LPFC_WQE_LENLOC_WORD4);
  7150. bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0);
  7151. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
  7152. break;
  7153. case CMD_FCP_ICMND64_CR:
  7154. /* word3 iocb=IO_TAG wqe=reserved */
  7155. wqe->fcp_icmd.rsrvd3 = 0;
  7156. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  7157. /* Always open the exchange */
  7158. bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0);
  7159. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
  7160. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
  7161. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  7162. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
  7163. LPFC_WQE_LENLOC_NONE);
  7164. bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0);
  7165. break;
  7166. case CMD_GEN_REQUEST64_CR:
  7167. /* For this command calculate the xmit length of the
  7168. * request bde.
  7169. */
  7170. xmit_len = 0;
  7171. numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
  7172. sizeof(struct ulp_bde64);
  7173. for (i = 0; i < numBdes; i++) {
  7174. bde.tus.w = le32_to_cpu(bpl[i].tus.w);
  7175. if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
  7176. break;
  7177. xmit_len += bde.tus.f.bdeSize;
  7178. }
  7179. /* word3 iocb=IO_TAG wqe=request_payload_len */
  7180. wqe->gen_req.request_payload_len = xmit_len;
  7181. /* word4 iocb=parameter wqe=relative_offset memcpy */
  7182. /* word5 [rctl, type, df_ctl, la] copied in memcpy */
  7183. /* word6 context tag copied in memcpy */
  7184. if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
  7185. ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
  7186. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7187. "2015 Invalid CT %x command 0x%x\n",
  7188. ct, iocbq->iocb.ulpCommand);
  7189. return IOCB_ERROR;
  7190. }
  7191. bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
  7192. bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
  7193. bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
  7194. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  7195. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  7196. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  7197. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  7198. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  7199. command_type = OTHER_COMMAND;
  7200. break;
  7201. case CMD_XMIT_ELS_RSP64_CX:
  7202. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7203. /* words0-2 BDE memcpy */
  7204. /* word3 iocb=iotag32 wqe=response_payload_len */
  7205. wqe->xmit_els_rsp.response_payload_len = xmit_len;
  7206. /* word4 iocb=did wge=rsvd. */
  7207. wqe->xmit_els_rsp.rsvd4 = 0;
  7208. /* word5 iocb=rsvd wge=did */
  7209. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  7210. iocbq->iocb.un.elsreq64.remoteID);
  7211. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
  7212. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7213. bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
  7214. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7215. iocbq->iocb.unsli3.rcvsli3.ox_id);
  7216. if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
  7217. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  7218. phba->vpi_ids[iocbq->vport->vpi]);
  7219. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  7220. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  7221. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  7222. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  7223. LPFC_WQE_LENLOC_WORD3);
  7224. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  7225. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  7226. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  7227. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  7228. iocbq->context2)->virt);
  7229. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7230. bf_set(els_req64_sp, &wqe->els_req, 1);
  7231. bf_set(els_req64_sid, &wqe->els_req,
  7232. iocbq->vport->fc_myDID);
  7233. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  7234. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  7235. phba->vpi_ids[phba->pport->vpi]);
  7236. }
  7237. command_type = OTHER_COMMAND;
  7238. break;
  7239. case CMD_CLOSE_XRI_CN:
  7240. case CMD_ABORT_XRI_CN:
  7241. case CMD_ABORT_XRI_CX:
  7242. /* words 0-2 memcpy should be 0 rserved */
  7243. /* port will send abts */
  7244. abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
  7245. if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
  7246. abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
  7247. fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
  7248. } else
  7249. fip = 0;
  7250. if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
  7251. /*
  7252. * The link is down, or the command was ELS_FIP
  7253. * so the fw does not need to send abts
  7254. * on the wire.
  7255. */
  7256. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  7257. else
  7258. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  7259. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  7260. /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
  7261. wqe->abort_cmd.rsrvd5 = 0;
  7262. bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
  7263. ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
  7264. abort_tag = iocbq->iocb.un.acxri.abortIoTag;
  7265. /*
  7266. * The abort handler will send us CMD_ABORT_XRI_CN or
  7267. * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
  7268. */
  7269. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  7270. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  7271. bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
  7272. LPFC_WQE_LENLOC_NONE);
  7273. cmnd = CMD_ABORT_XRI_CX;
  7274. command_type = OTHER_COMMAND;
  7275. xritag = 0;
  7276. break;
  7277. case CMD_XMIT_BLS_RSP64_CX:
  7278. ndlp = (struct lpfc_nodelist *)iocbq->context1;
  7279. /* As BLS ABTS RSP WQE is very different from other WQEs,
  7280. * we re-construct this WQE here based on information in
  7281. * iocbq from scratch.
  7282. */
  7283. memset(wqe, 0, sizeof(union lpfc_wqe));
  7284. /* OX_ID is invariable to who sent ABTS to CT exchange */
  7285. bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
  7286. bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
  7287. if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
  7288. LPFC_ABTS_UNSOL_INT) {
  7289. /* ABTS sent by initiator to CT exchange, the
  7290. * RX_ID field will be filled with the newly
  7291. * allocated responder XRI.
  7292. */
  7293. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7294. iocbq->sli4_xritag);
  7295. } else {
  7296. /* ABTS sent by responder to CT exchange, the
  7297. * RX_ID field will be filled with the responder
  7298. * RX_ID from ABTS.
  7299. */
  7300. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  7301. bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
  7302. }
  7303. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  7304. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  7305. /* Use CT=VPI */
  7306. bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
  7307. ndlp->nlp_DID);
  7308. bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
  7309. iocbq->iocb.ulpContext);
  7310. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  7311. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  7312. phba->vpi_ids[phba->pport->vpi]);
  7313. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  7314. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  7315. LPFC_WQE_LENLOC_NONE);
  7316. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  7317. command_type = OTHER_COMMAND;
  7318. if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
  7319. bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
  7320. bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
  7321. bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
  7322. bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
  7323. bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
  7324. bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
  7325. }
  7326. break;
  7327. case CMD_XRI_ABORTED_CX:
  7328. case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
  7329. case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
  7330. case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
  7331. case CMD_FCP_TRSP64_CX: /* Target mode rcv */
  7332. case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
  7333. default:
  7334. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7335. "2014 Invalid command 0x%x\n",
  7336. iocbq->iocb.ulpCommand);
  7337. return IOCB_ERROR;
  7338. break;
  7339. }
  7340. bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
  7341. bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
  7342. wqe->generic.wqe_com.abort_tag = abort_tag;
  7343. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  7344. bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
  7345. bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
  7346. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  7347. return 0;
  7348. }
  7349. /**
  7350. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  7351. * @phba: Pointer to HBA context object.
  7352. * @ring_number: SLI ring number to issue iocb on.
  7353. * @piocb: Pointer to command iocb.
  7354. * @flag: Flag indicating if this command can be put into txq.
  7355. *
  7356. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  7357. * an iocb command to an HBA with SLI-4 interface spec.
  7358. *
  7359. * This function is called with hbalock held. The function will return success
  7360. * after it successfully submit the iocb to firmware or after adding to the
  7361. * txq.
  7362. **/
  7363. static int
  7364. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  7365. struct lpfc_iocbq *piocb, uint32_t flag)
  7366. {
  7367. struct lpfc_sglq *sglq;
  7368. union lpfc_wqe wqe;
  7369. struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number];
  7370. if (piocb->sli4_xritag == NO_XRI) {
  7371. if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  7372. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  7373. sglq = NULL;
  7374. else {
  7375. if (pring->txq_cnt) {
  7376. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7377. __lpfc_sli_ringtx_put(phba,
  7378. pring, piocb);
  7379. return IOCB_SUCCESS;
  7380. } else {
  7381. return IOCB_BUSY;
  7382. }
  7383. } else {
  7384. sglq = __lpfc_sli_get_sglq(phba, piocb);
  7385. if (!sglq) {
  7386. if (!(flag & SLI_IOCB_RET_IOCB)) {
  7387. __lpfc_sli_ringtx_put(phba,
  7388. pring,
  7389. piocb);
  7390. return IOCB_SUCCESS;
  7391. } else
  7392. return IOCB_BUSY;
  7393. }
  7394. }
  7395. }
  7396. } else if (piocb->iocb_flag & LPFC_IO_FCP) {
  7397. /* These IO's already have an XRI and a mapped sgl. */
  7398. sglq = NULL;
  7399. } else {
  7400. /*
  7401. * This is a continuation of a commandi,(CX) so this
  7402. * sglq is on the active list
  7403. */
  7404. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag);
  7405. if (!sglq)
  7406. return IOCB_ERROR;
  7407. }
  7408. if (sglq) {
  7409. piocb->sli4_lxritag = sglq->sli4_lxritag;
  7410. piocb->sli4_xritag = sglq->sli4_xritag;
  7411. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
  7412. return IOCB_ERROR;
  7413. }
  7414. if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
  7415. return IOCB_ERROR;
  7416. if ((piocb->iocb_flag & LPFC_IO_FCP) ||
  7417. (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
  7418. /*
  7419. * For FCP command IOCB, get a new WQ index to distribute
  7420. * WQE across the WQsr. On the other hand, for abort IOCB,
  7421. * it carries the same WQ index to the original command
  7422. * IOCB.
  7423. */
  7424. if (piocb->iocb_flag & LPFC_IO_FCP)
  7425. piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
  7426. if (unlikely(!phba->sli4_hba.fcp_wq))
  7427. return IOCB_ERROR;
  7428. if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
  7429. &wqe))
  7430. return IOCB_ERROR;
  7431. } else {
  7432. if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  7433. return IOCB_ERROR;
  7434. }
  7435. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  7436. return 0;
  7437. }
  7438. /**
  7439. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  7440. *
  7441. * This routine wraps the actual lockless version for issusing IOCB function
  7442. * pointer from the lpfc_hba struct.
  7443. *
  7444. * Return codes:
  7445. * IOCB_ERROR - Error
  7446. * IOCB_SUCCESS - Success
  7447. * IOCB_BUSY - Busy
  7448. **/
  7449. int
  7450. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7451. struct lpfc_iocbq *piocb, uint32_t flag)
  7452. {
  7453. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7454. }
  7455. /**
  7456. * lpfc_sli_api_table_setup - Set up sli api function jump table
  7457. * @phba: The hba struct for which this call is being executed.
  7458. * @dev_grp: The HBA PCI-Device group number.
  7459. *
  7460. * This routine sets up the SLI interface API function jump table in @phba
  7461. * struct.
  7462. * Returns: 0 - success, -ENODEV - failure.
  7463. **/
  7464. int
  7465. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  7466. {
  7467. switch (dev_grp) {
  7468. case LPFC_PCI_DEV_LP:
  7469. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  7470. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  7471. break;
  7472. case LPFC_PCI_DEV_OC:
  7473. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  7474. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  7475. break;
  7476. default:
  7477. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7478. "1419 Invalid HBA PCI-device group: 0x%x\n",
  7479. dev_grp);
  7480. return -ENODEV;
  7481. break;
  7482. }
  7483. phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
  7484. return 0;
  7485. }
  7486. /**
  7487. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  7488. * @phba: Pointer to HBA context object.
  7489. * @pring: Pointer to driver SLI ring object.
  7490. * @piocb: Pointer to command iocb.
  7491. * @flag: Flag indicating if this command can be put into txq.
  7492. *
  7493. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  7494. * function. This function gets the hbalock and calls
  7495. * __lpfc_sli_issue_iocb function and will return the error returned
  7496. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  7497. * functions which do not hold hbalock.
  7498. **/
  7499. int
  7500. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  7501. struct lpfc_iocbq *piocb, uint32_t flag)
  7502. {
  7503. unsigned long iflags;
  7504. int rc;
  7505. spin_lock_irqsave(&phba->hbalock, iflags);
  7506. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  7507. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7508. return rc;
  7509. }
  7510. /**
  7511. * lpfc_extra_ring_setup - Extra ring setup function
  7512. * @phba: Pointer to HBA context object.
  7513. *
  7514. * This function is called while driver attaches with the
  7515. * HBA to setup the extra ring. The extra ring is used
  7516. * only when driver needs to support target mode functionality
  7517. * or IP over FC functionalities.
  7518. *
  7519. * This function is called with no lock held.
  7520. **/
  7521. static int
  7522. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  7523. {
  7524. struct lpfc_sli *psli;
  7525. struct lpfc_sli_ring *pring;
  7526. psli = &phba->sli;
  7527. /* Adjust cmd/rsp ring iocb entries more evenly */
  7528. /* Take some away from the FCP ring */
  7529. pring = &psli->ring[psli->fcp_ring];
  7530. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7531. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7532. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7533. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7534. /* and give them to the extra ring */
  7535. pring = &psli->ring[psli->extra_ring];
  7536. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7537. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7538. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7539. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7540. /* Setup default profile for this ring */
  7541. pring->iotag_max = 4096;
  7542. pring->num_mask = 1;
  7543. pring->prt[0].profile = 0; /* Mask 0 */
  7544. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  7545. pring->prt[0].type = phba->cfg_multi_ring_type;
  7546. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  7547. return 0;
  7548. }
  7549. /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS.
  7550. * @vport: pointer to virtual port object.
  7551. * @ndlp: nodelist pointer for the impacted rport.
  7552. *
  7553. * The driver calls this routine in response to a XRI ABORT CQE
  7554. * event from the port. In this event, the driver is required to
  7555. * recover its login to the rport even though its login may be valid
  7556. * from the driver's perspective. The failed ABTS notice from the
  7557. * port indicates the rport is not responding.
  7558. */
  7559. static void
  7560. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  7561. struct lpfc_nodelist *ndlp)
  7562. {
  7563. struct Scsi_Host *shost;
  7564. struct lpfc_hba *phba;
  7565. unsigned long flags = 0;
  7566. shost = lpfc_shost_from_vport(vport);
  7567. phba = vport->phba;
  7568. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  7569. lpfc_printf_log(phba, KERN_INFO,
  7570. LOG_SLI, "3093 No rport recovery needed. "
  7571. "rport in state 0x%x\n",
  7572. ndlp->nlp_state);
  7573. return;
  7574. }
  7575. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7576. "3094 Start rport recovery on shost id 0x%x "
  7577. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  7578. "flags 0x%x\n",
  7579. shost->host_no, ndlp->nlp_DID,
  7580. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  7581. ndlp->nlp_flag);
  7582. /*
  7583. * The rport is not responding. Don't attempt ADISC recovery.
  7584. * Remove the FCP-2 flag to force a PLOGI.
  7585. */
  7586. spin_lock_irqsave(shost->host_lock, flags);
  7587. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  7588. spin_unlock_irqrestore(shost->host_lock, flags);
  7589. lpfc_disc_state_machine(vport, ndlp, NULL,
  7590. NLP_EVT_DEVICE_RECOVERY);
  7591. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  7592. spin_lock_irqsave(shost->host_lock, flags);
  7593. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  7594. spin_unlock_irqrestore(shost->host_lock, flags);
  7595. lpfc_disc_start(vport);
  7596. }
  7597. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  7598. * @phba: Pointer to HBA context object.
  7599. * @iocbq: Pointer to iocb object.
  7600. *
  7601. * The async_event handler calls this routine when it receives
  7602. * an ASYNC_STATUS_CN event from the port. The port generates
  7603. * this event when an Abort Sequence request to an rport fails
  7604. * twice in succession. The abort could be originated by the
  7605. * driver or by the port. The ABTS could have been for an ELS
  7606. * or FCP IO. The port only generates this event when an ABTS
  7607. * fails to complete after one retry.
  7608. */
  7609. static void
  7610. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  7611. struct lpfc_iocbq *iocbq)
  7612. {
  7613. struct lpfc_nodelist *ndlp = NULL;
  7614. uint16_t rpi = 0, vpi = 0;
  7615. struct lpfc_vport *vport = NULL;
  7616. /* The rpi in the ulpContext is vport-sensitive. */
  7617. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  7618. rpi = iocbq->iocb.ulpContext;
  7619. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7620. "3092 Port generated ABTS async event "
  7621. "on vpi %d rpi %d status 0x%x\n",
  7622. vpi, rpi, iocbq->iocb.ulpStatus);
  7623. vport = lpfc_find_vport_by_vpid(phba, vpi);
  7624. if (!vport)
  7625. goto err_exit;
  7626. ndlp = lpfc_findnode_rpi(vport, rpi);
  7627. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  7628. goto err_exit;
  7629. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  7630. lpfc_sli_abts_recover_port(vport, ndlp);
  7631. return;
  7632. err_exit:
  7633. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7634. "3095 Event Context not found, no "
  7635. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  7636. iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
  7637. vpi, rpi);
  7638. }
  7639. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  7640. * @phba: pointer to HBA context object.
  7641. * @ndlp: nodelist pointer for the impacted rport.
  7642. * @axri: pointer to the wcqe containing the failed exchange.
  7643. *
  7644. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  7645. * port. The port generates this event when an abort exchange request to an
  7646. * rport fails twice in succession with no reply. The abort could be originated
  7647. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  7648. */
  7649. void
  7650. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  7651. struct lpfc_nodelist *ndlp,
  7652. struct sli4_wcqe_xri_aborted *axri)
  7653. {
  7654. struct lpfc_vport *vport;
  7655. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  7656. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  7657. "3115 Node Context not found, driver "
  7658. "ignoring abts err event\n");
  7659. return;
  7660. }
  7661. vport = ndlp->vport;
  7662. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  7663. "3116 Port generated FCP XRI ABORT event on "
  7664. "vpi %d rpi %d xri x%x status 0x%x\n",
  7665. ndlp->vport->vpi, ndlp->nlp_rpi,
  7666. bf_get(lpfc_wcqe_xa_xri, axri),
  7667. bf_get(lpfc_wcqe_xa_status, axri));
  7668. if (bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT)
  7669. lpfc_sli_abts_recover_port(vport, ndlp);
  7670. }
  7671. /**
  7672. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  7673. * @phba: Pointer to HBA context object.
  7674. * @pring: Pointer to driver SLI ring object.
  7675. * @iocbq: Pointer to iocb object.
  7676. *
  7677. * This function is called by the slow ring event handler
  7678. * function when there is an ASYNC event iocb in the ring.
  7679. * This function is called with no lock held.
  7680. * Currently this function handles only temperature related
  7681. * ASYNC events. The function decodes the temperature sensor
  7682. * event message and posts events for the management applications.
  7683. **/
  7684. static void
  7685. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  7686. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  7687. {
  7688. IOCB_t *icmd;
  7689. uint16_t evt_code;
  7690. struct temp_event temp_event_data;
  7691. struct Scsi_Host *shost;
  7692. uint32_t *iocb_w;
  7693. icmd = &iocbq->iocb;
  7694. evt_code = icmd->un.asyncstat.evt_code;
  7695. switch (evt_code) {
  7696. case ASYNC_TEMP_WARN:
  7697. case ASYNC_TEMP_SAFE:
  7698. temp_event_data.data = (uint32_t) icmd->ulpContext;
  7699. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  7700. if (evt_code == ASYNC_TEMP_WARN) {
  7701. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  7702. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7703. "0347 Adapter is very hot, please take "
  7704. "corrective action. temperature : %d Celsius\n",
  7705. (uint32_t) icmd->ulpContext);
  7706. } else {
  7707. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  7708. lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
  7709. "0340 Adapter temperature is OK now. "
  7710. "temperature : %d Celsius\n",
  7711. (uint32_t) icmd->ulpContext);
  7712. }
  7713. /* Send temperature change event to applications */
  7714. shost = lpfc_shost_from_vport(phba->pport);
  7715. fc_host_post_vendor_event(shost, fc_get_event_number(),
  7716. sizeof(temp_event_data), (char *) &temp_event_data,
  7717. LPFC_NL_VENDOR_ID);
  7718. break;
  7719. case ASYNC_STATUS_CN:
  7720. lpfc_sli_abts_err_handler(phba, iocbq);
  7721. break;
  7722. default:
  7723. iocb_w = (uint32_t *) icmd;
  7724. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7725. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  7726. " evt_code 0x%x\n"
  7727. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  7728. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  7729. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  7730. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  7731. pring->ringno, icmd->un.asyncstat.evt_code,
  7732. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  7733. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  7734. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  7735. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  7736. break;
  7737. }
  7738. }
  7739. /**
  7740. * lpfc_sli_setup - SLI ring setup function
  7741. * @phba: Pointer to HBA context object.
  7742. *
  7743. * lpfc_sli_setup sets up rings of the SLI interface with
  7744. * number of iocbs per ring and iotags. This function is
  7745. * called while driver attach to the HBA and before the
  7746. * interrupts are enabled. So there is no need for locking.
  7747. *
  7748. * This function always returns 0.
  7749. **/
  7750. int
  7751. lpfc_sli_setup(struct lpfc_hba *phba)
  7752. {
  7753. int i, totiocbsize = 0;
  7754. struct lpfc_sli *psli = &phba->sli;
  7755. struct lpfc_sli_ring *pring;
  7756. psli->num_rings = MAX_CONFIGURED_RINGS;
  7757. psli->sli_flag = 0;
  7758. psli->fcp_ring = LPFC_FCP_RING;
  7759. psli->next_ring = LPFC_FCP_NEXT_RING;
  7760. psli->extra_ring = LPFC_EXTRA_RING;
  7761. psli->iocbq_lookup = NULL;
  7762. psli->iocbq_lookup_len = 0;
  7763. psli->last_iotag = 0;
  7764. for (i = 0; i < psli->num_rings; i++) {
  7765. pring = &psli->ring[i];
  7766. switch (i) {
  7767. case LPFC_FCP_RING: /* ring 0 - FCP */
  7768. /* numCiocb and numRiocb are used in config_port */
  7769. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  7770. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  7771. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  7772. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  7773. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  7774. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  7775. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7776. SLI3_IOCB_CMD_SIZE :
  7777. SLI2_IOCB_CMD_SIZE;
  7778. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7779. SLI3_IOCB_RSP_SIZE :
  7780. SLI2_IOCB_RSP_SIZE;
  7781. pring->iotag_ctr = 0;
  7782. pring->iotag_max =
  7783. (phba->cfg_hba_queue_depth * 2);
  7784. pring->fast_iotag = pring->iotag_max;
  7785. pring->num_mask = 0;
  7786. break;
  7787. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  7788. /* numCiocb and numRiocb are used in config_port */
  7789. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  7790. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  7791. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7792. SLI3_IOCB_CMD_SIZE :
  7793. SLI2_IOCB_CMD_SIZE;
  7794. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7795. SLI3_IOCB_RSP_SIZE :
  7796. SLI2_IOCB_RSP_SIZE;
  7797. pring->iotag_max = phba->cfg_hba_queue_depth;
  7798. pring->num_mask = 0;
  7799. break;
  7800. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  7801. /* numCiocb and numRiocb are used in config_port */
  7802. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  7803. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  7804. pring->sizeCiocb = (phba->sli_rev == 3) ?
  7805. SLI3_IOCB_CMD_SIZE :
  7806. SLI2_IOCB_CMD_SIZE;
  7807. pring->sizeRiocb = (phba->sli_rev == 3) ?
  7808. SLI3_IOCB_RSP_SIZE :
  7809. SLI2_IOCB_RSP_SIZE;
  7810. pring->fast_iotag = 0;
  7811. pring->iotag_ctr = 0;
  7812. pring->iotag_max = 4096;
  7813. pring->lpfc_sli_rcv_async_status =
  7814. lpfc_sli_async_event_handler;
  7815. pring->num_mask = LPFC_MAX_RING_MASK;
  7816. pring->prt[0].profile = 0; /* Mask 0 */
  7817. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  7818. pring->prt[0].type = FC_TYPE_ELS;
  7819. pring->prt[0].lpfc_sli_rcv_unsol_event =
  7820. lpfc_els_unsol_event;
  7821. pring->prt[1].profile = 0; /* Mask 1 */
  7822. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  7823. pring->prt[1].type = FC_TYPE_ELS;
  7824. pring->prt[1].lpfc_sli_rcv_unsol_event =
  7825. lpfc_els_unsol_event;
  7826. pring->prt[2].profile = 0; /* Mask 2 */
  7827. /* NameServer Inquiry */
  7828. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  7829. /* NameServer */
  7830. pring->prt[2].type = FC_TYPE_CT;
  7831. pring->prt[2].lpfc_sli_rcv_unsol_event =
  7832. lpfc_ct_unsol_event;
  7833. pring->prt[3].profile = 0; /* Mask 3 */
  7834. /* NameServer response */
  7835. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  7836. /* NameServer */
  7837. pring->prt[3].type = FC_TYPE_CT;
  7838. pring->prt[3].lpfc_sli_rcv_unsol_event =
  7839. lpfc_ct_unsol_event;
  7840. /* abort unsolicited sequence */
  7841. pring->prt[4].profile = 0; /* Mask 4 */
  7842. pring->prt[4].rctl = FC_RCTL_BA_ABTS;
  7843. pring->prt[4].type = FC_TYPE_BLS;
  7844. pring->prt[4].lpfc_sli_rcv_unsol_event =
  7845. lpfc_sli4_ct_abort_unsol_event;
  7846. break;
  7847. }
  7848. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  7849. (pring->numRiocb * pring->sizeRiocb);
  7850. }
  7851. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  7852. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  7853. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  7854. "SLI2 SLIM Data: x%x x%lx\n",
  7855. phba->brd_no, totiocbsize,
  7856. (unsigned long) MAX_SLIM_IOCB_SIZE);
  7857. }
  7858. if (phba->cfg_multi_ring_support == 2)
  7859. lpfc_extra_ring_setup(phba);
  7860. return 0;
  7861. }
  7862. /**
  7863. * lpfc_sli_queue_setup - Queue initialization function
  7864. * @phba: Pointer to HBA context object.
  7865. *
  7866. * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
  7867. * ring. This function also initializes ring indices of each ring.
  7868. * This function is called during the initialization of the SLI
  7869. * interface of an HBA.
  7870. * This function is called with no lock held and always returns
  7871. * 1.
  7872. **/
  7873. int
  7874. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  7875. {
  7876. struct lpfc_sli *psli;
  7877. struct lpfc_sli_ring *pring;
  7878. int i;
  7879. psli = &phba->sli;
  7880. spin_lock_irq(&phba->hbalock);
  7881. INIT_LIST_HEAD(&psli->mboxq);
  7882. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  7883. /* Initialize list headers for txq and txcmplq as double linked lists */
  7884. for (i = 0; i < psli->num_rings; i++) {
  7885. pring = &psli->ring[i];
  7886. pring->ringno = i;
  7887. pring->next_cmdidx = 0;
  7888. pring->local_getidx = 0;
  7889. pring->cmdidx = 0;
  7890. INIT_LIST_HEAD(&pring->txq);
  7891. INIT_LIST_HEAD(&pring->txcmplq);
  7892. INIT_LIST_HEAD(&pring->iocb_continueq);
  7893. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  7894. INIT_LIST_HEAD(&pring->postbufq);
  7895. }
  7896. spin_unlock_irq(&phba->hbalock);
  7897. return 1;
  7898. }
  7899. /**
  7900. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  7901. * @phba: Pointer to HBA context object.
  7902. *
  7903. * This routine flushes the mailbox command subsystem. It will unconditionally
  7904. * flush all the mailbox commands in the three possible stages in the mailbox
  7905. * command sub-system: pending mailbox command queue; the outstanding mailbox
  7906. * command; and completed mailbox command queue. It is caller's responsibility
  7907. * to make sure that the driver is in the proper state to flush the mailbox
  7908. * command sub-system. Namely, the posting of mailbox commands into the
  7909. * pending mailbox command queue from the various clients must be stopped;
  7910. * either the HBA is in a state that it will never works on the outstanding
  7911. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  7912. * mailbox command has been completed.
  7913. **/
  7914. static void
  7915. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  7916. {
  7917. LIST_HEAD(completions);
  7918. struct lpfc_sli *psli = &phba->sli;
  7919. LPFC_MBOXQ_t *pmb;
  7920. unsigned long iflag;
  7921. /* Flush all the mailbox commands in the mbox system */
  7922. spin_lock_irqsave(&phba->hbalock, iflag);
  7923. /* The pending mailbox command queue */
  7924. list_splice_init(&phba->sli.mboxq, &completions);
  7925. /* The outstanding active mailbox command */
  7926. if (psli->mbox_active) {
  7927. list_add_tail(&psli->mbox_active->list, &completions);
  7928. psli->mbox_active = NULL;
  7929. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7930. }
  7931. /* The completed mailbox command queue */
  7932. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  7933. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7934. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  7935. while (!list_empty(&completions)) {
  7936. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  7937. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  7938. if (pmb->mbox_cmpl)
  7939. pmb->mbox_cmpl(phba, pmb);
  7940. }
  7941. }
  7942. /**
  7943. * lpfc_sli_host_down - Vport cleanup function
  7944. * @vport: Pointer to virtual port object.
  7945. *
  7946. * lpfc_sli_host_down is called to clean up the resources
  7947. * associated with a vport before destroying virtual
  7948. * port data structures.
  7949. * This function does following operations:
  7950. * - Free discovery resources associated with this virtual
  7951. * port.
  7952. * - Free iocbs associated with this virtual port in
  7953. * the txq.
  7954. * - Send abort for all iocb commands associated with this
  7955. * vport in txcmplq.
  7956. *
  7957. * This function is called with no lock held and always returns 1.
  7958. **/
  7959. int
  7960. lpfc_sli_host_down(struct lpfc_vport *vport)
  7961. {
  7962. LIST_HEAD(completions);
  7963. struct lpfc_hba *phba = vport->phba;
  7964. struct lpfc_sli *psli = &phba->sli;
  7965. struct lpfc_sli_ring *pring;
  7966. struct lpfc_iocbq *iocb, *next_iocb;
  7967. int i;
  7968. unsigned long flags = 0;
  7969. uint16_t prev_pring_flag;
  7970. lpfc_cleanup_discovery_resources(vport);
  7971. spin_lock_irqsave(&phba->hbalock, flags);
  7972. for (i = 0; i < psli->num_rings; i++) {
  7973. pring = &psli->ring[i];
  7974. prev_pring_flag = pring->flag;
  7975. /* Only slow rings */
  7976. if (pring->ringno == LPFC_ELS_RING) {
  7977. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  7978. /* Set the lpfc data pending flag */
  7979. set_bit(LPFC_DATA_READY, &phba->data_flags);
  7980. }
  7981. /*
  7982. * Error everything on the txq since these iocbs have not been
  7983. * given to the FW yet.
  7984. */
  7985. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  7986. if (iocb->vport != vport)
  7987. continue;
  7988. list_move_tail(&iocb->list, &completions);
  7989. pring->txq_cnt--;
  7990. }
  7991. /* Next issue ABTS for everything on the txcmplq */
  7992. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  7993. list) {
  7994. if (iocb->vport != vport)
  7995. continue;
  7996. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  7997. }
  7998. pring->flag = prev_pring_flag;
  7999. }
  8000. spin_unlock_irqrestore(&phba->hbalock, flags);
  8001. /* Cancel all the IOCBs from the completions list */
  8002. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8003. IOERR_SLI_DOWN);
  8004. return 1;
  8005. }
  8006. /**
  8007. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  8008. * @phba: Pointer to HBA context object.
  8009. *
  8010. * This function cleans up all iocb, buffers, mailbox commands
  8011. * while shutting down the HBA. This function is called with no
  8012. * lock held and always returns 1.
  8013. * This function does the following to cleanup driver resources:
  8014. * - Free discovery resources for each virtual port
  8015. * - Cleanup any pending fabric iocbs
  8016. * - Iterate through the iocb txq and free each entry
  8017. * in the list.
  8018. * - Free up any buffer posted to the HBA
  8019. * - Free mailbox commands in the mailbox queue.
  8020. **/
  8021. int
  8022. lpfc_sli_hba_down(struct lpfc_hba *phba)
  8023. {
  8024. LIST_HEAD(completions);
  8025. struct lpfc_sli *psli = &phba->sli;
  8026. struct lpfc_sli_ring *pring;
  8027. struct lpfc_dmabuf *buf_ptr;
  8028. unsigned long flags = 0;
  8029. int i;
  8030. /* Shutdown the mailbox command sub-system */
  8031. lpfc_sli_mbox_sys_shutdown(phba);
  8032. lpfc_hba_down_prep(phba);
  8033. lpfc_fabric_abort_hba(phba);
  8034. spin_lock_irqsave(&phba->hbalock, flags);
  8035. for (i = 0; i < psli->num_rings; i++) {
  8036. pring = &psli->ring[i];
  8037. /* Only slow rings */
  8038. if (pring->ringno == LPFC_ELS_RING) {
  8039. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  8040. /* Set the lpfc data pending flag */
  8041. set_bit(LPFC_DATA_READY, &phba->data_flags);
  8042. }
  8043. /*
  8044. * Error everything on the txq since these iocbs have not been
  8045. * given to the FW yet.
  8046. */
  8047. list_splice_init(&pring->txq, &completions);
  8048. pring->txq_cnt = 0;
  8049. }
  8050. spin_unlock_irqrestore(&phba->hbalock, flags);
  8051. /* Cancel all the IOCBs from the completions list */
  8052. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8053. IOERR_SLI_DOWN);
  8054. spin_lock_irqsave(&phba->hbalock, flags);
  8055. list_splice_init(&phba->elsbuf, &completions);
  8056. phba->elsbuf_cnt = 0;
  8057. phba->elsbuf_prev_cnt = 0;
  8058. spin_unlock_irqrestore(&phba->hbalock, flags);
  8059. while (!list_empty(&completions)) {
  8060. list_remove_head(&completions, buf_ptr,
  8061. struct lpfc_dmabuf, list);
  8062. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  8063. kfree(buf_ptr);
  8064. }
  8065. /* Return any active mbox cmds */
  8066. del_timer_sync(&psli->mbox_tmo);
  8067. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  8068. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8069. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  8070. return 1;
  8071. }
  8072. /**
  8073. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  8074. * @srcp: Source memory pointer.
  8075. * @destp: Destination memory pointer.
  8076. * @cnt: Number of words required to be copied.
  8077. *
  8078. * This function is used for copying data between driver memory
  8079. * and the SLI memory. This function also changes the endianness
  8080. * of each word if native endianness is different from SLI
  8081. * endianness. This function can be called with or without
  8082. * lock.
  8083. **/
  8084. void
  8085. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8086. {
  8087. uint32_t *src = srcp;
  8088. uint32_t *dest = destp;
  8089. uint32_t ldata;
  8090. int i;
  8091. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  8092. ldata = *src;
  8093. ldata = le32_to_cpu(ldata);
  8094. *dest = ldata;
  8095. src++;
  8096. dest++;
  8097. }
  8098. }
  8099. /**
  8100. * lpfc_sli_bemem_bcopy - SLI memory copy function
  8101. * @srcp: Source memory pointer.
  8102. * @destp: Destination memory pointer.
  8103. * @cnt: Number of words required to be copied.
  8104. *
  8105. * This function is used for copying data between a data structure
  8106. * with big endian representation to local endianness.
  8107. * This function can be called with or without lock.
  8108. **/
  8109. void
  8110. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  8111. {
  8112. uint32_t *src = srcp;
  8113. uint32_t *dest = destp;
  8114. uint32_t ldata;
  8115. int i;
  8116. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  8117. ldata = *src;
  8118. ldata = be32_to_cpu(ldata);
  8119. *dest = ldata;
  8120. src++;
  8121. dest++;
  8122. }
  8123. }
  8124. /**
  8125. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  8126. * @phba: Pointer to HBA context object.
  8127. * @pring: Pointer to driver SLI ring object.
  8128. * @mp: Pointer to driver buffer object.
  8129. *
  8130. * This function is called with no lock held.
  8131. * It always return zero after adding the buffer to the postbufq
  8132. * buffer list.
  8133. **/
  8134. int
  8135. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8136. struct lpfc_dmabuf *mp)
  8137. {
  8138. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  8139. later */
  8140. spin_lock_irq(&phba->hbalock);
  8141. list_add_tail(&mp->list, &pring->postbufq);
  8142. pring->postbufq_cnt++;
  8143. spin_unlock_irq(&phba->hbalock);
  8144. return 0;
  8145. }
  8146. /**
  8147. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  8148. * @phba: Pointer to HBA context object.
  8149. *
  8150. * When HBQ is enabled, buffers are searched based on tags. This function
  8151. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  8152. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  8153. * does not conflict with tags of buffer posted for unsolicited events.
  8154. * The function returns the allocated tag. The function is called with
  8155. * no locks held.
  8156. **/
  8157. uint32_t
  8158. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  8159. {
  8160. spin_lock_irq(&phba->hbalock);
  8161. phba->buffer_tag_count++;
  8162. /*
  8163. * Always set the QUE_BUFTAG_BIT to distiguish between
  8164. * a tag assigned by HBQ.
  8165. */
  8166. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  8167. spin_unlock_irq(&phba->hbalock);
  8168. return phba->buffer_tag_count;
  8169. }
  8170. /**
  8171. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  8172. * @phba: Pointer to HBA context object.
  8173. * @pring: Pointer to driver SLI ring object.
  8174. * @tag: Buffer tag.
  8175. *
  8176. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  8177. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  8178. * iocb is posted to the response ring with the tag of the buffer.
  8179. * This function searches the pring->postbufq list using the tag
  8180. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  8181. * iocb. If the buffer is found then lpfc_dmabuf object of the
  8182. * buffer is returned to the caller else NULL is returned.
  8183. * This function is called with no lock held.
  8184. **/
  8185. struct lpfc_dmabuf *
  8186. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8187. uint32_t tag)
  8188. {
  8189. struct lpfc_dmabuf *mp, *next_mp;
  8190. struct list_head *slp = &pring->postbufq;
  8191. /* Search postbufq, from the beginning, looking for a match on tag */
  8192. spin_lock_irq(&phba->hbalock);
  8193. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8194. if (mp->buffer_tag == tag) {
  8195. list_del_init(&mp->list);
  8196. pring->postbufq_cnt--;
  8197. spin_unlock_irq(&phba->hbalock);
  8198. return mp;
  8199. }
  8200. }
  8201. spin_unlock_irq(&phba->hbalock);
  8202. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8203. "0402 Cannot find virtual addr for buffer tag on "
  8204. "ring %d Data x%lx x%p x%p x%x\n",
  8205. pring->ringno, (unsigned long) tag,
  8206. slp->next, slp->prev, pring->postbufq_cnt);
  8207. return NULL;
  8208. }
  8209. /**
  8210. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  8211. * @phba: Pointer to HBA context object.
  8212. * @pring: Pointer to driver SLI ring object.
  8213. * @phys: DMA address of the buffer.
  8214. *
  8215. * This function searches the buffer list using the dma_address
  8216. * of unsolicited event to find the driver's lpfc_dmabuf object
  8217. * corresponding to the dma_address. The function returns the
  8218. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  8219. * This function is called by the ct and els unsolicited event
  8220. * handlers to get the buffer associated with the unsolicited
  8221. * event.
  8222. *
  8223. * This function is called with no lock held.
  8224. **/
  8225. struct lpfc_dmabuf *
  8226. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8227. dma_addr_t phys)
  8228. {
  8229. struct lpfc_dmabuf *mp, *next_mp;
  8230. struct list_head *slp = &pring->postbufq;
  8231. /* Search postbufq, from the beginning, looking for a match on phys */
  8232. spin_lock_irq(&phba->hbalock);
  8233. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  8234. if (mp->phys == phys) {
  8235. list_del_init(&mp->list);
  8236. pring->postbufq_cnt--;
  8237. spin_unlock_irq(&phba->hbalock);
  8238. return mp;
  8239. }
  8240. }
  8241. spin_unlock_irq(&phba->hbalock);
  8242. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8243. "0410 Cannot find virtual addr for mapped buf on "
  8244. "ring %d Data x%llx x%p x%p x%x\n",
  8245. pring->ringno, (unsigned long long)phys,
  8246. slp->next, slp->prev, pring->postbufq_cnt);
  8247. return NULL;
  8248. }
  8249. /**
  8250. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  8251. * @phba: Pointer to HBA context object.
  8252. * @cmdiocb: Pointer to driver command iocb object.
  8253. * @rspiocb: Pointer to driver response iocb object.
  8254. *
  8255. * This function is the completion handler for the abort iocbs for
  8256. * ELS commands. This function is called from the ELS ring event
  8257. * handler with no lock held. This function frees memory resources
  8258. * associated with the abort iocb.
  8259. **/
  8260. static void
  8261. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8262. struct lpfc_iocbq *rspiocb)
  8263. {
  8264. IOCB_t *irsp = &rspiocb->iocb;
  8265. uint16_t abort_iotag, abort_context;
  8266. struct lpfc_iocbq *abort_iocb = NULL;
  8267. if (irsp->ulpStatus) {
  8268. /*
  8269. * Assume that the port already completed and returned, or
  8270. * will return the iocb. Just Log the message.
  8271. */
  8272. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  8273. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  8274. spin_lock_irq(&phba->hbalock);
  8275. if (phba->sli_rev < LPFC_SLI_REV4) {
  8276. if (abort_iotag != 0 &&
  8277. abort_iotag <= phba->sli.last_iotag)
  8278. abort_iocb =
  8279. phba->sli.iocbq_lookup[abort_iotag];
  8280. } else
  8281. /* For sli4 the abort_tag is the XRI,
  8282. * so the abort routine puts the iotag of the iocb
  8283. * being aborted in the context field of the abort
  8284. * IOCB.
  8285. */
  8286. abort_iocb = phba->sli.iocbq_lookup[abort_context];
  8287. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  8288. "0327 Cannot abort els iocb %p "
  8289. "with tag %x context %x, abort status %x, "
  8290. "abort code %x\n",
  8291. abort_iocb, abort_iotag, abort_context,
  8292. irsp->ulpStatus, irsp->un.ulpWord[4]);
  8293. spin_unlock_irq(&phba->hbalock);
  8294. }
  8295. lpfc_sli_release_iocbq(phba, cmdiocb);
  8296. return;
  8297. }
  8298. /**
  8299. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  8300. * @phba: Pointer to HBA context object.
  8301. * @cmdiocb: Pointer to driver command iocb object.
  8302. * @rspiocb: Pointer to driver response iocb object.
  8303. *
  8304. * The function is called from SLI ring event handler with no
  8305. * lock held. This function is the completion handler for ELS commands
  8306. * which are aborted. The function frees memory resources used for
  8307. * the aborted ELS commands.
  8308. **/
  8309. static void
  8310. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8311. struct lpfc_iocbq *rspiocb)
  8312. {
  8313. IOCB_t *irsp = &rspiocb->iocb;
  8314. /* ELS cmd tag <ulpIoTag> completes */
  8315. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8316. "0139 Ignoring ELS cmd tag x%x completion Data: "
  8317. "x%x x%x x%x\n",
  8318. irsp->ulpIoTag, irsp->ulpStatus,
  8319. irsp->un.ulpWord[4], irsp->ulpTimeout);
  8320. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  8321. lpfc_ct_free_iocb(phba, cmdiocb);
  8322. else
  8323. lpfc_els_free_iocb(phba, cmdiocb);
  8324. return;
  8325. }
  8326. /**
  8327. * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
  8328. * @phba: Pointer to HBA context object.
  8329. * @pring: Pointer to driver SLI ring object.
  8330. * @cmdiocb: Pointer to driver command iocb object.
  8331. *
  8332. * This function issues an abort iocb for the provided command iocb down to
  8333. * the port. Other than the case the outstanding command iocb is an abort
  8334. * request, this function issues abort out unconditionally. This function is
  8335. * called with hbalock held. The function returns 0 when it fails due to
  8336. * memory allocation failure or when the command iocb is an abort request.
  8337. **/
  8338. static int
  8339. lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8340. struct lpfc_iocbq *cmdiocb)
  8341. {
  8342. struct lpfc_vport *vport = cmdiocb->vport;
  8343. struct lpfc_iocbq *abtsiocbp;
  8344. IOCB_t *icmd = NULL;
  8345. IOCB_t *iabt = NULL;
  8346. int retval;
  8347. /*
  8348. * There are certain command types we don't want to abort. And we
  8349. * don't want to abort commands that are already in the process of
  8350. * being aborted.
  8351. */
  8352. icmd = &cmdiocb->iocb;
  8353. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8354. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8355. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8356. return 0;
  8357. /* issue ABTS for this IOCB based on iotag */
  8358. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  8359. if (abtsiocbp == NULL)
  8360. return 0;
  8361. /* This signals the response to set the correct status
  8362. * before calling the completion handler
  8363. */
  8364. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  8365. iabt = &abtsiocbp->iocb;
  8366. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  8367. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  8368. if (phba->sli_rev == LPFC_SLI_REV4) {
  8369. iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
  8370. iabt->un.acxri.abortContextTag = cmdiocb->iotag;
  8371. }
  8372. else
  8373. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  8374. iabt->ulpLe = 1;
  8375. iabt->ulpClass = icmd->ulpClass;
  8376. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8377. abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
  8378. if (cmdiocb->iocb_flag & LPFC_IO_FCP)
  8379. abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
  8380. if (phba->link_state >= LPFC_LINK_UP)
  8381. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  8382. else
  8383. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  8384. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  8385. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  8386. "0339 Abort xri x%x, original iotag x%x, "
  8387. "abort cmd iotag x%x\n",
  8388. iabt->un.acxri.abortIoTag,
  8389. iabt->un.acxri.abortContextTag,
  8390. abtsiocbp->iotag);
  8391. retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0);
  8392. if (retval)
  8393. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  8394. /*
  8395. * Caller to this routine should check for IOCB_ERROR
  8396. * and handle it properly. This routine no longer removes
  8397. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8398. */
  8399. return retval;
  8400. }
  8401. /**
  8402. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  8403. * @phba: Pointer to HBA context object.
  8404. * @pring: Pointer to driver SLI ring object.
  8405. * @cmdiocb: Pointer to driver command iocb object.
  8406. *
  8407. * This function issues an abort iocb for the provided command iocb. In case
  8408. * of unloading, the abort iocb will not be issued to commands on the ELS
  8409. * ring. Instead, the callback function shall be changed to those commands
  8410. * so that nothing happens when them finishes. This function is called with
  8411. * hbalock held. The function returns 0 when the command iocb is an abort
  8412. * request.
  8413. **/
  8414. int
  8415. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  8416. struct lpfc_iocbq *cmdiocb)
  8417. {
  8418. struct lpfc_vport *vport = cmdiocb->vport;
  8419. int retval = IOCB_ERROR;
  8420. IOCB_t *icmd = NULL;
  8421. /*
  8422. * There are certain command types we don't want to abort. And we
  8423. * don't want to abort commands that are already in the process of
  8424. * being aborted.
  8425. */
  8426. icmd = &cmdiocb->iocb;
  8427. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  8428. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  8429. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  8430. return 0;
  8431. /*
  8432. * If we're unloading, don't abort iocb on the ELS ring, but change
  8433. * the callback so that nothing happens when it finishes.
  8434. */
  8435. if ((vport->load_flag & FC_UNLOADING) &&
  8436. (pring->ringno == LPFC_ELS_RING)) {
  8437. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  8438. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  8439. else
  8440. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  8441. goto abort_iotag_exit;
  8442. }
  8443. /* Now, we try to issue the abort to the cmdiocb out */
  8444. retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
  8445. abort_iotag_exit:
  8446. /*
  8447. * Caller to this routine should check for IOCB_ERROR
  8448. * and handle it properly. This routine no longer removes
  8449. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  8450. */
  8451. return retval;
  8452. }
  8453. /**
  8454. * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
  8455. * @phba: Pointer to HBA context object.
  8456. * @pring: Pointer to driver SLI ring object.
  8457. *
  8458. * This function aborts all iocbs in the given ring and frees all the iocb
  8459. * objects in txq. This function issues abort iocbs unconditionally for all
  8460. * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
  8461. * to complete before the return of this function. The caller is not required
  8462. * to hold any locks.
  8463. **/
  8464. static void
  8465. lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  8466. {
  8467. LIST_HEAD(completions);
  8468. struct lpfc_iocbq *iocb, *next_iocb;
  8469. if (pring->ringno == LPFC_ELS_RING)
  8470. lpfc_fabric_abort_hba(phba);
  8471. spin_lock_irq(&phba->hbalock);
  8472. /* Take off all the iocbs on txq for cancelling */
  8473. list_splice_init(&pring->txq, &completions);
  8474. pring->txq_cnt = 0;
  8475. /* Next issue ABTS for everything on the txcmplq */
  8476. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  8477. lpfc_sli_abort_iotag_issue(phba, pring, iocb);
  8478. spin_unlock_irq(&phba->hbalock);
  8479. /* Cancel all the IOCBs from the completions list */
  8480. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  8481. IOERR_SLI_ABORTED);
  8482. }
  8483. /**
  8484. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  8485. * @phba: pointer to lpfc HBA data structure.
  8486. *
  8487. * This routine will abort all pending and outstanding iocbs to an HBA.
  8488. **/
  8489. void
  8490. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  8491. {
  8492. struct lpfc_sli *psli = &phba->sli;
  8493. struct lpfc_sli_ring *pring;
  8494. int i;
  8495. for (i = 0; i < psli->num_rings; i++) {
  8496. pring = &psli->ring[i];
  8497. lpfc_sli_iocb_ring_abort(phba, pring);
  8498. }
  8499. }
  8500. /**
  8501. * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
  8502. * @iocbq: Pointer to driver iocb object.
  8503. * @vport: Pointer to driver virtual port object.
  8504. * @tgt_id: SCSI ID of the target.
  8505. * @lun_id: LUN ID of the scsi device.
  8506. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  8507. *
  8508. * This function acts as an iocb filter for functions which abort or count
  8509. * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
  8510. * 0 if the filtering criteria is met for the given iocb and will return
  8511. * 1 if the filtering criteria is not met.
  8512. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  8513. * given iocb is for the SCSI device specified by vport, tgt_id and
  8514. * lun_id parameter.
  8515. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  8516. * given iocb is for the SCSI target specified by vport and tgt_id
  8517. * parameters.
  8518. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  8519. * given iocb is for the SCSI host associated with the given vport.
  8520. * This function is called with no locks held.
  8521. **/
  8522. static int
  8523. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  8524. uint16_t tgt_id, uint64_t lun_id,
  8525. lpfc_ctx_cmd ctx_cmd)
  8526. {
  8527. struct lpfc_scsi_buf *lpfc_cmd;
  8528. int rc = 1;
  8529. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  8530. return rc;
  8531. if (iocbq->vport != vport)
  8532. return rc;
  8533. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  8534. if (lpfc_cmd->pCmd == NULL)
  8535. return rc;
  8536. switch (ctx_cmd) {
  8537. case LPFC_CTX_LUN:
  8538. if ((lpfc_cmd->rdata->pnode) &&
  8539. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  8540. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  8541. rc = 0;
  8542. break;
  8543. case LPFC_CTX_TGT:
  8544. if ((lpfc_cmd->rdata->pnode) &&
  8545. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  8546. rc = 0;
  8547. break;
  8548. case LPFC_CTX_HOST:
  8549. rc = 0;
  8550. break;
  8551. default:
  8552. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  8553. __func__, ctx_cmd);
  8554. break;
  8555. }
  8556. return rc;
  8557. }
  8558. /**
  8559. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  8560. * @vport: Pointer to virtual port.
  8561. * @tgt_id: SCSI ID of the target.
  8562. * @lun_id: LUN ID of the scsi device.
  8563. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8564. *
  8565. * This function returns number of FCP commands pending for the vport.
  8566. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  8567. * commands pending on the vport associated with SCSI device specified
  8568. * by tgt_id and lun_id parameters.
  8569. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  8570. * commands pending on the vport associated with SCSI target specified
  8571. * by tgt_id parameter.
  8572. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  8573. * commands pending on the vport.
  8574. * This function returns the number of iocbs which satisfy the filter.
  8575. * This function is called without any lock held.
  8576. **/
  8577. int
  8578. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  8579. lpfc_ctx_cmd ctx_cmd)
  8580. {
  8581. struct lpfc_hba *phba = vport->phba;
  8582. struct lpfc_iocbq *iocbq;
  8583. int sum, i;
  8584. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  8585. iocbq = phba->sli.iocbq_lookup[i];
  8586. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  8587. ctx_cmd) == 0)
  8588. sum++;
  8589. }
  8590. return sum;
  8591. }
  8592. /**
  8593. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  8594. * @phba: Pointer to HBA context object
  8595. * @cmdiocb: Pointer to command iocb object.
  8596. * @rspiocb: Pointer to response iocb object.
  8597. *
  8598. * This function is called when an aborted FCP iocb completes. This
  8599. * function is called by the ring event handler with no lock held.
  8600. * This function frees the iocb.
  8601. **/
  8602. void
  8603. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  8604. struct lpfc_iocbq *rspiocb)
  8605. {
  8606. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8607. "3096 ABORT_XRI_CN completing on xri x%x "
  8608. "original iotag x%x, abort cmd iotag x%x "
  8609. "status 0x%x, reason 0x%x\n",
  8610. cmdiocb->iocb.un.acxri.abortContextTag,
  8611. cmdiocb->iocb.un.acxri.abortIoTag,
  8612. cmdiocb->iotag, rspiocb->iocb.ulpStatus,
  8613. rspiocb->iocb.un.ulpWord[4]);
  8614. lpfc_sli_release_iocbq(phba, cmdiocb);
  8615. return;
  8616. }
  8617. /**
  8618. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  8619. * @vport: Pointer to virtual port.
  8620. * @pring: Pointer to driver SLI ring object.
  8621. * @tgt_id: SCSI ID of the target.
  8622. * @lun_id: LUN ID of the scsi device.
  8623. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  8624. *
  8625. * This function sends an abort command for every SCSI command
  8626. * associated with the given virtual port pending on the ring
  8627. * filtered by lpfc_sli_validate_fcp_iocb function.
  8628. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  8629. * FCP iocbs associated with lun specified by tgt_id and lun_id
  8630. * parameters
  8631. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  8632. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  8633. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  8634. * FCP iocbs associated with virtual port.
  8635. * This function returns number of iocbs it failed to abort.
  8636. * This function is called with no locks held.
  8637. **/
  8638. int
  8639. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  8640. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  8641. {
  8642. struct lpfc_hba *phba = vport->phba;
  8643. struct lpfc_iocbq *iocbq;
  8644. struct lpfc_iocbq *abtsiocb;
  8645. IOCB_t *cmd = NULL;
  8646. int errcnt = 0, ret_val = 0;
  8647. int i;
  8648. for (i = 1; i <= phba->sli.last_iotag; i++) {
  8649. iocbq = phba->sli.iocbq_lookup[i];
  8650. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  8651. abort_cmd) != 0)
  8652. continue;
  8653. /* issue ABTS for this IOCB based on iotag */
  8654. abtsiocb = lpfc_sli_get_iocbq(phba);
  8655. if (abtsiocb == NULL) {
  8656. errcnt++;
  8657. continue;
  8658. }
  8659. cmd = &iocbq->iocb;
  8660. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  8661. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  8662. if (phba->sli_rev == LPFC_SLI_REV4)
  8663. abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
  8664. else
  8665. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  8666. abtsiocb->iocb.ulpLe = 1;
  8667. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  8668. abtsiocb->vport = phba->pport;
  8669. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  8670. abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
  8671. if (iocbq->iocb_flag & LPFC_IO_FCP)
  8672. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  8673. if (lpfc_is_link_up(phba))
  8674. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  8675. else
  8676. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  8677. /* Setup callback routine and issue the command. */
  8678. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  8679. ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
  8680. abtsiocb, 0);
  8681. if (ret_val == IOCB_ERROR) {
  8682. lpfc_sli_release_iocbq(phba, abtsiocb);
  8683. errcnt++;
  8684. continue;
  8685. }
  8686. }
  8687. return errcnt;
  8688. }
  8689. /**
  8690. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  8691. * @phba: Pointer to HBA context object.
  8692. * @cmdiocbq: Pointer to command iocb.
  8693. * @rspiocbq: Pointer to response iocb.
  8694. *
  8695. * This function is the completion handler for iocbs issued using
  8696. * lpfc_sli_issue_iocb_wait function. This function is called by the
  8697. * ring event handler function without any lock held. This function
  8698. * can be called from both worker thread context and interrupt
  8699. * context. This function also can be called from other thread which
  8700. * cleans up the SLI layer objects.
  8701. * This function copy the contents of the response iocb to the
  8702. * response iocb memory object provided by the caller of
  8703. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  8704. * sleeps for the iocb completion.
  8705. **/
  8706. static void
  8707. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  8708. struct lpfc_iocbq *cmdiocbq,
  8709. struct lpfc_iocbq *rspiocbq)
  8710. {
  8711. wait_queue_head_t *pdone_q;
  8712. unsigned long iflags;
  8713. struct lpfc_scsi_buf *lpfc_cmd;
  8714. spin_lock_irqsave(&phba->hbalock, iflags);
  8715. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  8716. if (cmdiocbq->context2 && rspiocbq)
  8717. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  8718. &rspiocbq->iocb, sizeof(IOCB_t));
  8719. /* Set the exchange busy flag for task management commands */
  8720. if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
  8721. !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
  8722. lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
  8723. cur_iocbq);
  8724. lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
  8725. }
  8726. pdone_q = cmdiocbq->context_un.wait_queue;
  8727. if (pdone_q)
  8728. wake_up(pdone_q);
  8729. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8730. return;
  8731. }
  8732. /**
  8733. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  8734. * @phba: Pointer to HBA context object..
  8735. * @piocbq: Pointer to command iocb.
  8736. * @flag: Flag to test.
  8737. *
  8738. * This routine grabs the hbalock and then test the iocb_flag to
  8739. * see if the passed in flag is set.
  8740. * Returns:
  8741. * 1 if flag is set.
  8742. * 0 if flag is not set.
  8743. **/
  8744. static int
  8745. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  8746. struct lpfc_iocbq *piocbq, uint32_t flag)
  8747. {
  8748. unsigned long iflags;
  8749. int ret;
  8750. spin_lock_irqsave(&phba->hbalock, iflags);
  8751. ret = piocbq->iocb_flag & flag;
  8752. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8753. return ret;
  8754. }
  8755. /**
  8756. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  8757. * @phba: Pointer to HBA context object..
  8758. * @pring: Pointer to sli ring.
  8759. * @piocb: Pointer to command iocb.
  8760. * @prspiocbq: Pointer to response iocb.
  8761. * @timeout: Timeout in number of seconds.
  8762. *
  8763. * This function issues the iocb to firmware and waits for the
  8764. * iocb to complete. If the iocb command is not
  8765. * completed within timeout seconds, it returns IOCB_TIMEDOUT.
  8766. * Caller should not free the iocb resources if this function
  8767. * returns IOCB_TIMEDOUT.
  8768. * The function waits for the iocb completion using an
  8769. * non-interruptible wait.
  8770. * This function will sleep while waiting for iocb completion.
  8771. * So, this function should not be called from any context which
  8772. * does not allow sleeping. Due to the same reason, this function
  8773. * cannot be called with interrupt disabled.
  8774. * This function assumes that the iocb completions occur while
  8775. * this function sleep. So, this function cannot be called from
  8776. * the thread which process iocb completion for this ring.
  8777. * This function clears the iocb_flag of the iocb object before
  8778. * issuing the iocb and the iocb completion handler sets this
  8779. * flag and wakes this thread when the iocb completes.
  8780. * The contents of the response iocb will be copied to prspiocbq
  8781. * by the completion handler when the command completes.
  8782. * This function returns IOCB_SUCCESS when success.
  8783. * This function is called with no lock held.
  8784. **/
  8785. int
  8786. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  8787. uint32_t ring_number,
  8788. struct lpfc_iocbq *piocb,
  8789. struct lpfc_iocbq *prspiocbq,
  8790. uint32_t timeout)
  8791. {
  8792. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  8793. long timeleft, timeout_req = 0;
  8794. int retval = IOCB_SUCCESS;
  8795. uint32_t creg_val;
  8796. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  8797. /*
  8798. * If the caller has provided a response iocbq buffer, then context2
  8799. * is NULL or its an error.
  8800. */
  8801. if (prspiocbq) {
  8802. if (piocb->context2)
  8803. return IOCB_ERROR;
  8804. piocb->context2 = prspiocbq;
  8805. }
  8806. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  8807. piocb->context_un.wait_queue = &done_q;
  8808. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  8809. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  8810. if (lpfc_readl(phba->HCregaddr, &creg_val))
  8811. return IOCB_ERROR;
  8812. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  8813. writel(creg_val, phba->HCregaddr);
  8814. readl(phba->HCregaddr); /* flush */
  8815. }
  8816. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  8817. SLI_IOCB_RET_IOCB);
  8818. if (retval == IOCB_SUCCESS) {
  8819. timeout_req = timeout * HZ;
  8820. timeleft = wait_event_timeout(done_q,
  8821. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  8822. timeout_req);
  8823. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  8824. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8825. "0331 IOCB wake signaled\n");
  8826. } else if (timeleft == 0) {
  8827. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8828. "0338 IOCB wait timeout error - no "
  8829. "wake response Data x%x\n", timeout);
  8830. retval = IOCB_TIMEDOUT;
  8831. } else {
  8832. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  8833. "0330 IOCB wake NOT set, "
  8834. "Data x%x x%lx\n",
  8835. timeout, (timeleft / jiffies));
  8836. retval = IOCB_TIMEDOUT;
  8837. }
  8838. } else if (retval == IOCB_BUSY) {
  8839. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8840. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  8841. phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt);
  8842. return retval;
  8843. } else {
  8844. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  8845. "0332 IOCB wait issue failed, Data x%x\n",
  8846. retval);
  8847. retval = IOCB_ERROR;
  8848. }
  8849. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  8850. if (lpfc_readl(phba->HCregaddr, &creg_val))
  8851. return IOCB_ERROR;
  8852. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  8853. writel(creg_val, phba->HCregaddr);
  8854. readl(phba->HCregaddr); /* flush */
  8855. }
  8856. if (prspiocbq)
  8857. piocb->context2 = NULL;
  8858. piocb->context_un.wait_queue = NULL;
  8859. piocb->iocb_cmpl = NULL;
  8860. return retval;
  8861. }
  8862. /**
  8863. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  8864. * @phba: Pointer to HBA context object.
  8865. * @pmboxq: Pointer to driver mailbox object.
  8866. * @timeout: Timeout in number of seconds.
  8867. *
  8868. * This function issues the mailbox to firmware and waits for the
  8869. * mailbox command to complete. If the mailbox command is not
  8870. * completed within timeout seconds, it returns MBX_TIMEOUT.
  8871. * The function waits for the mailbox completion using an
  8872. * interruptible wait. If the thread is woken up due to a
  8873. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  8874. * should not free the mailbox resources, if this function returns
  8875. * MBX_TIMEOUT.
  8876. * This function will sleep while waiting for mailbox completion.
  8877. * So, this function should not be called from any context which
  8878. * does not allow sleeping. Due to the same reason, this function
  8879. * cannot be called with interrupt disabled.
  8880. * This function assumes that the mailbox completion occurs while
  8881. * this function sleep. So, this function cannot be called from
  8882. * the worker thread which processes mailbox completion.
  8883. * This function is called in the context of HBA management
  8884. * applications.
  8885. * This function returns MBX_SUCCESS when successful.
  8886. * This function is called with no lock held.
  8887. **/
  8888. int
  8889. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  8890. uint32_t timeout)
  8891. {
  8892. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  8893. int retval;
  8894. unsigned long flag;
  8895. /* The caller must leave context1 empty. */
  8896. if (pmboxq->context1)
  8897. return MBX_NOT_FINISHED;
  8898. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  8899. /* setup wake call as IOCB callback */
  8900. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  8901. /* setup context field to pass wait_queue pointer to wake function */
  8902. pmboxq->context1 = &done_q;
  8903. /* now issue the command */
  8904. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  8905. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  8906. wait_event_interruptible_timeout(done_q,
  8907. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  8908. timeout * HZ);
  8909. spin_lock_irqsave(&phba->hbalock, flag);
  8910. pmboxq->context1 = NULL;
  8911. /*
  8912. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  8913. * else do not free the resources.
  8914. */
  8915. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  8916. retval = MBX_SUCCESS;
  8917. lpfc_sli4_swap_str(phba, pmboxq);
  8918. } else {
  8919. retval = MBX_TIMEOUT;
  8920. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  8921. }
  8922. spin_unlock_irqrestore(&phba->hbalock, flag);
  8923. }
  8924. return retval;
  8925. }
  8926. /**
  8927. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  8928. * @phba: Pointer to HBA context.
  8929. *
  8930. * This function is called to shutdown the driver's mailbox sub-system.
  8931. * It first marks the mailbox sub-system is in a block state to prevent
  8932. * the asynchronous mailbox command from issued off the pending mailbox
  8933. * command queue. If the mailbox command sub-system shutdown is due to
  8934. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  8935. * the mailbox sub-system flush routine to forcefully bring down the
  8936. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  8937. * as with offline or HBA function reset), this routine will wait for the
  8938. * outstanding mailbox command to complete before invoking the mailbox
  8939. * sub-system flush routine to gracefully bring down mailbox sub-system.
  8940. **/
  8941. void
  8942. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba)
  8943. {
  8944. struct lpfc_sli *psli = &phba->sli;
  8945. unsigned long timeout;
  8946. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  8947. spin_lock_irq(&phba->hbalock);
  8948. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  8949. spin_unlock_irq(&phba->hbalock);
  8950. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  8951. spin_lock_irq(&phba->hbalock);
  8952. /* Determine how long we might wait for the active mailbox
  8953. * command to be gracefully completed by firmware.
  8954. */
  8955. if (phba->sli.mbox_active)
  8956. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  8957. phba->sli.mbox_active) *
  8958. 1000) + jiffies;
  8959. spin_unlock_irq(&phba->hbalock);
  8960. while (phba->sli.mbox_active) {
  8961. /* Check active mailbox complete status every 2ms */
  8962. msleep(2);
  8963. if (time_after(jiffies, timeout))
  8964. /* Timeout, let the mailbox flush routine to
  8965. * forcefully release active mailbox command
  8966. */
  8967. break;
  8968. }
  8969. }
  8970. lpfc_sli_mbox_sys_flush(phba);
  8971. }
  8972. /**
  8973. * lpfc_sli_eratt_read - read sli-3 error attention events
  8974. * @phba: Pointer to HBA context.
  8975. *
  8976. * This function is called to read the SLI3 device error attention registers
  8977. * for possible error attention events. The caller must hold the hostlock
  8978. * with spin_lock_irq().
  8979. *
  8980. * This function returns 1 when there is Error Attention in the Host Attention
  8981. * Register and returns 0 otherwise.
  8982. **/
  8983. static int
  8984. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  8985. {
  8986. uint32_t ha_copy;
  8987. /* Read chip Host Attention (HA) register */
  8988. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  8989. goto unplug_err;
  8990. if (ha_copy & HA_ERATT) {
  8991. /* Read host status register to retrieve error event */
  8992. if (lpfc_sli_read_hs(phba))
  8993. goto unplug_err;
  8994. /* Check if there is a deferred error condition is active */
  8995. if ((HS_FFER1 & phba->work_hs) &&
  8996. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  8997. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  8998. phba->hba_flag |= DEFER_ERATT;
  8999. /* Clear all interrupt enable conditions */
  9000. writel(0, phba->HCregaddr);
  9001. readl(phba->HCregaddr);
  9002. }
  9003. /* Set the driver HA work bitmap */
  9004. phba->work_ha |= HA_ERATT;
  9005. /* Indicate polling handles this ERATT */
  9006. phba->hba_flag |= HBA_ERATT_HANDLED;
  9007. return 1;
  9008. }
  9009. return 0;
  9010. unplug_err:
  9011. /* Set the driver HS work bitmap */
  9012. phba->work_hs |= UNPLUG_ERR;
  9013. /* Set the driver HA work bitmap */
  9014. phba->work_ha |= HA_ERATT;
  9015. /* Indicate polling handles this ERATT */
  9016. phba->hba_flag |= HBA_ERATT_HANDLED;
  9017. return 1;
  9018. }
  9019. /**
  9020. * lpfc_sli4_eratt_read - read sli-4 error attention events
  9021. * @phba: Pointer to HBA context.
  9022. *
  9023. * This function is called to read the SLI4 device error attention registers
  9024. * for possible error attention events. The caller must hold the hostlock
  9025. * with spin_lock_irq().
  9026. *
  9027. * This function returns 1 when there is Error Attention in the Host Attention
  9028. * Register and returns 0 otherwise.
  9029. **/
  9030. static int
  9031. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  9032. {
  9033. uint32_t uerr_sta_hi, uerr_sta_lo;
  9034. uint32_t if_type, portsmphr;
  9035. struct lpfc_register portstat_reg;
  9036. /*
  9037. * For now, use the SLI4 device internal unrecoverable error
  9038. * registers for error attention. This can be changed later.
  9039. */
  9040. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  9041. switch (if_type) {
  9042. case LPFC_SLI_INTF_IF_TYPE_0:
  9043. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  9044. &uerr_sta_lo) ||
  9045. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  9046. &uerr_sta_hi)) {
  9047. phba->work_hs |= UNPLUG_ERR;
  9048. phba->work_ha |= HA_ERATT;
  9049. phba->hba_flag |= HBA_ERATT_HANDLED;
  9050. return 1;
  9051. }
  9052. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  9053. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  9054. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9055. "1423 HBA Unrecoverable error: "
  9056. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  9057. "ue_mask_lo_reg=0x%x, "
  9058. "ue_mask_hi_reg=0x%x\n",
  9059. uerr_sta_lo, uerr_sta_hi,
  9060. phba->sli4_hba.ue_mask_lo,
  9061. phba->sli4_hba.ue_mask_hi);
  9062. phba->work_status[0] = uerr_sta_lo;
  9063. phba->work_status[1] = uerr_sta_hi;
  9064. phba->work_ha |= HA_ERATT;
  9065. phba->hba_flag |= HBA_ERATT_HANDLED;
  9066. return 1;
  9067. }
  9068. break;
  9069. case LPFC_SLI_INTF_IF_TYPE_2:
  9070. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  9071. &portstat_reg.word0) ||
  9072. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  9073. &portsmphr)){
  9074. phba->work_hs |= UNPLUG_ERR;
  9075. phba->work_ha |= HA_ERATT;
  9076. phba->hba_flag |= HBA_ERATT_HANDLED;
  9077. return 1;
  9078. }
  9079. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  9080. phba->work_status[0] =
  9081. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  9082. phba->work_status[1] =
  9083. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  9084. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9085. "2885 Port Status Event: "
  9086. "port status reg 0x%x, "
  9087. "port smphr reg 0x%x, "
  9088. "error 1=0x%x, error 2=0x%x\n",
  9089. portstat_reg.word0,
  9090. portsmphr,
  9091. phba->work_status[0],
  9092. phba->work_status[1]);
  9093. phba->work_ha |= HA_ERATT;
  9094. phba->hba_flag |= HBA_ERATT_HANDLED;
  9095. return 1;
  9096. }
  9097. break;
  9098. case LPFC_SLI_INTF_IF_TYPE_1:
  9099. default:
  9100. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9101. "2886 HBA Error Attention on unsupported "
  9102. "if type %d.", if_type);
  9103. return 1;
  9104. }
  9105. return 0;
  9106. }
  9107. /**
  9108. * lpfc_sli_check_eratt - check error attention events
  9109. * @phba: Pointer to HBA context.
  9110. *
  9111. * This function is called from timer soft interrupt context to check HBA's
  9112. * error attention register bit for error attention events.
  9113. *
  9114. * This function returns 1 when there is Error Attention in the Host Attention
  9115. * Register and returns 0 otherwise.
  9116. **/
  9117. int
  9118. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  9119. {
  9120. uint32_t ha_copy;
  9121. /* If somebody is waiting to handle an eratt, don't process it
  9122. * here. The brdkill function will do this.
  9123. */
  9124. if (phba->link_flag & LS_IGNORE_ERATT)
  9125. return 0;
  9126. /* Check if interrupt handler handles this ERATT */
  9127. spin_lock_irq(&phba->hbalock);
  9128. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  9129. /* Interrupt handler has handled ERATT */
  9130. spin_unlock_irq(&phba->hbalock);
  9131. return 0;
  9132. }
  9133. /*
  9134. * If there is deferred error attention, do not check for error
  9135. * attention
  9136. */
  9137. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9138. spin_unlock_irq(&phba->hbalock);
  9139. return 0;
  9140. }
  9141. /* If PCI channel is offline, don't process it */
  9142. if (unlikely(pci_channel_offline(phba->pcidev))) {
  9143. spin_unlock_irq(&phba->hbalock);
  9144. return 0;
  9145. }
  9146. switch (phba->sli_rev) {
  9147. case LPFC_SLI_REV2:
  9148. case LPFC_SLI_REV3:
  9149. /* Read chip Host Attention (HA) register */
  9150. ha_copy = lpfc_sli_eratt_read(phba);
  9151. break;
  9152. case LPFC_SLI_REV4:
  9153. /* Read device Uncoverable Error (UERR) registers */
  9154. ha_copy = lpfc_sli4_eratt_read(phba);
  9155. break;
  9156. default:
  9157. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9158. "0299 Invalid SLI revision (%d)\n",
  9159. phba->sli_rev);
  9160. ha_copy = 0;
  9161. break;
  9162. }
  9163. spin_unlock_irq(&phba->hbalock);
  9164. return ha_copy;
  9165. }
  9166. /**
  9167. * lpfc_intr_state_check - Check device state for interrupt handling
  9168. * @phba: Pointer to HBA context.
  9169. *
  9170. * This inline routine checks whether a device or its PCI slot is in a state
  9171. * that the interrupt should be handled.
  9172. *
  9173. * This function returns 0 if the device or the PCI slot is in a state that
  9174. * interrupt should be handled, otherwise -EIO.
  9175. */
  9176. static inline int
  9177. lpfc_intr_state_check(struct lpfc_hba *phba)
  9178. {
  9179. /* If the pci channel is offline, ignore all the interrupts */
  9180. if (unlikely(pci_channel_offline(phba->pcidev)))
  9181. return -EIO;
  9182. /* Update device level interrupt statistics */
  9183. phba->sli.slistat.sli_intr++;
  9184. /* Ignore all interrupts during initialization. */
  9185. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9186. return -EIO;
  9187. return 0;
  9188. }
  9189. /**
  9190. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  9191. * @irq: Interrupt number.
  9192. * @dev_id: The device context pointer.
  9193. *
  9194. * This function is directly called from the PCI layer as an interrupt
  9195. * service routine when device with SLI-3 interface spec is enabled with
  9196. * MSI-X multi-message interrupt mode and there are slow-path events in
  9197. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  9198. * interrupt mode, this function is called as part of the device-level
  9199. * interrupt handler. When the PCI slot is in error recovery or the HBA
  9200. * is undergoing initialization, the interrupt handler will not process
  9201. * the interrupt. The link attention and ELS ring attention events are
  9202. * handled by the worker thread. The interrupt handler signals the worker
  9203. * thread and returns for these events. This function is called without
  9204. * any lock held. It gets the hbalock to access and update SLI data
  9205. * structures.
  9206. *
  9207. * This function returns IRQ_HANDLED when interrupt is handled else it
  9208. * returns IRQ_NONE.
  9209. **/
  9210. irqreturn_t
  9211. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  9212. {
  9213. struct lpfc_hba *phba;
  9214. uint32_t ha_copy, hc_copy;
  9215. uint32_t work_ha_copy;
  9216. unsigned long status;
  9217. unsigned long iflag;
  9218. uint32_t control;
  9219. MAILBOX_t *mbox, *pmbox;
  9220. struct lpfc_vport *vport;
  9221. struct lpfc_nodelist *ndlp;
  9222. struct lpfc_dmabuf *mp;
  9223. LPFC_MBOXQ_t *pmb;
  9224. int rc;
  9225. /*
  9226. * Get the driver's phba structure from the dev_id and
  9227. * assume the HBA is not interrupting.
  9228. */
  9229. phba = (struct lpfc_hba *)dev_id;
  9230. if (unlikely(!phba))
  9231. return IRQ_NONE;
  9232. /*
  9233. * Stuff needs to be attented to when this function is invoked as an
  9234. * individual interrupt handler in MSI-X multi-message interrupt mode
  9235. */
  9236. if (phba->intr_type == MSIX) {
  9237. /* Check device state for handling interrupt */
  9238. if (lpfc_intr_state_check(phba))
  9239. return IRQ_NONE;
  9240. /* Need to read HA REG for slow-path events */
  9241. spin_lock_irqsave(&phba->hbalock, iflag);
  9242. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9243. goto unplug_error;
  9244. /* If somebody is waiting to handle an eratt don't process it
  9245. * here. The brdkill function will do this.
  9246. */
  9247. if (phba->link_flag & LS_IGNORE_ERATT)
  9248. ha_copy &= ~HA_ERATT;
  9249. /* Check the need for handling ERATT in interrupt handler */
  9250. if (ha_copy & HA_ERATT) {
  9251. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9252. /* ERATT polling has handled ERATT */
  9253. ha_copy &= ~HA_ERATT;
  9254. else
  9255. /* Indicate interrupt handler handles ERATT */
  9256. phba->hba_flag |= HBA_ERATT_HANDLED;
  9257. }
  9258. /*
  9259. * If there is deferred error attention, do not check for any
  9260. * interrupt.
  9261. */
  9262. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9263. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9264. return IRQ_NONE;
  9265. }
  9266. /* Clear up only attention source related to slow-path */
  9267. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  9268. goto unplug_error;
  9269. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  9270. HC_LAINT_ENA | HC_ERINT_ENA),
  9271. phba->HCregaddr);
  9272. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  9273. phba->HAregaddr);
  9274. writel(hc_copy, phba->HCregaddr);
  9275. readl(phba->HAregaddr); /* flush */
  9276. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9277. } else
  9278. ha_copy = phba->ha_copy;
  9279. work_ha_copy = ha_copy & phba->work_ha_mask;
  9280. if (work_ha_copy) {
  9281. if (work_ha_copy & HA_LATT) {
  9282. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  9283. /*
  9284. * Turn off Link Attention interrupts
  9285. * until CLEAR_LA done
  9286. */
  9287. spin_lock_irqsave(&phba->hbalock, iflag);
  9288. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  9289. if (lpfc_readl(phba->HCregaddr, &control))
  9290. goto unplug_error;
  9291. control &= ~HC_LAINT_ENA;
  9292. writel(control, phba->HCregaddr);
  9293. readl(phba->HCregaddr); /* flush */
  9294. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9295. }
  9296. else
  9297. work_ha_copy &= ~HA_LATT;
  9298. }
  9299. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  9300. /*
  9301. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  9302. * the only slow ring.
  9303. */
  9304. status = (work_ha_copy &
  9305. (HA_RXMASK << (4*LPFC_ELS_RING)));
  9306. status >>= (4*LPFC_ELS_RING);
  9307. if (status & HA_RXMASK) {
  9308. spin_lock_irqsave(&phba->hbalock, iflag);
  9309. if (lpfc_readl(phba->HCregaddr, &control))
  9310. goto unplug_error;
  9311. lpfc_debugfs_slow_ring_trc(phba,
  9312. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  9313. control, status,
  9314. (uint32_t)phba->sli.slistat.sli_intr);
  9315. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  9316. lpfc_debugfs_slow_ring_trc(phba,
  9317. "ISR Disable ring:"
  9318. "pwork:x%x hawork:x%x wait:x%x",
  9319. phba->work_ha, work_ha_copy,
  9320. (uint32_t)((unsigned long)
  9321. &phba->work_waitq));
  9322. control &=
  9323. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  9324. writel(control, phba->HCregaddr);
  9325. readl(phba->HCregaddr); /* flush */
  9326. }
  9327. else {
  9328. lpfc_debugfs_slow_ring_trc(phba,
  9329. "ISR slow ring: pwork:"
  9330. "x%x hawork:x%x wait:x%x",
  9331. phba->work_ha, work_ha_copy,
  9332. (uint32_t)((unsigned long)
  9333. &phba->work_waitq));
  9334. }
  9335. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9336. }
  9337. }
  9338. spin_lock_irqsave(&phba->hbalock, iflag);
  9339. if (work_ha_copy & HA_ERATT) {
  9340. if (lpfc_sli_read_hs(phba))
  9341. goto unplug_error;
  9342. /*
  9343. * Check if there is a deferred error condition
  9344. * is active
  9345. */
  9346. if ((HS_FFER1 & phba->work_hs) &&
  9347. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  9348. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  9349. phba->work_hs)) {
  9350. phba->hba_flag |= DEFER_ERATT;
  9351. /* Clear all interrupt enable conditions */
  9352. writel(0, phba->HCregaddr);
  9353. readl(phba->HCregaddr);
  9354. }
  9355. }
  9356. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  9357. pmb = phba->sli.mbox_active;
  9358. pmbox = &pmb->u.mb;
  9359. mbox = phba->mbox;
  9360. vport = pmb->vport;
  9361. /* First check out the status word */
  9362. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  9363. if (pmbox->mbxOwner != OWN_HOST) {
  9364. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9365. /*
  9366. * Stray Mailbox Interrupt, mbxCommand <cmd>
  9367. * mbxStatus <status>
  9368. */
  9369. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9370. LOG_SLI,
  9371. "(%d):0304 Stray Mailbox "
  9372. "Interrupt mbxCommand x%x "
  9373. "mbxStatus x%x\n",
  9374. (vport ? vport->vpi : 0),
  9375. pmbox->mbxCommand,
  9376. pmbox->mbxStatus);
  9377. /* clear mailbox attention bit */
  9378. work_ha_copy &= ~HA_MBATT;
  9379. } else {
  9380. phba->sli.mbox_active = NULL;
  9381. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9382. phba->last_completion_time = jiffies;
  9383. del_timer(&phba->sli.mbox_tmo);
  9384. if (pmb->mbox_cmpl) {
  9385. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  9386. MAILBOX_CMD_SIZE);
  9387. if (pmb->out_ext_byte_len &&
  9388. pmb->context2)
  9389. lpfc_sli_pcimem_bcopy(
  9390. phba->mbox_ext,
  9391. pmb->context2,
  9392. pmb->out_ext_byte_len);
  9393. }
  9394. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9395. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9396. lpfc_debugfs_disc_trc(vport,
  9397. LPFC_DISC_TRC_MBOX_VPORT,
  9398. "MBOX dflt rpi: : "
  9399. "status:x%x rpi:x%x",
  9400. (uint32_t)pmbox->mbxStatus,
  9401. pmbox->un.varWords[0], 0);
  9402. if (!pmbox->mbxStatus) {
  9403. mp = (struct lpfc_dmabuf *)
  9404. (pmb->context1);
  9405. ndlp = (struct lpfc_nodelist *)
  9406. pmb->context2;
  9407. /* Reg_LOGIN of dflt RPI was
  9408. * successful. new lets get
  9409. * rid of the RPI using the
  9410. * same mbox buffer.
  9411. */
  9412. lpfc_unreg_login(phba,
  9413. vport->vpi,
  9414. pmbox->un.varWords[0],
  9415. pmb);
  9416. pmb->mbox_cmpl =
  9417. lpfc_mbx_cmpl_dflt_rpi;
  9418. pmb->context1 = mp;
  9419. pmb->context2 = ndlp;
  9420. pmb->vport = vport;
  9421. rc = lpfc_sli_issue_mbox(phba,
  9422. pmb,
  9423. MBX_NOWAIT);
  9424. if (rc != MBX_BUSY)
  9425. lpfc_printf_log(phba,
  9426. KERN_ERR,
  9427. LOG_MBOX | LOG_SLI,
  9428. "0350 rc should have"
  9429. "been MBX_BUSY\n");
  9430. if (rc != MBX_NOT_FINISHED)
  9431. goto send_current_mbox;
  9432. }
  9433. }
  9434. spin_lock_irqsave(
  9435. &phba->pport->work_port_lock,
  9436. iflag);
  9437. phba->pport->work_port_events &=
  9438. ~WORKER_MBOX_TMO;
  9439. spin_unlock_irqrestore(
  9440. &phba->pport->work_port_lock,
  9441. iflag);
  9442. lpfc_mbox_cmpl_put(phba, pmb);
  9443. }
  9444. } else
  9445. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9446. if ((work_ha_copy & HA_MBATT) &&
  9447. (phba->sli.mbox_active == NULL)) {
  9448. send_current_mbox:
  9449. /* Process next mailbox command if there is one */
  9450. do {
  9451. rc = lpfc_sli_issue_mbox(phba, NULL,
  9452. MBX_NOWAIT);
  9453. } while (rc == MBX_NOT_FINISHED);
  9454. if (rc != MBX_SUCCESS)
  9455. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9456. LOG_SLI, "0349 rc should be "
  9457. "MBX_SUCCESS\n");
  9458. }
  9459. spin_lock_irqsave(&phba->hbalock, iflag);
  9460. phba->work_ha |= work_ha_copy;
  9461. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9462. lpfc_worker_wake_up(phba);
  9463. }
  9464. return IRQ_HANDLED;
  9465. unplug_error:
  9466. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9467. return IRQ_HANDLED;
  9468. } /* lpfc_sli_sp_intr_handler */
  9469. /**
  9470. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  9471. * @irq: Interrupt number.
  9472. * @dev_id: The device context pointer.
  9473. *
  9474. * This function is directly called from the PCI layer as an interrupt
  9475. * service routine when device with SLI-3 interface spec is enabled with
  9476. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  9477. * ring event in the HBA. However, when the device is enabled with either
  9478. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  9479. * device-level interrupt handler. When the PCI slot is in error recovery
  9480. * or the HBA is undergoing initialization, the interrupt handler will not
  9481. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  9482. * the intrrupt context. This function is called without any lock held.
  9483. * It gets the hbalock to access and update SLI data structures.
  9484. *
  9485. * This function returns IRQ_HANDLED when interrupt is handled else it
  9486. * returns IRQ_NONE.
  9487. **/
  9488. irqreturn_t
  9489. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  9490. {
  9491. struct lpfc_hba *phba;
  9492. uint32_t ha_copy;
  9493. unsigned long status;
  9494. unsigned long iflag;
  9495. /* Get the driver's phba structure from the dev_id and
  9496. * assume the HBA is not interrupting.
  9497. */
  9498. phba = (struct lpfc_hba *) dev_id;
  9499. if (unlikely(!phba))
  9500. return IRQ_NONE;
  9501. /*
  9502. * Stuff needs to be attented to when this function is invoked as an
  9503. * individual interrupt handler in MSI-X multi-message interrupt mode
  9504. */
  9505. if (phba->intr_type == MSIX) {
  9506. /* Check device state for handling interrupt */
  9507. if (lpfc_intr_state_check(phba))
  9508. return IRQ_NONE;
  9509. /* Need to read HA REG for FCP ring and other ring events */
  9510. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  9511. return IRQ_HANDLED;
  9512. /* Clear up only attention source related to fast-path */
  9513. spin_lock_irqsave(&phba->hbalock, iflag);
  9514. /*
  9515. * If there is deferred error attention, do not check for
  9516. * any interrupt.
  9517. */
  9518. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9519. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9520. return IRQ_NONE;
  9521. }
  9522. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  9523. phba->HAregaddr);
  9524. readl(phba->HAregaddr); /* flush */
  9525. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9526. } else
  9527. ha_copy = phba->ha_copy;
  9528. /*
  9529. * Process all events on FCP ring. Take the optimized path for FCP IO.
  9530. */
  9531. ha_copy &= ~(phba->work_ha_mask);
  9532. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9533. status >>= (4*LPFC_FCP_RING);
  9534. if (status & HA_RXMASK)
  9535. lpfc_sli_handle_fast_ring_event(phba,
  9536. &phba->sli.ring[LPFC_FCP_RING],
  9537. status);
  9538. if (phba->cfg_multi_ring_support == 2) {
  9539. /*
  9540. * Process all events on extra ring. Take the optimized path
  9541. * for extra ring IO.
  9542. */
  9543. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9544. status >>= (4*LPFC_EXTRA_RING);
  9545. if (status & HA_RXMASK) {
  9546. lpfc_sli_handle_fast_ring_event(phba,
  9547. &phba->sli.ring[LPFC_EXTRA_RING],
  9548. status);
  9549. }
  9550. }
  9551. return IRQ_HANDLED;
  9552. } /* lpfc_sli_fp_intr_handler */
  9553. /**
  9554. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  9555. * @irq: Interrupt number.
  9556. * @dev_id: The device context pointer.
  9557. *
  9558. * This function is the HBA device-level interrupt handler to device with
  9559. * SLI-3 interface spec, called from the PCI layer when either MSI or
  9560. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  9561. * requires driver attention. This function invokes the slow-path interrupt
  9562. * attention handling function and fast-path interrupt attention handling
  9563. * function in turn to process the relevant HBA attention events. This
  9564. * function is called without any lock held. It gets the hbalock to access
  9565. * and update SLI data structures.
  9566. *
  9567. * This function returns IRQ_HANDLED when interrupt is handled, else it
  9568. * returns IRQ_NONE.
  9569. **/
  9570. irqreturn_t
  9571. lpfc_sli_intr_handler(int irq, void *dev_id)
  9572. {
  9573. struct lpfc_hba *phba;
  9574. irqreturn_t sp_irq_rc, fp_irq_rc;
  9575. unsigned long status1, status2;
  9576. uint32_t hc_copy;
  9577. /*
  9578. * Get the driver's phba structure from the dev_id and
  9579. * assume the HBA is not interrupting.
  9580. */
  9581. phba = (struct lpfc_hba *) dev_id;
  9582. if (unlikely(!phba))
  9583. return IRQ_NONE;
  9584. /* Check device state for handling interrupt */
  9585. if (lpfc_intr_state_check(phba))
  9586. return IRQ_NONE;
  9587. spin_lock(&phba->hbalock);
  9588. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  9589. spin_unlock(&phba->hbalock);
  9590. return IRQ_HANDLED;
  9591. }
  9592. if (unlikely(!phba->ha_copy)) {
  9593. spin_unlock(&phba->hbalock);
  9594. return IRQ_NONE;
  9595. } else if (phba->ha_copy & HA_ERATT) {
  9596. if (phba->hba_flag & HBA_ERATT_HANDLED)
  9597. /* ERATT polling has handled ERATT */
  9598. phba->ha_copy &= ~HA_ERATT;
  9599. else
  9600. /* Indicate interrupt handler handles ERATT */
  9601. phba->hba_flag |= HBA_ERATT_HANDLED;
  9602. }
  9603. /*
  9604. * If there is deferred error attention, do not check for any interrupt.
  9605. */
  9606. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  9607. spin_unlock(&phba->hbalock);
  9608. return IRQ_NONE;
  9609. }
  9610. /* Clear attention sources except link and error attentions */
  9611. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  9612. spin_unlock(&phba->hbalock);
  9613. return IRQ_HANDLED;
  9614. }
  9615. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  9616. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  9617. phba->HCregaddr);
  9618. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  9619. writel(hc_copy, phba->HCregaddr);
  9620. readl(phba->HAregaddr); /* flush */
  9621. spin_unlock(&phba->hbalock);
  9622. /*
  9623. * Invokes slow-path host attention interrupt handling as appropriate.
  9624. */
  9625. /* status of events with mailbox and link attention */
  9626. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  9627. /* status of events with ELS ring */
  9628. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  9629. status2 >>= (4*LPFC_ELS_RING);
  9630. if (status1 || (status2 & HA_RXMASK))
  9631. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  9632. else
  9633. sp_irq_rc = IRQ_NONE;
  9634. /*
  9635. * Invoke fast-path host attention interrupt handling as appropriate.
  9636. */
  9637. /* status of events with FCP ring */
  9638. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  9639. status1 >>= (4*LPFC_FCP_RING);
  9640. /* status of events with extra ring */
  9641. if (phba->cfg_multi_ring_support == 2) {
  9642. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  9643. status2 >>= (4*LPFC_EXTRA_RING);
  9644. } else
  9645. status2 = 0;
  9646. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  9647. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  9648. else
  9649. fp_irq_rc = IRQ_NONE;
  9650. /* Return device-level interrupt handling status */
  9651. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  9652. } /* lpfc_sli_intr_handler */
  9653. /**
  9654. * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
  9655. * @phba: pointer to lpfc hba data structure.
  9656. *
  9657. * This routine is invoked by the worker thread to process all the pending
  9658. * SLI4 FCP abort XRI events.
  9659. **/
  9660. void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
  9661. {
  9662. struct lpfc_cq_event *cq_event;
  9663. /* First, declare the fcp xri abort event has been handled */
  9664. spin_lock_irq(&phba->hbalock);
  9665. phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
  9666. spin_unlock_irq(&phba->hbalock);
  9667. /* Now, handle all the fcp xri abort events */
  9668. while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
  9669. /* Get the first event from the head of the event queue */
  9670. spin_lock_irq(&phba->hbalock);
  9671. list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  9672. cq_event, struct lpfc_cq_event, list);
  9673. spin_unlock_irq(&phba->hbalock);
  9674. /* Notify aborted XRI for FCP work queue */
  9675. lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9676. /* Free the event processed back to the free pool */
  9677. lpfc_sli4_cq_event_release(phba, cq_event);
  9678. }
  9679. }
  9680. /**
  9681. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  9682. * @phba: pointer to lpfc hba data structure.
  9683. *
  9684. * This routine is invoked by the worker thread to process all the pending
  9685. * SLI4 els abort xri events.
  9686. **/
  9687. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  9688. {
  9689. struct lpfc_cq_event *cq_event;
  9690. /* First, declare the els xri abort event has been handled */
  9691. spin_lock_irq(&phba->hbalock);
  9692. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  9693. spin_unlock_irq(&phba->hbalock);
  9694. /* Now, handle all the els xri abort events */
  9695. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  9696. /* Get the first event from the head of the event queue */
  9697. spin_lock_irq(&phba->hbalock);
  9698. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  9699. cq_event, struct lpfc_cq_event, list);
  9700. spin_unlock_irq(&phba->hbalock);
  9701. /* Notify aborted XRI for ELS work queue */
  9702. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  9703. /* Free the event processed back to the free pool */
  9704. lpfc_sli4_cq_event_release(phba, cq_event);
  9705. }
  9706. }
  9707. /**
  9708. * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
  9709. * @phba: pointer to lpfc hba data structure
  9710. * @pIocbIn: pointer to the rspiocbq
  9711. * @pIocbOut: pointer to the cmdiocbq
  9712. * @wcqe: pointer to the complete wcqe
  9713. *
  9714. * This routine transfers the fields of a command iocbq to a response iocbq
  9715. * by copying all the IOCB fields from command iocbq and transferring the
  9716. * completion status information from the complete wcqe.
  9717. **/
  9718. static void
  9719. lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
  9720. struct lpfc_iocbq *pIocbIn,
  9721. struct lpfc_iocbq *pIocbOut,
  9722. struct lpfc_wcqe_complete *wcqe)
  9723. {
  9724. unsigned long iflags;
  9725. size_t offset = offsetof(struct lpfc_iocbq, iocb);
  9726. memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
  9727. sizeof(struct lpfc_iocbq) - offset);
  9728. /* Map WCQE parameters into irspiocb parameters */
  9729. pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe);
  9730. if (pIocbOut->iocb_flag & LPFC_IO_FCP)
  9731. if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
  9732. pIocbIn->iocb.un.fcpi.fcpi_parm =
  9733. pIocbOut->iocb.un.fcpi.fcpi_parm -
  9734. wcqe->total_data_placed;
  9735. else
  9736. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9737. else {
  9738. pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
  9739. pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
  9740. }
  9741. /* Pick up HBA exchange busy condition */
  9742. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  9743. spin_lock_irqsave(&phba->hbalock, iflags);
  9744. pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
  9745. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9746. }
  9747. }
  9748. /**
  9749. * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
  9750. * @phba: Pointer to HBA context object.
  9751. * @wcqe: Pointer to work-queue completion queue entry.
  9752. *
  9753. * This routine handles an ELS work-queue completion event and construct
  9754. * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
  9755. * discovery engine to handle.
  9756. *
  9757. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  9758. **/
  9759. static struct lpfc_iocbq *
  9760. lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
  9761. struct lpfc_iocbq *irspiocbq)
  9762. {
  9763. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  9764. struct lpfc_iocbq *cmdiocbq;
  9765. struct lpfc_wcqe_complete *wcqe;
  9766. unsigned long iflags;
  9767. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  9768. spin_lock_irqsave(&phba->hbalock, iflags);
  9769. pring->stats.iocb_event++;
  9770. /* Look up the ELS command IOCB and create pseudo response IOCB */
  9771. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  9772. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9773. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9774. if (unlikely(!cmdiocbq)) {
  9775. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  9776. "0386 ELS complete with no corresponding "
  9777. "cmdiocb: iotag (%d)\n",
  9778. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  9779. lpfc_sli_release_iocbq(phba, irspiocbq);
  9780. return NULL;
  9781. }
  9782. /* Fake the irspiocbq and copy necessary response information */
  9783. lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
  9784. return irspiocbq;
  9785. }
  9786. /**
  9787. * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
  9788. * @phba: Pointer to HBA context object.
  9789. * @cqe: Pointer to mailbox completion queue entry.
  9790. *
  9791. * This routine process a mailbox completion queue entry with asynchrous
  9792. * event.
  9793. *
  9794. * Return: true if work posted to worker thread, otherwise false.
  9795. **/
  9796. static bool
  9797. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  9798. {
  9799. struct lpfc_cq_event *cq_event;
  9800. unsigned long iflags;
  9801. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  9802. "0392 Async Event: word0:x%x, word1:x%x, "
  9803. "word2:x%x, word3:x%x\n", mcqe->word0,
  9804. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  9805. /* Allocate a new internal CQ_EVENT entry */
  9806. cq_event = lpfc_sli4_cq_event_alloc(phba);
  9807. if (!cq_event) {
  9808. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9809. "0394 Failed to allocate CQ_EVENT entry\n");
  9810. return false;
  9811. }
  9812. /* Move the CQE into an asynchronous event entry */
  9813. memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
  9814. spin_lock_irqsave(&phba->hbalock, iflags);
  9815. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  9816. /* Set the async event flag */
  9817. phba->hba_flag |= ASYNC_EVENT;
  9818. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9819. return true;
  9820. }
  9821. /**
  9822. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  9823. * @phba: Pointer to HBA context object.
  9824. * @cqe: Pointer to mailbox completion queue entry.
  9825. *
  9826. * This routine process a mailbox completion queue entry with mailbox
  9827. * completion event.
  9828. *
  9829. * Return: true if work posted to worker thread, otherwise false.
  9830. **/
  9831. static bool
  9832. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  9833. {
  9834. uint32_t mcqe_status;
  9835. MAILBOX_t *mbox, *pmbox;
  9836. struct lpfc_mqe *mqe;
  9837. struct lpfc_vport *vport;
  9838. struct lpfc_nodelist *ndlp;
  9839. struct lpfc_dmabuf *mp;
  9840. unsigned long iflags;
  9841. LPFC_MBOXQ_t *pmb;
  9842. bool workposted = false;
  9843. int rc;
  9844. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  9845. if (!bf_get(lpfc_trailer_completed, mcqe))
  9846. goto out_no_mqe_complete;
  9847. /* Get the reference to the active mbox command */
  9848. spin_lock_irqsave(&phba->hbalock, iflags);
  9849. pmb = phba->sli.mbox_active;
  9850. if (unlikely(!pmb)) {
  9851. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  9852. "1832 No pending MBOX command to handle\n");
  9853. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9854. goto out_no_mqe_complete;
  9855. }
  9856. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9857. mqe = &pmb->u.mqe;
  9858. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  9859. mbox = phba->mbox;
  9860. vport = pmb->vport;
  9861. /* Reset heartbeat timer */
  9862. phba->last_completion_time = jiffies;
  9863. del_timer(&phba->sli.mbox_tmo);
  9864. /* Move mbox data to caller's mailbox region, do endian swapping */
  9865. if (pmb->mbox_cmpl && mbox)
  9866. lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  9867. /*
  9868. * For mcqe errors, conditionally move a modified error code to
  9869. * the mbox so that the error will not be missed.
  9870. */
  9871. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  9872. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  9873. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  9874. bf_set(lpfc_mqe_status, mqe,
  9875. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  9876. }
  9877. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  9878. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  9879. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  9880. "MBOX dflt rpi: status:x%x rpi:x%x",
  9881. mcqe_status,
  9882. pmbox->un.varWords[0], 0);
  9883. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  9884. mp = (struct lpfc_dmabuf *)(pmb->context1);
  9885. ndlp = (struct lpfc_nodelist *)pmb->context2;
  9886. /* Reg_LOGIN of dflt RPI was successful. Now lets get
  9887. * RID of the PPI using the same mbox buffer.
  9888. */
  9889. lpfc_unreg_login(phba, vport->vpi,
  9890. pmbox->un.varWords[0], pmb);
  9891. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  9892. pmb->context1 = mp;
  9893. pmb->context2 = ndlp;
  9894. pmb->vport = vport;
  9895. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  9896. if (rc != MBX_BUSY)
  9897. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  9898. LOG_SLI, "0385 rc should "
  9899. "have been MBX_BUSY\n");
  9900. if (rc != MBX_NOT_FINISHED)
  9901. goto send_current_mbox;
  9902. }
  9903. }
  9904. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  9905. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  9906. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  9907. /* There is mailbox completion work to do */
  9908. spin_lock_irqsave(&phba->hbalock, iflags);
  9909. __lpfc_mbox_cmpl_put(phba, pmb);
  9910. phba->work_ha |= HA_MBATT;
  9911. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9912. workposted = true;
  9913. send_current_mbox:
  9914. spin_lock_irqsave(&phba->hbalock, iflags);
  9915. /* Release the mailbox command posting token */
  9916. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  9917. /* Setting active mailbox pointer need to be in sync to flag clear */
  9918. phba->sli.mbox_active = NULL;
  9919. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9920. /* Wake up worker thread to post the next pending mailbox command */
  9921. lpfc_worker_wake_up(phba);
  9922. out_no_mqe_complete:
  9923. if (bf_get(lpfc_trailer_consumed, mcqe))
  9924. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  9925. return workposted;
  9926. }
  9927. /**
  9928. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  9929. * @phba: Pointer to HBA context object.
  9930. * @cqe: Pointer to mailbox completion queue entry.
  9931. *
  9932. * This routine process a mailbox completion queue entry, it invokes the
  9933. * proper mailbox complete handling or asynchrous event handling routine
  9934. * according to the MCQE's async bit.
  9935. *
  9936. * Return: true if work posted to worker thread, otherwise false.
  9937. **/
  9938. static bool
  9939. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
  9940. {
  9941. struct lpfc_mcqe mcqe;
  9942. bool workposted;
  9943. /* Copy the mailbox MCQE and convert endian order as needed */
  9944. lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  9945. /* Invoke the proper event handling routine */
  9946. if (!bf_get(lpfc_trailer_async, &mcqe))
  9947. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  9948. else
  9949. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  9950. return workposted;
  9951. }
  9952. /**
  9953. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  9954. * @phba: Pointer to HBA context object.
  9955. * @wcqe: Pointer to work-queue completion queue entry.
  9956. *
  9957. * This routine handles an ELS work-queue completion event.
  9958. *
  9959. * Return: true if work posted to worker thread, otherwise false.
  9960. **/
  9961. static bool
  9962. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba,
  9963. struct lpfc_wcqe_complete *wcqe)
  9964. {
  9965. struct lpfc_iocbq *irspiocbq;
  9966. unsigned long iflags;
  9967. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  9968. /* Get an irspiocbq for later ELS response processing use */
  9969. irspiocbq = lpfc_sli_get_iocbq(phba);
  9970. if (!irspiocbq) {
  9971. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  9972. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  9973. "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
  9974. pring->txq_cnt, phba->iocb_cnt,
  9975. phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt,
  9976. phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt);
  9977. return false;
  9978. }
  9979. /* Save off the slow-path queue event for work thread to process */
  9980. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  9981. spin_lock_irqsave(&phba->hbalock, iflags);
  9982. list_add_tail(&irspiocbq->cq_event.list,
  9983. &phba->sli4_hba.sp_queue_event);
  9984. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  9985. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9986. return true;
  9987. }
  9988. /**
  9989. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  9990. * @phba: Pointer to HBA context object.
  9991. * @wcqe: Pointer to work-queue completion queue entry.
  9992. *
  9993. * This routine handles slow-path WQ entry comsumed event by invoking the
  9994. * proper WQ release routine to the slow-path WQ.
  9995. **/
  9996. static void
  9997. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  9998. struct lpfc_wcqe_release *wcqe)
  9999. {
  10000. /* sanity check on queue memory */
  10001. if (unlikely(!phba->sli4_hba.els_wq))
  10002. return;
  10003. /* Check for the slow-path ELS work queue */
  10004. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  10005. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  10006. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10007. else
  10008. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10009. "2579 Slow-path wqe consume event carries "
  10010. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  10011. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  10012. phba->sli4_hba.els_wq->queue_id);
  10013. }
  10014. /**
  10015. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  10016. * @phba: Pointer to HBA context object.
  10017. * @cq: Pointer to a WQ completion queue.
  10018. * @wcqe: Pointer to work-queue completion queue entry.
  10019. *
  10020. * This routine handles an XRI abort event.
  10021. *
  10022. * Return: true if work posted to worker thread, otherwise false.
  10023. **/
  10024. static bool
  10025. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  10026. struct lpfc_queue *cq,
  10027. struct sli4_wcqe_xri_aborted *wcqe)
  10028. {
  10029. bool workposted = false;
  10030. struct lpfc_cq_event *cq_event;
  10031. unsigned long iflags;
  10032. /* Allocate a new internal CQ_EVENT entry */
  10033. cq_event = lpfc_sli4_cq_event_alloc(phba);
  10034. if (!cq_event) {
  10035. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10036. "0602 Failed to allocate CQ_EVENT entry\n");
  10037. return false;
  10038. }
  10039. /* Move the CQE into the proper xri abort event list */
  10040. memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
  10041. switch (cq->subtype) {
  10042. case LPFC_FCP:
  10043. spin_lock_irqsave(&phba->hbalock, iflags);
  10044. list_add_tail(&cq_event->list,
  10045. &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  10046. /* Set the fcp xri abort event flag */
  10047. phba->hba_flag |= FCP_XRI_ABORT_EVENT;
  10048. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10049. workposted = true;
  10050. break;
  10051. case LPFC_ELS:
  10052. spin_lock_irqsave(&phba->hbalock, iflags);
  10053. list_add_tail(&cq_event->list,
  10054. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  10055. /* Set the els xri abort event flag */
  10056. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  10057. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10058. workposted = true;
  10059. break;
  10060. default:
  10061. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10062. "0603 Invalid work queue CQE subtype (x%x)\n",
  10063. cq->subtype);
  10064. workposted = false;
  10065. break;
  10066. }
  10067. return workposted;
  10068. }
  10069. /**
  10070. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  10071. * @phba: Pointer to HBA context object.
  10072. * @rcqe: Pointer to receive-queue completion queue entry.
  10073. *
  10074. * This routine process a receive-queue completion queue entry.
  10075. *
  10076. * Return: true if work posted to worker thread, otherwise false.
  10077. **/
  10078. static bool
  10079. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  10080. {
  10081. bool workposted = false;
  10082. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  10083. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  10084. struct hbq_dmabuf *dma_buf;
  10085. uint32_t status, rq_id;
  10086. unsigned long iflags;
  10087. /* sanity check on queue memory */
  10088. if (unlikely(!hrq) || unlikely(!drq))
  10089. return workposted;
  10090. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  10091. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  10092. else
  10093. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  10094. if (rq_id != hrq->queue_id)
  10095. goto out;
  10096. status = bf_get(lpfc_rcqe_status, rcqe);
  10097. switch (status) {
  10098. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  10099. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10100. "2537 Receive Frame Truncated!!\n");
  10101. case FC_STATUS_RQ_SUCCESS:
  10102. lpfc_sli4_rq_release(hrq, drq);
  10103. spin_lock_irqsave(&phba->hbalock, iflags);
  10104. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  10105. if (!dma_buf) {
  10106. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10107. goto out;
  10108. }
  10109. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  10110. /* save off the frame for the word thread to process */
  10111. list_add_tail(&dma_buf->cq_event.list,
  10112. &phba->sli4_hba.sp_queue_event);
  10113. /* Frame received */
  10114. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  10115. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10116. workposted = true;
  10117. break;
  10118. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  10119. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  10120. /* Post more buffers if possible */
  10121. spin_lock_irqsave(&phba->hbalock, iflags);
  10122. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  10123. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10124. workposted = true;
  10125. break;
  10126. }
  10127. out:
  10128. return workposted;
  10129. }
  10130. /**
  10131. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  10132. * @phba: Pointer to HBA context object.
  10133. * @cq: Pointer to the completion queue.
  10134. * @wcqe: Pointer to a completion queue entry.
  10135. *
  10136. * This routine process a slow-path work-queue or receive queue completion queue
  10137. * entry.
  10138. *
  10139. * Return: true if work posted to worker thread, otherwise false.
  10140. **/
  10141. static bool
  10142. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10143. struct lpfc_cqe *cqe)
  10144. {
  10145. struct lpfc_cqe cqevt;
  10146. bool workposted = false;
  10147. /* Copy the work queue CQE and convert endian order if needed */
  10148. lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  10149. /* Check and process for different type of WCQE and dispatch */
  10150. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  10151. case CQE_CODE_COMPL_WQE:
  10152. /* Process the WQ/RQ complete event */
  10153. phba->last_completion_time = jiffies;
  10154. workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
  10155. (struct lpfc_wcqe_complete *)&cqevt);
  10156. break;
  10157. case CQE_CODE_RELEASE_WQE:
  10158. /* Process the WQ release event */
  10159. lpfc_sli4_sp_handle_rel_wcqe(phba,
  10160. (struct lpfc_wcqe_release *)&cqevt);
  10161. break;
  10162. case CQE_CODE_XRI_ABORTED:
  10163. /* Process the WQ XRI abort event */
  10164. phba->last_completion_time = jiffies;
  10165. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10166. (struct sli4_wcqe_xri_aborted *)&cqevt);
  10167. break;
  10168. case CQE_CODE_RECEIVE:
  10169. case CQE_CODE_RECEIVE_V1:
  10170. /* Process the RQ event */
  10171. phba->last_completion_time = jiffies;
  10172. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  10173. (struct lpfc_rcqe *)&cqevt);
  10174. break;
  10175. default:
  10176. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10177. "0388 Not a valid WCQE code: x%x\n",
  10178. bf_get(lpfc_cqe_code, &cqevt));
  10179. break;
  10180. }
  10181. return workposted;
  10182. }
  10183. /**
  10184. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  10185. * @phba: Pointer to HBA context object.
  10186. * @eqe: Pointer to fast-path event queue entry.
  10187. *
  10188. * This routine process a event queue entry from the slow-path event queue.
  10189. * It will check the MajorCode and MinorCode to determine this is for a
  10190. * completion event on a completion queue, if not, an error shall be logged
  10191. * and just return. Otherwise, it will get to the corresponding completion
  10192. * queue and process all the entries on that completion queue, rearm the
  10193. * completion queue, and then return.
  10194. *
  10195. **/
  10196. static void
  10197. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
  10198. {
  10199. struct lpfc_queue *cq = NULL, *childq, *speq;
  10200. struct lpfc_cqe *cqe;
  10201. bool workposted = false;
  10202. int ecount = 0;
  10203. uint16_t cqid;
  10204. if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) {
  10205. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10206. "0359 Not a valid slow-path completion "
  10207. "event: majorcode=x%x, minorcode=x%x\n",
  10208. bf_get_le32(lpfc_eqe_major_code, eqe),
  10209. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10210. return;
  10211. }
  10212. /* Get the reference to the corresponding CQ */
  10213. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10214. /* Search for completion queue pointer matching this cqid */
  10215. speq = phba->sli4_hba.sp_eq;
  10216. /* sanity check on queue memory */
  10217. if (unlikely(!speq))
  10218. return;
  10219. list_for_each_entry(childq, &speq->child_list, list) {
  10220. if (childq->queue_id == cqid) {
  10221. cq = childq;
  10222. break;
  10223. }
  10224. }
  10225. if (unlikely(!cq)) {
  10226. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10227. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10228. "0365 Slow-path CQ identifier "
  10229. "(%d) does not exist\n", cqid);
  10230. return;
  10231. }
  10232. /* Process all the entries to the CQ */
  10233. switch (cq->type) {
  10234. case LPFC_MCQ:
  10235. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10236. workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
  10237. if (!(++ecount % cq->entry_repost))
  10238. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10239. }
  10240. break;
  10241. case LPFC_WCQ:
  10242. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10243. if (cq->subtype == LPFC_FCP)
  10244. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq,
  10245. cqe);
  10246. else
  10247. workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
  10248. cqe);
  10249. if (!(++ecount % cq->entry_repost))
  10250. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10251. }
  10252. break;
  10253. default:
  10254. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10255. "0370 Invalid completion queue type (%d)\n",
  10256. cq->type);
  10257. return;
  10258. }
  10259. /* Catch the no cq entry condition, log an error */
  10260. if (unlikely(ecount == 0))
  10261. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10262. "0371 No entry from the CQ: identifier "
  10263. "(x%x), type (%d)\n", cq->queue_id, cq->type);
  10264. /* In any case, flash and re-arm the RCQ */
  10265. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10266. /* wake up worker thread if there are works to be done */
  10267. if (workposted)
  10268. lpfc_worker_wake_up(phba);
  10269. }
  10270. /**
  10271. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  10272. * @eqe: Pointer to fast-path completion queue entry.
  10273. *
  10274. * This routine process a fast-path work queue completion entry from fast-path
  10275. * event queue for FCP command response completion.
  10276. **/
  10277. static void
  10278. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
  10279. struct lpfc_wcqe_complete *wcqe)
  10280. {
  10281. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING];
  10282. struct lpfc_iocbq *cmdiocbq;
  10283. struct lpfc_iocbq irspiocbq;
  10284. unsigned long iflags;
  10285. spin_lock_irqsave(&phba->hbalock, iflags);
  10286. pring->stats.iocb_event++;
  10287. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10288. /* Check for response status */
  10289. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  10290. /* If resource errors reported from HBA, reduce queue
  10291. * depth of the SCSI device.
  10292. */
  10293. if ((bf_get(lpfc_wcqe_c_status, wcqe) ==
  10294. IOSTAT_LOCAL_REJECT) &&
  10295. (wcqe->parameter == IOERR_NO_RESOURCES)) {
  10296. phba->lpfc_rampdown_queue_depth(phba);
  10297. }
  10298. /* Log the error status */
  10299. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10300. "0373 FCP complete error: status=x%x, "
  10301. "hw_status=x%x, total_data_specified=%d, "
  10302. "parameter=x%x, word3=x%x\n",
  10303. bf_get(lpfc_wcqe_c_status, wcqe),
  10304. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  10305. wcqe->total_data_placed, wcqe->parameter,
  10306. wcqe->word3);
  10307. }
  10308. /* Look up the FCP command IOCB and create pseudo response IOCB */
  10309. spin_lock_irqsave(&phba->hbalock, iflags);
  10310. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  10311. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10312. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10313. if (unlikely(!cmdiocbq)) {
  10314. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10315. "0374 FCP complete with no corresponding "
  10316. "cmdiocb: iotag (%d)\n",
  10317. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10318. return;
  10319. }
  10320. if (unlikely(!cmdiocbq->iocb_cmpl)) {
  10321. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10322. "0375 FCP cmdiocb not callback function "
  10323. "iotag: (%d)\n",
  10324. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  10325. return;
  10326. }
  10327. /* Fake the irspiocb and copy necessary response information */
  10328. lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
  10329. if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
  10330. spin_lock_irqsave(&phba->hbalock, iflags);
  10331. cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  10332. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10333. }
  10334. /* Pass the cmd_iocb and the rsp state to the upper layer */
  10335. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
  10336. }
  10337. /**
  10338. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  10339. * @phba: Pointer to HBA context object.
  10340. * @cq: Pointer to completion queue.
  10341. * @wcqe: Pointer to work-queue completion queue entry.
  10342. *
  10343. * This routine handles an fast-path WQ entry comsumed event by invoking the
  10344. * proper WQ release routine to the slow-path WQ.
  10345. **/
  10346. static void
  10347. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10348. struct lpfc_wcqe_release *wcqe)
  10349. {
  10350. struct lpfc_queue *childwq;
  10351. bool wqid_matched = false;
  10352. uint16_t fcp_wqid;
  10353. /* Check for fast-path FCP work queue release */
  10354. fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  10355. list_for_each_entry(childwq, &cq->child_list, list) {
  10356. if (childwq->queue_id == fcp_wqid) {
  10357. lpfc_sli4_wq_release(childwq,
  10358. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  10359. wqid_matched = true;
  10360. break;
  10361. }
  10362. }
  10363. /* Report warning log message if no match found */
  10364. if (wqid_matched != true)
  10365. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10366. "2580 Fast-path wqe consume event carries "
  10367. "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid);
  10368. }
  10369. /**
  10370. * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
  10371. * @cq: Pointer to the completion queue.
  10372. * @eqe: Pointer to fast-path completion queue entry.
  10373. *
  10374. * This routine process a fast-path work queue completion entry from fast-path
  10375. * event queue for FCP command response completion.
  10376. **/
  10377. static int
  10378. lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10379. struct lpfc_cqe *cqe)
  10380. {
  10381. struct lpfc_wcqe_release wcqe;
  10382. bool workposted = false;
  10383. /* Copy the work queue CQE and convert endian order if needed */
  10384. lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  10385. /* Check and process for different type of WCQE and dispatch */
  10386. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  10387. case CQE_CODE_COMPL_WQE:
  10388. /* Process the WQ complete event */
  10389. phba->last_completion_time = jiffies;
  10390. lpfc_sli4_fp_handle_fcp_wcqe(phba,
  10391. (struct lpfc_wcqe_complete *)&wcqe);
  10392. break;
  10393. case CQE_CODE_RELEASE_WQE:
  10394. /* Process the WQ release event */
  10395. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  10396. (struct lpfc_wcqe_release *)&wcqe);
  10397. break;
  10398. case CQE_CODE_XRI_ABORTED:
  10399. /* Process the WQ XRI abort event */
  10400. phba->last_completion_time = jiffies;
  10401. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  10402. (struct sli4_wcqe_xri_aborted *)&wcqe);
  10403. break;
  10404. default:
  10405. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10406. "0144 Not a valid WCQE code: x%x\n",
  10407. bf_get(lpfc_wcqe_c_code, &wcqe));
  10408. break;
  10409. }
  10410. return workposted;
  10411. }
  10412. /**
  10413. * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry
  10414. * @phba: Pointer to HBA context object.
  10415. * @eqe: Pointer to fast-path event queue entry.
  10416. *
  10417. * This routine process a event queue entry from the fast-path event queue.
  10418. * It will check the MajorCode and MinorCode to determine this is for a
  10419. * completion event on a completion queue, if not, an error shall be logged
  10420. * and just return. Otherwise, it will get to the corresponding completion
  10421. * queue and process all the entries on the completion queue, rearm the
  10422. * completion queue, and then return.
  10423. **/
  10424. static void
  10425. lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  10426. uint32_t fcp_cqidx)
  10427. {
  10428. struct lpfc_queue *cq;
  10429. struct lpfc_cqe *cqe;
  10430. bool workposted = false;
  10431. uint16_t cqid;
  10432. int ecount = 0;
  10433. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  10434. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10435. "0366 Not a valid fast-path completion "
  10436. "event: majorcode=x%x, minorcode=x%x\n",
  10437. bf_get_le32(lpfc_eqe_major_code, eqe),
  10438. bf_get_le32(lpfc_eqe_minor_code, eqe));
  10439. return;
  10440. }
  10441. if (unlikely(!phba->sli4_hba.fcp_cq)) {
  10442. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10443. "3146 Fast-path completion queues "
  10444. "does not exist\n");
  10445. return;
  10446. }
  10447. cq = phba->sli4_hba.fcp_cq[fcp_cqidx];
  10448. if (unlikely(!cq)) {
  10449. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  10450. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10451. "0367 Fast-path completion queue "
  10452. "(%d) does not exist\n", fcp_cqidx);
  10453. return;
  10454. }
  10455. /* Get the reference to the corresponding CQ */
  10456. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  10457. if (unlikely(cqid != cq->queue_id)) {
  10458. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10459. "0368 Miss-matched fast-path completion "
  10460. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  10461. cqid, cq->queue_id);
  10462. return;
  10463. }
  10464. /* Process all the entries to the CQ */
  10465. while ((cqe = lpfc_sli4_cq_get(cq))) {
  10466. workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe);
  10467. if (!(++ecount % cq->entry_repost))
  10468. lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
  10469. }
  10470. /* Catch the no cq entry condition */
  10471. if (unlikely(ecount == 0))
  10472. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10473. "0369 No entry from fast-path completion "
  10474. "queue fcpcqid=%d\n", cq->queue_id);
  10475. /* In any case, flash and re-arm the CQ */
  10476. lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
  10477. /* wake up worker thread if there are works to be done */
  10478. if (workposted)
  10479. lpfc_worker_wake_up(phba);
  10480. }
  10481. static void
  10482. lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  10483. {
  10484. struct lpfc_eqe *eqe;
  10485. /* walk all the EQ entries and drop on the floor */
  10486. while ((eqe = lpfc_sli4_eq_get(eq)))
  10487. ;
  10488. /* Clear and re-arm the EQ */
  10489. lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
  10490. }
  10491. /**
  10492. * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device
  10493. * @irq: Interrupt number.
  10494. * @dev_id: The device context pointer.
  10495. *
  10496. * This function is directly called from the PCI layer as an interrupt
  10497. * service routine when device with SLI-4 interface spec is enabled with
  10498. * MSI-X multi-message interrupt mode and there are slow-path events in
  10499. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  10500. * interrupt mode, this function is called as part of the device-level
  10501. * interrupt handler. When the PCI slot is in error recovery or the HBA is
  10502. * undergoing initialization, the interrupt handler will not process the
  10503. * interrupt. The link attention and ELS ring attention events are handled
  10504. * by the worker thread. The interrupt handler signals the worker thread
  10505. * and returns for these events. This function is called without any lock
  10506. * held. It gets the hbalock to access and update SLI data structures.
  10507. *
  10508. * This function returns IRQ_HANDLED when interrupt is handled else it
  10509. * returns IRQ_NONE.
  10510. **/
  10511. irqreturn_t
  10512. lpfc_sli4_sp_intr_handler(int irq, void *dev_id)
  10513. {
  10514. struct lpfc_hba *phba;
  10515. struct lpfc_queue *speq;
  10516. struct lpfc_eqe *eqe;
  10517. unsigned long iflag;
  10518. int ecount = 0;
  10519. /*
  10520. * Get the driver's phba structure from the dev_id
  10521. */
  10522. phba = (struct lpfc_hba *)dev_id;
  10523. if (unlikely(!phba))
  10524. return IRQ_NONE;
  10525. /* Get to the EQ struct associated with this vector */
  10526. speq = phba->sli4_hba.sp_eq;
  10527. if (unlikely(!speq))
  10528. return IRQ_NONE;
  10529. /* Check device state for handling interrupt */
  10530. if (unlikely(lpfc_intr_state_check(phba))) {
  10531. /* Check again for link_state with lock held */
  10532. spin_lock_irqsave(&phba->hbalock, iflag);
  10533. if (phba->link_state < LPFC_LINK_DOWN)
  10534. /* Flush, clear interrupt, and rearm the EQ */
  10535. lpfc_sli4_eq_flush(phba, speq);
  10536. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10537. return IRQ_NONE;
  10538. }
  10539. /*
  10540. * Process all the event on FCP slow-path EQ
  10541. */
  10542. while ((eqe = lpfc_sli4_eq_get(speq))) {
  10543. lpfc_sli4_sp_handle_eqe(phba, eqe);
  10544. if (!(++ecount % speq->entry_repost))
  10545. lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM);
  10546. }
  10547. /* Always clear and re-arm the slow-path EQ */
  10548. lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM);
  10549. /* Catch the no cq entry condition */
  10550. if (unlikely(ecount == 0)) {
  10551. if (phba->intr_type == MSIX)
  10552. /* MSI-X treated interrupt served as no EQ share INT */
  10553. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10554. "0357 MSI-X interrupt with no EQE\n");
  10555. else
  10556. /* Non MSI-X treated on interrupt as EQ share INT */
  10557. return IRQ_NONE;
  10558. }
  10559. return IRQ_HANDLED;
  10560. } /* lpfc_sli4_sp_intr_handler */
  10561. /**
  10562. * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device
  10563. * @irq: Interrupt number.
  10564. * @dev_id: The device context pointer.
  10565. *
  10566. * This function is directly called from the PCI layer as an interrupt
  10567. * service routine when device with SLI-4 interface spec is enabled with
  10568. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  10569. * ring event in the HBA. However, when the device is enabled with either
  10570. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  10571. * device-level interrupt handler. When the PCI slot is in error recovery
  10572. * or the HBA is undergoing initialization, the interrupt handler will not
  10573. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  10574. * the intrrupt context. This function is called without any lock held.
  10575. * It gets the hbalock to access and update SLI data structures. Note that,
  10576. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  10577. * equal to that of FCP CQ index.
  10578. *
  10579. * This function returns IRQ_HANDLED when interrupt is handled else it
  10580. * returns IRQ_NONE.
  10581. **/
  10582. irqreturn_t
  10583. lpfc_sli4_fp_intr_handler(int irq, void *dev_id)
  10584. {
  10585. struct lpfc_hba *phba;
  10586. struct lpfc_fcp_eq_hdl *fcp_eq_hdl;
  10587. struct lpfc_queue *fpeq;
  10588. struct lpfc_eqe *eqe;
  10589. unsigned long iflag;
  10590. int ecount = 0;
  10591. uint32_t fcp_eqidx;
  10592. /* Get the driver's phba structure from the dev_id */
  10593. fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id;
  10594. phba = fcp_eq_hdl->phba;
  10595. fcp_eqidx = fcp_eq_hdl->idx;
  10596. if (unlikely(!phba))
  10597. return IRQ_NONE;
  10598. if (unlikely(!phba->sli4_hba.fp_eq))
  10599. return IRQ_NONE;
  10600. /* Get to the EQ struct associated with this vector */
  10601. fpeq = phba->sli4_hba.fp_eq[fcp_eqidx];
  10602. if (unlikely(!fpeq))
  10603. return IRQ_NONE;
  10604. /* Check device state for handling interrupt */
  10605. if (unlikely(lpfc_intr_state_check(phba))) {
  10606. /* Check again for link_state with lock held */
  10607. spin_lock_irqsave(&phba->hbalock, iflag);
  10608. if (phba->link_state < LPFC_LINK_DOWN)
  10609. /* Flush, clear interrupt, and rearm the EQ */
  10610. lpfc_sli4_eq_flush(phba, fpeq);
  10611. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10612. return IRQ_NONE;
  10613. }
  10614. /*
  10615. * Process all the event on FCP fast-path EQ
  10616. */
  10617. while ((eqe = lpfc_sli4_eq_get(fpeq))) {
  10618. lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx);
  10619. if (!(++ecount % fpeq->entry_repost))
  10620. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
  10621. }
  10622. /* Always clear and re-arm the fast-path EQ */
  10623. lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
  10624. if (unlikely(ecount == 0)) {
  10625. if (phba->intr_type == MSIX)
  10626. /* MSI-X treated interrupt served as no EQ share INT */
  10627. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10628. "0358 MSI-X interrupt with no EQE\n");
  10629. else
  10630. /* Non MSI-X treated on interrupt as EQ share INT */
  10631. return IRQ_NONE;
  10632. }
  10633. return IRQ_HANDLED;
  10634. } /* lpfc_sli4_fp_intr_handler */
  10635. /**
  10636. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  10637. * @irq: Interrupt number.
  10638. * @dev_id: The device context pointer.
  10639. *
  10640. * This function is the device-level interrupt handler to device with SLI-4
  10641. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  10642. * interrupt mode is enabled and there is an event in the HBA which requires
  10643. * driver attention. This function invokes the slow-path interrupt attention
  10644. * handling function and fast-path interrupt attention handling function in
  10645. * turn to process the relevant HBA attention events. This function is called
  10646. * without any lock held. It gets the hbalock to access and update SLI data
  10647. * structures.
  10648. *
  10649. * This function returns IRQ_HANDLED when interrupt is handled, else it
  10650. * returns IRQ_NONE.
  10651. **/
  10652. irqreturn_t
  10653. lpfc_sli4_intr_handler(int irq, void *dev_id)
  10654. {
  10655. struct lpfc_hba *phba;
  10656. irqreturn_t sp_irq_rc, fp_irq_rc;
  10657. bool fp_handled = false;
  10658. uint32_t fcp_eqidx;
  10659. /* Get the driver's phba structure from the dev_id */
  10660. phba = (struct lpfc_hba *)dev_id;
  10661. if (unlikely(!phba))
  10662. return IRQ_NONE;
  10663. /*
  10664. * Invokes slow-path host attention interrupt handling as appropriate.
  10665. */
  10666. sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id);
  10667. /*
  10668. * Invoke fast-path host attention interrupt handling as appropriate.
  10669. */
  10670. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  10671. fp_irq_rc = lpfc_sli4_fp_intr_handler(irq,
  10672. &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]);
  10673. if (fp_irq_rc == IRQ_HANDLED)
  10674. fp_handled |= true;
  10675. }
  10676. return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc;
  10677. } /* lpfc_sli4_intr_handler */
  10678. /**
  10679. * lpfc_sli4_queue_free - free a queue structure and associated memory
  10680. * @queue: The queue structure to free.
  10681. *
  10682. * This function frees a queue structure and the DMAable memory used for
  10683. * the host resident queue. This function must be called after destroying the
  10684. * queue on the HBA.
  10685. **/
  10686. void
  10687. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  10688. {
  10689. struct lpfc_dmabuf *dmabuf;
  10690. if (!queue)
  10691. return;
  10692. while (!list_empty(&queue->page_list)) {
  10693. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  10694. list);
  10695. dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
  10696. dmabuf->virt, dmabuf->phys);
  10697. kfree(dmabuf);
  10698. }
  10699. kfree(queue);
  10700. return;
  10701. }
  10702. /**
  10703. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  10704. * @phba: The HBA that this queue is being created on.
  10705. * @entry_size: The size of each queue entry for this queue.
  10706. * @entry count: The number of entries that this queue will handle.
  10707. *
  10708. * This function allocates a queue structure and the DMAable memory used for
  10709. * the host resident queue. This function must be called before creating the
  10710. * queue on the HBA.
  10711. **/
  10712. struct lpfc_queue *
  10713. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
  10714. uint32_t entry_count)
  10715. {
  10716. struct lpfc_queue *queue;
  10717. struct lpfc_dmabuf *dmabuf;
  10718. int x, total_qe_count;
  10719. void *dma_pointer;
  10720. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10721. if (!phba->sli4_hba.pc_sli4_params.supported)
  10722. hw_page_size = SLI4_PAGE_SIZE;
  10723. queue = kzalloc(sizeof(struct lpfc_queue) +
  10724. (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
  10725. if (!queue)
  10726. return NULL;
  10727. queue->page_count = (ALIGN(entry_size * entry_count,
  10728. hw_page_size))/hw_page_size;
  10729. INIT_LIST_HEAD(&queue->list);
  10730. INIT_LIST_HEAD(&queue->page_list);
  10731. INIT_LIST_HEAD(&queue->child_list);
  10732. for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
  10733. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  10734. if (!dmabuf)
  10735. goto out_fail;
  10736. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  10737. hw_page_size, &dmabuf->phys,
  10738. GFP_KERNEL);
  10739. if (!dmabuf->virt) {
  10740. kfree(dmabuf);
  10741. goto out_fail;
  10742. }
  10743. memset(dmabuf->virt, 0, hw_page_size);
  10744. dmabuf->buffer_tag = x;
  10745. list_add_tail(&dmabuf->list, &queue->page_list);
  10746. /* initialize queue's entry array */
  10747. dma_pointer = dmabuf->virt;
  10748. for (; total_qe_count < entry_count &&
  10749. dma_pointer < (hw_page_size + dmabuf->virt);
  10750. total_qe_count++, dma_pointer += entry_size) {
  10751. queue->qe[total_qe_count].address = dma_pointer;
  10752. }
  10753. }
  10754. queue->entry_size = entry_size;
  10755. queue->entry_count = entry_count;
  10756. /*
  10757. * entry_repost is calculated based on the number of entries in the
  10758. * queue. This works out except for RQs. If buffers are NOT initially
  10759. * posted for every RQE, entry_repost should be adjusted accordingly.
  10760. */
  10761. queue->entry_repost = (entry_count >> 3);
  10762. if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
  10763. queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
  10764. queue->phba = phba;
  10765. return queue;
  10766. out_fail:
  10767. lpfc_sli4_queue_free(queue);
  10768. return NULL;
  10769. }
  10770. /**
  10771. * lpfc_eq_create - Create an Event Queue on the HBA
  10772. * @phba: HBA structure that indicates port to create a queue on.
  10773. * @eq: The queue structure to use to create the event queue.
  10774. * @imax: The maximum interrupt per second limit.
  10775. *
  10776. * This function creates an event queue, as detailed in @eq, on a port,
  10777. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  10778. *
  10779. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  10780. * is used to get the entry count and entry size that are necessary to
  10781. * determine the number of pages to allocate and use for this queue. This
  10782. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  10783. * event queue. This function is asynchronous and will wait for the mailbox
  10784. * command to finish before continuing.
  10785. *
  10786. * On success this function will return a zero. If unable to allocate enough
  10787. * memory this function will return -ENOMEM. If the queue create mailbox command
  10788. * fails this function will return -ENXIO.
  10789. **/
  10790. uint32_t
  10791. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax)
  10792. {
  10793. struct lpfc_mbx_eq_create *eq_create;
  10794. LPFC_MBOXQ_t *mbox;
  10795. int rc, length, status = 0;
  10796. struct lpfc_dmabuf *dmabuf;
  10797. uint32_t shdr_status, shdr_add_status;
  10798. union lpfc_sli4_cfg_shdr *shdr;
  10799. uint16_t dmult;
  10800. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10801. /* sanity check on queue memory */
  10802. if (!eq)
  10803. return -ENODEV;
  10804. if (!phba->sli4_hba.pc_sli4_params.supported)
  10805. hw_page_size = SLI4_PAGE_SIZE;
  10806. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10807. if (!mbox)
  10808. return -ENOMEM;
  10809. length = (sizeof(struct lpfc_mbx_eq_create) -
  10810. sizeof(struct lpfc_sli4_cfg_mhdr));
  10811. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10812. LPFC_MBOX_OPCODE_EQ_CREATE,
  10813. length, LPFC_SLI4_MBX_EMBED);
  10814. eq_create = &mbox->u.mqe.un.eq_create;
  10815. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  10816. eq->page_count);
  10817. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  10818. LPFC_EQE_SIZE);
  10819. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  10820. /* Calculate delay multiper from maximum interrupt per second */
  10821. dmult = LPFC_DMULT_CONST/imax - 1;
  10822. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  10823. dmult);
  10824. switch (eq->entry_count) {
  10825. default:
  10826. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10827. "0360 Unsupported EQ count. (%d)\n",
  10828. eq->entry_count);
  10829. if (eq->entry_count < 256)
  10830. return -EINVAL;
  10831. /* otherwise default to smallest count (drop through) */
  10832. case 256:
  10833. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10834. LPFC_EQ_CNT_256);
  10835. break;
  10836. case 512:
  10837. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10838. LPFC_EQ_CNT_512);
  10839. break;
  10840. case 1024:
  10841. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10842. LPFC_EQ_CNT_1024);
  10843. break;
  10844. case 2048:
  10845. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10846. LPFC_EQ_CNT_2048);
  10847. break;
  10848. case 4096:
  10849. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  10850. LPFC_EQ_CNT_4096);
  10851. break;
  10852. }
  10853. list_for_each_entry(dmabuf, &eq->page_list, list) {
  10854. memset(dmabuf->virt, 0, hw_page_size);
  10855. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10856. putPaddrLow(dmabuf->phys);
  10857. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10858. putPaddrHigh(dmabuf->phys);
  10859. }
  10860. mbox->vport = phba->pport;
  10861. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  10862. mbox->context1 = NULL;
  10863. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10864. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  10865. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10866. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10867. if (shdr_status || shdr_add_status || rc) {
  10868. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10869. "2500 EQ_CREATE mailbox failed with "
  10870. "status x%x add_status x%x, mbx status x%x\n",
  10871. shdr_status, shdr_add_status, rc);
  10872. status = -ENXIO;
  10873. }
  10874. eq->type = LPFC_EQ;
  10875. eq->subtype = LPFC_NONE;
  10876. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  10877. if (eq->queue_id == 0xFFFF)
  10878. status = -ENXIO;
  10879. eq->host_index = 0;
  10880. eq->hba_index = 0;
  10881. mempool_free(mbox, phba->mbox_mem_pool);
  10882. return status;
  10883. }
  10884. /**
  10885. * lpfc_cq_create - Create a Completion Queue on the HBA
  10886. * @phba: HBA structure that indicates port to create a queue on.
  10887. * @cq: The queue structure to use to create the completion queue.
  10888. * @eq: The event queue to bind this completion queue to.
  10889. *
  10890. * This function creates a completion queue, as detailed in @wq, on a port,
  10891. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  10892. *
  10893. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  10894. * is used to get the entry count and entry size that are necessary to
  10895. * determine the number of pages to allocate and use for this queue. The @eq
  10896. * is used to indicate which event queue to bind this completion queue to. This
  10897. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  10898. * completion queue. This function is asynchronous and will wait for the mailbox
  10899. * command to finish before continuing.
  10900. *
  10901. * On success this function will return a zero. If unable to allocate enough
  10902. * memory this function will return -ENOMEM. If the queue create mailbox command
  10903. * fails this function will return -ENXIO.
  10904. **/
  10905. uint32_t
  10906. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  10907. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  10908. {
  10909. struct lpfc_mbx_cq_create *cq_create;
  10910. struct lpfc_dmabuf *dmabuf;
  10911. LPFC_MBOXQ_t *mbox;
  10912. int rc, length, status = 0;
  10913. uint32_t shdr_status, shdr_add_status;
  10914. union lpfc_sli4_cfg_shdr *shdr;
  10915. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  10916. /* sanity check on queue memory */
  10917. if (!cq || !eq)
  10918. return -ENODEV;
  10919. if (!phba->sli4_hba.pc_sli4_params.supported)
  10920. hw_page_size = SLI4_PAGE_SIZE;
  10921. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  10922. if (!mbox)
  10923. return -ENOMEM;
  10924. length = (sizeof(struct lpfc_mbx_cq_create) -
  10925. sizeof(struct lpfc_sli4_cfg_mhdr));
  10926. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  10927. LPFC_MBOX_OPCODE_CQ_CREATE,
  10928. length, LPFC_SLI4_MBX_EMBED);
  10929. cq_create = &mbox->u.mqe.un.cq_create;
  10930. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  10931. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  10932. cq->page_count);
  10933. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  10934. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  10935. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  10936. phba->sli4_hba.pc_sli4_params.cqv);
  10937. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  10938. /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
  10939. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
  10940. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  10941. eq->queue_id);
  10942. } else {
  10943. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  10944. eq->queue_id);
  10945. }
  10946. switch (cq->entry_count) {
  10947. default:
  10948. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  10949. "0361 Unsupported CQ count. (%d)\n",
  10950. cq->entry_count);
  10951. if (cq->entry_count < 256)
  10952. return -EINVAL;
  10953. /* otherwise default to smallest count (drop through) */
  10954. case 256:
  10955. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  10956. LPFC_CQ_CNT_256);
  10957. break;
  10958. case 512:
  10959. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  10960. LPFC_CQ_CNT_512);
  10961. break;
  10962. case 1024:
  10963. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  10964. LPFC_CQ_CNT_1024);
  10965. break;
  10966. }
  10967. list_for_each_entry(dmabuf, &cq->page_list, list) {
  10968. memset(dmabuf->virt, 0, hw_page_size);
  10969. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  10970. putPaddrLow(dmabuf->phys);
  10971. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  10972. putPaddrHigh(dmabuf->phys);
  10973. }
  10974. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  10975. /* The IOCTL status is embedded in the mailbox subheader. */
  10976. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  10977. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  10978. if (shdr_status || shdr_add_status || rc) {
  10979. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10980. "2501 CQ_CREATE mailbox failed with "
  10981. "status x%x add_status x%x, mbx status x%x\n",
  10982. shdr_status, shdr_add_status, rc);
  10983. status = -ENXIO;
  10984. goto out;
  10985. }
  10986. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  10987. if (cq->queue_id == 0xFFFF) {
  10988. status = -ENXIO;
  10989. goto out;
  10990. }
  10991. /* link the cq onto the parent eq child list */
  10992. list_add_tail(&cq->list, &eq->child_list);
  10993. /* Set up completion queue's type and subtype */
  10994. cq->type = type;
  10995. cq->subtype = subtype;
  10996. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  10997. cq->assoc_qid = eq->queue_id;
  10998. cq->host_index = 0;
  10999. cq->hba_index = 0;
  11000. out:
  11001. mempool_free(mbox, phba->mbox_mem_pool);
  11002. return status;
  11003. }
  11004. /**
  11005. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  11006. * @phba: HBA structure that indicates port to create a queue on.
  11007. * @mq: The queue structure to use to create the mailbox queue.
  11008. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  11009. * @cq: The completion queue to associate with this cq.
  11010. *
  11011. * This function provides failback (fb) functionality when the
  11012. * mq_create_ext fails on older FW generations. It's purpose is identical
  11013. * to mq_create_ext otherwise.
  11014. *
  11015. * This routine cannot fail as all attributes were previously accessed and
  11016. * initialized in mq_create_ext.
  11017. **/
  11018. static void
  11019. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11020. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  11021. {
  11022. struct lpfc_mbx_mq_create *mq_create;
  11023. struct lpfc_dmabuf *dmabuf;
  11024. int length;
  11025. length = (sizeof(struct lpfc_mbx_mq_create) -
  11026. sizeof(struct lpfc_sli4_cfg_mhdr));
  11027. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11028. LPFC_MBOX_OPCODE_MQ_CREATE,
  11029. length, LPFC_SLI4_MBX_EMBED);
  11030. mq_create = &mbox->u.mqe.un.mq_create;
  11031. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  11032. mq->page_count);
  11033. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  11034. cq->queue_id);
  11035. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  11036. switch (mq->entry_count) {
  11037. case 16:
  11038. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11039. LPFC_MQ_RING_SIZE_16);
  11040. break;
  11041. case 32:
  11042. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11043. LPFC_MQ_RING_SIZE_32);
  11044. break;
  11045. case 64:
  11046. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11047. LPFC_MQ_RING_SIZE_64);
  11048. break;
  11049. case 128:
  11050. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  11051. LPFC_MQ_RING_SIZE_128);
  11052. break;
  11053. }
  11054. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11055. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11056. putPaddrLow(dmabuf->phys);
  11057. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11058. putPaddrHigh(dmabuf->phys);
  11059. }
  11060. }
  11061. /**
  11062. * lpfc_mq_create - Create a mailbox Queue on the HBA
  11063. * @phba: HBA structure that indicates port to create a queue on.
  11064. * @mq: The queue structure to use to create the mailbox queue.
  11065. * @cq: The completion queue to associate with this cq.
  11066. * @subtype: The queue's subtype.
  11067. *
  11068. * This function creates a mailbox queue, as detailed in @mq, on a port,
  11069. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  11070. *
  11071. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  11072. * is used to get the entry count and entry size that are necessary to
  11073. * determine the number of pages to allocate and use for this queue. This
  11074. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  11075. * mailbox queue. This function is asynchronous and will wait for the mailbox
  11076. * command to finish before continuing.
  11077. *
  11078. * On success this function will return a zero. If unable to allocate enough
  11079. * memory this function will return -ENOMEM. If the queue create mailbox command
  11080. * fails this function will return -ENXIO.
  11081. **/
  11082. int32_t
  11083. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  11084. struct lpfc_queue *cq, uint32_t subtype)
  11085. {
  11086. struct lpfc_mbx_mq_create *mq_create;
  11087. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  11088. struct lpfc_dmabuf *dmabuf;
  11089. LPFC_MBOXQ_t *mbox;
  11090. int rc, length, status = 0;
  11091. uint32_t shdr_status, shdr_add_status;
  11092. union lpfc_sli4_cfg_shdr *shdr;
  11093. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11094. /* sanity check on queue memory */
  11095. if (!mq || !cq)
  11096. return -ENODEV;
  11097. if (!phba->sli4_hba.pc_sli4_params.supported)
  11098. hw_page_size = SLI4_PAGE_SIZE;
  11099. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11100. if (!mbox)
  11101. return -ENOMEM;
  11102. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  11103. sizeof(struct lpfc_sli4_cfg_mhdr));
  11104. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11105. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  11106. length, LPFC_SLI4_MBX_EMBED);
  11107. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  11108. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  11109. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  11110. &mq_create_ext->u.request, mq->page_count);
  11111. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  11112. &mq_create_ext->u.request, 1);
  11113. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  11114. &mq_create_ext->u.request, 1);
  11115. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  11116. &mq_create_ext->u.request, 1);
  11117. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  11118. &mq_create_ext->u.request, 1);
  11119. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  11120. &mq_create_ext->u.request, 1);
  11121. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  11122. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11123. phba->sli4_hba.pc_sli4_params.mqv);
  11124. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  11125. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  11126. cq->queue_id);
  11127. else
  11128. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  11129. cq->queue_id);
  11130. switch (mq->entry_count) {
  11131. default:
  11132. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11133. "0362 Unsupported MQ count. (%d)\n",
  11134. mq->entry_count);
  11135. if (mq->entry_count < 16)
  11136. return -EINVAL;
  11137. /* otherwise default to smallest count (drop through) */
  11138. case 16:
  11139. bf_set(lpfc_mq_context_ring_size,
  11140. &mq_create_ext->u.request.context,
  11141. LPFC_MQ_RING_SIZE_16);
  11142. break;
  11143. case 32:
  11144. bf_set(lpfc_mq_context_ring_size,
  11145. &mq_create_ext->u.request.context,
  11146. LPFC_MQ_RING_SIZE_32);
  11147. break;
  11148. case 64:
  11149. bf_set(lpfc_mq_context_ring_size,
  11150. &mq_create_ext->u.request.context,
  11151. LPFC_MQ_RING_SIZE_64);
  11152. break;
  11153. case 128:
  11154. bf_set(lpfc_mq_context_ring_size,
  11155. &mq_create_ext->u.request.context,
  11156. LPFC_MQ_RING_SIZE_128);
  11157. break;
  11158. }
  11159. list_for_each_entry(dmabuf, &mq->page_list, list) {
  11160. memset(dmabuf->virt, 0, hw_page_size);
  11161. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  11162. putPaddrLow(dmabuf->phys);
  11163. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  11164. putPaddrHigh(dmabuf->phys);
  11165. }
  11166. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11167. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11168. &mq_create_ext->u.response);
  11169. if (rc != MBX_SUCCESS) {
  11170. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  11171. "2795 MQ_CREATE_EXT failed with "
  11172. "status x%x. Failback to MQ_CREATE.\n",
  11173. rc);
  11174. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  11175. mq_create = &mbox->u.mqe.un.mq_create;
  11176. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11177. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  11178. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  11179. &mq_create->u.response);
  11180. }
  11181. /* The IOCTL status is embedded in the mailbox subheader. */
  11182. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11183. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11184. if (shdr_status || shdr_add_status || rc) {
  11185. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11186. "2502 MQ_CREATE mailbox failed with "
  11187. "status x%x add_status x%x, mbx status x%x\n",
  11188. shdr_status, shdr_add_status, rc);
  11189. status = -ENXIO;
  11190. goto out;
  11191. }
  11192. if (mq->queue_id == 0xFFFF) {
  11193. status = -ENXIO;
  11194. goto out;
  11195. }
  11196. mq->type = LPFC_MQ;
  11197. mq->assoc_qid = cq->queue_id;
  11198. mq->subtype = subtype;
  11199. mq->host_index = 0;
  11200. mq->hba_index = 0;
  11201. /* link the mq onto the parent cq child list */
  11202. list_add_tail(&mq->list, &cq->child_list);
  11203. out:
  11204. mempool_free(mbox, phba->mbox_mem_pool);
  11205. return status;
  11206. }
  11207. /**
  11208. * lpfc_wq_create - Create a Work Queue on the HBA
  11209. * @phba: HBA structure that indicates port to create a queue on.
  11210. * @wq: The queue structure to use to create the work queue.
  11211. * @cq: The completion queue to bind this work queue to.
  11212. * @subtype: The subtype of the work queue indicating its functionality.
  11213. *
  11214. * This function creates a work queue, as detailed in @wq, on a port, described
  11215. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  11216. *
  11217. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  11218. * is used to get the entry count and entry size that are necessary to
  11219. * determine the number of pages to allocate and use for this queue. The @cq
  11220. * is used to indicate which completion queue to bind this work queue to. This
  11221. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  11222. * work queue. This function is asynchronous and will wait for the mailbox
  11223. * command to finish before continuing.
  11224. *
  11225. * On success this function will return a zero. If unable to allocate enough
  11226. * memory this function will return -ENOMEM. If the queue create mailbox command
  11227. * fails this function will return -ENXIO.
  11228. **/
  11229. uint32_t
  11230. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  11231. struct lpfc_queue *cq, uint32_t subtype)
  11232. {
  11233. struct lpfc_mbx_wq_create *wq_create;
  11234. struct lpfc_dmabuf *dmabuf;
  11235. LPFC_MBOXQ_t *mbox;
  11236. int rc, length, status = 0;
  11237. uint32_t shdr_status, shdr_add_status;
  11238. union lpfc_sli4_cfg_shdr *shdr;
  11239. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11240. struct dma_address *page;
  11241. /* sanity check on queue memory */
  11242. if (!wq || !cq)
  11243. return -ENODEV;
  11244. if (!phba->sli4_hba.pc_sli4_params.supported)
  11245. hw_page_size = SLI4_PAGE_SIZE;
  11246. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11247. if (!mbox)
  11248. return -ENOMEM;
  11249. length = (sizeof(struct lpfc_mbx_wq_create) -
  11250. sizeof(struct lpfc_sli4_cfg_mhdr));
  11251. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11252. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  11253. length, LPFC_SLI4_MBX_EMBED);
  11254. wq_create = &mbox->u.mqe.un.wq_create;
  11255. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  11256. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  11257. wq->page_count);
  11258. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  11259. cq->queue_id);
  11260. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11261. phba->sli4_hba.pc_sli4_params.wqv);
  11262. if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) {
  11263. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  11264. wq->entry_count);
  11265. switch (wq->entry_size) {
  11266. default:
  11267. case 64:
  11268. bf_set(lpfc_mbx_wq_create_wqe_size,
  11269. &wq_create->u.request_1,
  11270. LPFC_WQ_WQE_SIZE_64);
  11271. break;
  11272. case 128:
  11273. bf_set(lpfc_mbx_wq_create_wqe_size,
  11274. &wq_create->u.request_1,
  11275. LPFC_WQ_WQE_SIZE_128);
  11276. break;
  11277. }
  11278. bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1,
  11279. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11280. page = wq_create->u.request_1.page;
  11281. } else {
  11282. page = wq_create->u.request.page;
  11283. }
  11284. list_for_each_entry(dmabuf, &wq->page_list, list) {
  11285. memset(dmabuf->virt, 0, hw_page_size);
  11286. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  11287. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  11288. }
  11289. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11290. /* The IOCTL status is embedded in the mailbox subheader. */
  11291. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11292. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11293. if (shdr_status || shdr_add_status || rc) {
  11294. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11295. "2503 WQ_CREATE mailbox failed with "
  11296. "status x%x add_status x%x, mbx status x%x\n",
  11297. shdr_status, shdr_add_status, rc);
  11298. status = -ENXIO;
  11299. goto out;
  11300. }
  11301. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
  11302. if (wq->queue_id == 0xFFFF) {
  11303. status = -ENXIO;
  11304. goto out;
  11305. }
  11306. wq->type = LPFC_WQ;
  11307. wq->assoc_qid = cq->queue_id;
  11308. wq->subtype = subtype;
  11309. wq->host_index = 0;
  11310. wq->hba_index = 0;
  11311. wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
  11312. /* link the wq onto the parent cq child list */
  11313. list_add_tail(&wq->list, &cq->child_list);
  11314. out:
  11315. mempool_free(mbox, phba->mbox_mem_pool);
  11316. return status;
  11317. }
  11318. /**
  11319. * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
  11320. * @phba: HBA structure that indicates port to create a queue on.
  11321. * @rq: The queue structure to use for the receive queue.
  11322. * @qno: The associated HBQ number
  11323. *
  11324. *
  11325. * For SLI4 we need to adjust the RQ repost value based on
  11326. * the number of buffers that are initially posted to the RQ.
  11327. */
  11328. void
  11329. lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
  11330. {
  11331. uint32_t cnt;
  11332. /* sanity check on queue memory */
  11333. if (!rq)
  11334. return;
  11335. cnt = lpfc_hbq_defs[qno]->entry_count;
  11336. /* Recalc repost for RQs based on buffers initially posted */
  11337. cnt = (cnt >> 3);
  11338. if (cnt < LPFC_QUEUE_MIN_REPOST)
  11339. cnt = LPFC_QUEUE_MIN_REPOST;
  11340. rq->entry_repost = cnt;
  11341. }
  11342. /**
  11343. * lpfc_rq_create - Create a Receive Queue on the HBA
  11344. * @phba: HBA structure that indicates port to create a queue on.
  11345. * @hrq: The queue structure to use to create the header receive queue.
  11346. * @drq: The queue structure to use to create the data receive queue.
  11347. * @cq: The completion queue to bind this work queue to.
  11348. *
  11349. * This function creates a receive buffer queue pair , as detailed in @hrq and
  11350. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  11351. * to the HBA.
  11352. *
  11353. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  11354. * struct is used to get the entry count that is necessary to determine the
  11355. * number of pages to use for this queue. The @cq is used to indicate which
  11356. * completion queue to bind received buffers that are posted to these queues to.
  11357. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  11358. * receive queue pair. This function is asynchronous and will wait for the
  11359. * mailbox command to finish before continuing.
  11360. *
  11361. * On success this function will return a zero. If unable to allocate enough
  11362. * memory this function will return -ENOMEM. If the queue create mailbox command
  11363. * fails this function will return -ENXIO.
  11364. **/
  11365. uint32_t
  11366. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11367. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  11368. {
  11369. struct lpfc_mbx_rq_create *rq_create;
  11370. struct lpfc_dmabuf *dmabuf;
  11371. LPFC_MBOXQ_t *mbox;
  11372. int rc, length, status = 0;
  11373. uint32_t shdr_status, shdr_add_status;
  11374. union lpfc_sli4_cfg_shdr *shdr;
  11375. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  11376. /* sanity check on queue memory */
  11377. if (!hrq || !drq || !cq)
  11378. return -ENODEV;
  11379. if (!phba->sli4_hba.pc_sli4_params.supported)
  11380. hw_page_size = SLI4_PAGE_SIZE;
  11381. if (hrq->entry_count != drq->entry_count)
  11382. return -EINVAL;
  11383. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11384. if (!mbox)
  11385. return -ENOMEM;
  11386. length = (sizeof(struct lpfc_mbx_rq_create) -
  11387. sizeof(struct lpfc_sli4_cfg_mhdr));
  11388. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11389. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11390. length, LPFC_SLI4_MBX_EMBED);
  11391. rq_create = &mbox->u.mqe.un.rq_create;
  11392. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11393. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11394. phba->sli4_hba.pc_sli4_params.rqv);
  11395. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11396. bf_set(lpfc_rq_context_rqe_count_1,
  11397. &rq_create->u.request.context,
  11398. hrq->entry_count);
  11399. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  11400. bf_set(lpfc_rq_context_rqe_size,
  11401. &rq_create->u.request.context,
  11402. LPFC_RQE_SIZE_8);
  11403. bf_set(lpfc_rq_context_page_size,
  11404. &rq_create->u.request.context,
  11405. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11406. } else {
  11407. switch (hrq->entry_count) {
  11408. default:
  11409. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11410. "2535 Unsupported RQ count. (%d)\n",
  11411. hrq->entry_count);
  11412. if (hrq->entry_count < 512)
  11413. return -EINVAL;
  11414. /* otherwise default to smallest count (drop through) */
  11415. case 512:
  11416. bf_set(lpfc_rq_context_rqe_count,
  11417. &rq_create->u.request.context,
  11418. LPFC_RQ_RING_SIZE_512);
  11419. break;
  11420. case 1024:
  11421. bf_set(lpfc_rq_context_rqe_count,
  11422. &rq_create->u.request.context,
  11423. LPFC_RQ_RING_SIZE_1024);
  11424. break;
  11425. case 2048:
  11426. bf_set(lpfc_rq_context_rqe_count,
  11427. &rq_create->u.request.context,
  11428. LPFC_RQ_RING_SIZE_2048);
  11429. break;
  11430. case 4096:
  11431. bf_set(lpfc_rq_context_rqe_count,
  11432. &rq_create->u.request.context,
  11433. LPFC_RQ_RING_SIZE_4096);
  11434. break;
  11435. }
  11436. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11437. LPFC_HDR_BUF_SIZE);
  11438. }
  11439. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11440. cq->queue_id);
  11441. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11442. hrq->page_count);
  11443. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  11444. memset(dmabuf->virt, 0, hw_page_size);
  11445. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11446. putPaddrLow(dmabuf->phys);
  11447. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11448. putPaddrHigh(dmabuf->phys);
  11449. }
  11450. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11451. /* The IOCTL status is embedded in the mailbox subheader. */
  11452. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11453. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11454. if (shdr_status || shdr_add_status || rc) {
  11455. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11456. "2504 RQ_CREATE mailbox failed with "
  11457. "status x%x add_status x%x, mbx status x%x\n",
  11458. shdr_status, shdr_add_status, rc);
  11459. status = -ENXIO;
  11460. goto out;
  11461. }
  11462. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11463. if (hrq->queue_id == 0xFFFF) {
  11464. status = -ENXIO;
  11465. goto out;
  11466. }
  11467. hrq->type = LPFC_HRQ;
  11468. hrq->assoc_qid = cq->queue_id;
  11469. hrq->subtype = subtype;
  11470. hrq->host_index = 0;
  11471. hrq->hba_index = 0;
  11472. /* now create the data queue */
  11473. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11474. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  11475. length, LPFC_SLI4_MBX_EMBED);
  11476. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  11477. phba->sli4_hba.pc_sli4_params.rqv);
  11478. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  11479. bf_set(lpfc_rq_context_rqe_count_1,
  11480. &rq_create->u.request.context, hrq->entry_count);
  11481. rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
  11482. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  11483. LPFC_RQE_SIZE_8);
  11484. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  11485. (PAGE_SIZE/SLI4_PAGE_SIZE));
  11486. } else {
  11487. switch (drq->entry_count) {
  11488. default:
  11489. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11490. "2536 Unsupported RQ count. (%d)\n",
  11491. drq->entry_count);
  11492. if (drq->entry_count < 512)
  11493. return -EINVAL;
  11494. /* otherwise default to smallest count (drop through) */
  11495. case 512:
  11496. bf_set(lpfc_rq_context_rqe_count,
  11497. &rq_create->u.request.context,
  11498. LPFC_RQ_RING_SIZE_512);
  11499. break;
  11500. case 1024:
  11501. bf_set(lpfc_rq_context_rqe_count,
  11502. &rq_create->u.request.context,
  11503. LPFC_RQ_RING_SIZE_1024);
  11504. break;
  11505. case 2048:
  11506. bf_set(lpfc_rq_context_rqe_count,
  11507. &rq_create->u.request.context,
  11508. LPFC_RQ_RING_SIZE_2048);
  11509. break;
  11510. case 4096:
  11511. bf_set(lpfc_rq_context_rqe_count,
  11512. &rq_create->u.request.context,
  11513. LPFC_RQ_RING_SIZE_4096);
  11514. break;
  11515. }
  11516. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  11517. LPFC_DATA_BUF_SIZE);
  11518. }
  11519. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  11520. cq->queue_id);
  11521. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  11522. drq->page_count);
  11523. list_for_each_entry(dmabuf, &drq->page_list, list) {
  11524. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  11525. putPaddrLow(dmabuf->phys);
  11526. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  11527. putPaddrHigh(dmabuf->phys);
  11528. }
  11529. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11530. /* The IOCTL status is embedded in the mailbox subheader. */
  11531. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  11532. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11533. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11534. if (shdr_status || shdr_add_status || rc) {
  11535. status = -ENXIO;
  11536. goto out;
  11537. }
  11538. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  11539. if (drq->queue_id == 0xFFFF) {
  11540. status = -ENXIO;
  11541. goto out;
  11542. }
  11543. drq->type = LPFC_DRQ;
  11544. drq->assoc_qid = cq->queue_id;
  11545. drq->subtype = subtype;
  11546. drq->host_index = 0;
  11547. drq->hba_index = 0;
  11548. /* link the header and data RQs onto the parent cq child list */
  11549. list_add_tail(&hrq->list, &cq->child_list);
  11550. list_add_tail(&drq->list, &cq->child_list);
  11551. out:
  11552. mempool_free(mbox, phba->mbox_mem_pool);
  11553. return status;
  11554. }
  11555. /**
  11556. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  11557. * @eq: The queue structure associated with the queue to destroy.
  11558. *
  11559. * This function destroys a queue, as detailed in @eq by sending an mailbox
  11560. * command, specific to the type of queue, to the HBA.
  11561. *
  11562. * The @eq struct is used to get the queue ID of the queue to destroy.
  11563. *
  11564. * On success this function will return a zero. If the queue destroy mailbox
  11565. * command fails this function will return -ENXIO.
  11566. **/
  11567. uint32_t
  11568. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  11569. {
  11570. LPFC_MBOXQ_t *mbox;
  11571. int rc, length, status = 0;
  11572. uint32_t shdr_status, shdr_add_status;
  11573. union lpfc_sli4_cfg_shdr *shdr;
  11574. /* sanity check on queue memory */
  11575. if (!eq)
  11576. return -ENODEV;
  11577. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  11578. if (!mbox)
  11579. return -ENOMEM;
  11580. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  11581. sizeof(struct lpfc_sli4_cfg_mhdr));
  11582. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11583. LPFC_MBOX_OPCODE_EQ_DESTROY,
  11584. length, LPFC_SLI4_MBX_EMBED);
  11585. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  11586. eq->queue_id);
  11587. mbox->vport = eq->phba->pport;
  11588. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11589. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  11590. /* The IOCTL status is embedded in the mailbox subheader. */
  11591. shdr = (union lpfc_sli4_cfg_shdr *)
  11592. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  11593. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11594. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11595. if (shdr_status || shdr_add_status || rc) {
  11596. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11597. "2505 EQ_DESTROY mailbox failed with "
  11598. "status x%x add_status x%x, mbx status x%x\n",
  11599. shdr_status, shdr_add_status, rc);
  11600. status = -ENXIO;
  11601. }
  11602. /* Remove eq from any list */
  11603. list_del_init(&eq->list);
  11604. mempool_free(mbox, eq->phba->mbox_mem_pool);
  11605. return status;
  11606. }
  11607. /**
  11608. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  11609. * @cq: The queue structure associated with the queue to destroy.
  11610. *
  11611. * This function destroys a queue, as detailed in @cq by sending an mailbox
  11612. * command, specific to the type of queue, to the HBA.
  11613. *
  11614. * The @cq struct is used to get the queue ID of the queue to destroy.
  11615. *
  11616. * On success this function will return a zero. If the queue destroy mailbox
  11617. * command fails this function will return -ENXIO.
  11618. **/
  11619. uint32_t
  11620. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  11621. {
  11622. LPFC_MBOXQ_t *mbox;
  11623. int rc, length, status = 0;
  11624. uint32_t shdr_status, shdr_add_status;
  11625. union lpfc_sli4_cfg_shdr *shdr;
  11626. /* sanity check on queue memory */
  11627. if (!cq)
  11628. return -ENODEV;
  11629. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  11630. if (!mbox)
  11631. return -ENOMEM;
  11632. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  11633. sizeof(struct lpfc_sli4_cfg_mhdr));
  11634. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11635. LPFC_MBOX_OPCODE_CQ_DESTROY,
  11636. length, LPFC_SLI4_MBX_EMBED);
  11637. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  11638. cq->queue_id);
  11639. mbox->vport = cq->phba->pport;
  11640. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11641. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  11642. /* The IOCTL status is embedded in the mailbox subheader. */
  11643. shdr = (union lpfc_sli4_cfg_shdr *)
  11644. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  11645. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11646. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11647. if (shdr_status || shdr_add_status || rc) {
  11648. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11649. "2506 CQ_DESTROY mailbox failed with "
  11650. "status x%x add_status x%x, mbx status x%x\n",
  11651. shdr_status, shdr_add_status, rc);
  11652. status = -ENXIO;
  11653. }
  11654. /* Remove cq from any list */
  11655. list_del_init(&cq->list);
  11656. mempool_free(mbox, cq->phba->mbox_mem_pool);
  11657. return status;
  11658. }
  11659. /**
  11660. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  11661. * @qm: The queue structure associated with the queue to destroy.
  11662. *
  11663. * This function destroys a queue, as detailed in @mq by sending an mailbox
  11664. * command, specific to the type of queue, to the HBA.
  11665. *
  11666. * The @mq struct is used to get the queue ID of the queue to destroy.
  11667. *
  11668. * On success this function will return a zero. If the queue destroy mailbox
  11669. * command fails this function will return -ENXIO.
  11670. **/
  11671. uint32_t
  11672. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  11673. {
  11674. LPFC_MBOXQ_t *mbox;
  11675. int rc, length, status = 0;
  11676. uint32_t shdr_status, shdr_add_status;
  11677. union lpfc_sli4_cfg_shdr *shdr;
  11678. /* sanity check on queue memory */
  11679. if (!mq)
  11680. return -ENODEV;
  11681. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  11682. if (!mbox)
  11683. return -ENOMEM;
  11684. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  11685. sizeof(struct lpfc_sli4_cfg_mhdr));
  11686. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  11687. LPFC_MBOX_OPCODE_MQ_DESTROY,
  11688. length, LPFC_SLI4_MBX_EMBED);
  11689. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  11690. mq->queue_id);
  11691. mbox->vport = mq->phba->pport;
  11692. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11693. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  11694. /* The IOCTL status is embedded in the mailbox subheader. */
  11695. shdr = (union lpfc_sli4_cfg_shdr *)
  11696. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  11697. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11698. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11699. if (shdr_status || shdr_add_status || rc) {
  11700. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11701. "2507 MQ_DESTROY mailbox failed with "
  11702. "status x%x add_status x%x, mbx status x%x\n",
  11703. shdr_status, shdr_add_status, rc);
  11704. status = -ENXIO;
  11705. }
  11706. /* Remove mq from any list */
  11707. list_del_init(&mq->list);
  11708. mempool_free(mbox, mq->phba->mbox_mem_pool);
  11709. return status;
  11710. }
  11711. /**
  11712. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  11713. * @wq: The queue structure associated with the queue to destroy.
  11714. *
  11715. * This function destroys a queue, as detailed in @wq by sending an mailbox
  11716. * command, specific to the type of queue, to the HBA.
  11717. *
  11718. * The @wq struct is used to get the queue ID of the queue to destroy.
  11719. *
  11720. * On success this function will return a zero. If the queue destroy mailbox
  11721. * command fails this function will return -ENXIO.
  11722. **/
  11723. uint32_t
  11724. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  11725. {
  11726. LPFC_MBOXQ_t *mbox;
  11727. int rc, length, status = 0;
  11728. uint32_t shdr_status, shdr_add_status;
  11729. union lpfc_sli4_cfg_shdr *shdr;
  11730. /* sanity check on queue memory */
  11731. if (!wq)
  11732. return -ENODEV;
  11733. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  11734. if (!mbox)
  11735. return -ENOMEM;
  11736. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  11737. sizeof(struct lpfc_sli4_cfg_mhdr));
  11738. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11739. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  11740. length, LPFC_SLI4_MBX_EMBED);
  11741. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  11742. wq->queue_id);
  11743. mbox->vport = wq->phba->pport;
  11744. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11745. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  11746. shdr = (union lpfc_sli4_cfg_shdr *)
  11747. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  11748. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11749. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11750. if (shdr_status || shdr_add_status || rc) {
  11751. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11752. "2508 WQ_DESTROY mailbox failed with "
  11753. "status x%x add_status x%x, mbx status x%x\n",
  11754. shdr_status, shdr_add_status, rc);
  11755. status = -ENXIO;
  11756. }
  11757. /* Remove wq from any list */
  11758. list_del_init(&wq->list);
  11759. mempool_free(mbox, wq->phba->mbox_mem_pool);
  11760. return status;
  11761. }
  11762. /**
  11763. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  11764. * @rq: The queue structure associated with the queue to destroy.
  11765. *
  11766. * This function destroys a queue, as detailed in @rq by sending an mailbox
  11767. * command, specific to the type of queue, to the HBA.
  11768. *
  11769. * The @rq struct is used to get the queue ID of the queue to destroy.
  11770. *
  11771. * On success this function will return a zero. If the queue destroy mailbox
  11772. * command fails this function will return -ENXIO.
  11773. **/
  11774. uint32_t
  11775. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  11776. struct lpfc_queue *drq)
  11777. {
  11778. LPFC_MBOXQ_t *mbox;
  11779. int rc, length, status = 0;
  11780. uint32_t shdr_status, shdr_add_status;
  11781. union lpfc_sli4_cfg_shdr *shdr;
  11782. /* sanity check on queue memory */
  11783. if (!hrq || !drq)
  11784. return -ENODEV;
  11785. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  11786. if (!mbox)
  11787. return -ENOMEM;
  11788. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  11789. sizeof(struct lpfc_sli4_cfg_mhdr));
  11790. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11791. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  11792. length, LPFC_SLI4_MBX_EMBED);
  11793. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  11794. hrq->queue_id);
  11795. mbox->vport = hrq->phba->pport;
  11796. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11797. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  11798. /* The IOCTL status is embedded in the mailbox subheader. */
  11799. shdr = (union lpfc_sli4_cfg_shdr *)
  11800. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  11801. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11802. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11803. if (shdr_status || shdr_add_status || rc) {
  11804. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11805. "2509 RQ_DESTROY mailbox failed with "
  11806. "status x%x add_status x%x, mbx status x%x\n",
  11807. shdr_status, shdr_add_status, rc);
  11808. if (rc != MBX_TIMEOUT)
  11809. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  11810. return -ENXIO;
  11811. }
  11812. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  11813. drq->queue_id);
  11814. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  11815. shdr = (union lpfc_sli4_cfg_shdr *)
  11816. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  11817. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11818. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11819. if (shdr_status || shdr_add_status || rc) {
  11820. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11821. "2510 RQ_DESTROY mailbox failed with "
  11822. "status x%x add_status x%x, mbx status x%x\n",
  11823. shdr_status, shdr_add_status, rc);
  11824. status = -ENXIO;
  11825. }
  11826. list_del_init(&hrq->list);
  11827. list_del_init(&drq->list);
  11828. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  11829. return status;
  11830. }
  11831. /**
  11832. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  11833. * @phba: The virtual port for which this call being executed.
  11834. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  11835. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  11836. * @xritag: the xritag that ties this io to the SGL pages.
  11837. *
  11838. * This routine will post the sgl pages for the IO that has the xritag
  11839. * that is in the iocbq structure. The xritag is assigned during iocbq
  11840. * creation and persists for as long as the driver is loaded.
  11841. * if the caller has fewer than 256 scatter gather segments to map then
  11842. * pdma_phys_addr1 should be 0.
  11843. * If the caller needs to map more than 256 scatter gather segment then
  11844. * pdma_phys_addr1 should be a valid physical address.
  11845. * physical address for SGLs must be 64 byte aligned.
  11846. * If you are going to map 2 SGL's then the first one must have 256 entries
  11847. * the second sgl can have between 1 and 256 entries.
  11848. *
  11849. * Return codes:
  11850. * 0 - Success
  11851. * -ENXIO, -ENOMEM - Failure
  11852. **/
  11853. int
  11854. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  11855. dma_addr_t pdma_phys_addr0,
  11856. dma_addr_t pdma_phys_addr1,
  11857. uint16_t xritag)
  11858. {
  11859. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  11860. LPFC_MBOXQ_t *mbox;
  11861. int rc;
  11862. uint32_t shdr_status, shdr_add_status;
  11863. uint32_t mbox_tmo;
  11864. union lpfc_sli4_cfg_shdr *shdr;
  11865. if (xritag == NO_XRI) {
  11866. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11867. "0364 Invalid param:\n");
  11868. return -EINVAL;
  11869. }
  11870. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  11871. if (!mbox)
  11872. return -ENOMEM;
  11873. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  11874. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  11875. sizeof(struct lpfc_mbx_post_sgl_pages) -
  11876. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  11877. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  11878. &mbox->u.mqe.un.post_sgl_pages;
  11879. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  11880. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  11881. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  11882. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  11883. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  11884. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  11885. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  11886. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  11887. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  11888. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  11889. if (!phba->sli4_hba.intr_enable)
  11890. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  11891. else {
  11892. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  11893. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  11894. }
  11895. /* The IOCTL status is embedded in the mailbox subheader. */
  11896. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  11897. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  11898. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  11899. if (rc != MBX_TIMEOUT)
  11900. mempool_free(mbox, phba->mbox_mem_pool);
  11901. if (shdr_status || shdr_add_status || rc) {
  11902. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  11903. "2511 POST_SGL mailbox failed with "
  11904. "status x%x add_status x%x, mbx status x%x\n",
  11905. shdr_status, shdr_add_status, rc);
  11906. rc = -ENXIO;
  11907. }
  11908. return 0;
  11909. }
  11910. /**
  11911. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  11912. * @phba: pointer to lpfc hba data structure.
  11913. *
  11914. * This routine is invoked to post rpi header templates to the
  11915. * HBA consistent with the SLI-4 interface spec. This routine
  11916. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  11917. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  11918. *
  11919. * Returns
  11920. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  11921. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  11922. **/
  11923. uint16_t
  11924. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  11925. {
  11926. unsigned long xri;
  11927. /*
  11928. * Fetch the next logical xri. Because this index is logical,
  11929. * the driver starts at 0 each time.
  11930. */
  11931. spin_lock_irq(&phba->hbalock);
  11932. xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
  11933. phba->sli4_hba.max_cfg_param.max_xri, 0);
  11934. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  11935. spin_unlock_irq(&phba->hbalock);
  11936. return NO_XRI;
  11937. } else {
  11938. set_bit(xri, phba->sli4_hba.xri_bmask);
  11939. phba->sli4_hba.max_cfg_param.xri_used++;
  11940. phba->sli4_hba.xri_count++;
  11941. }
  11942. spin_unlock_irq(&phba->hbalock);
  11943. return xri;
  11944. }
  11945. /**
  11946. * lpfc_sli4_free_xri - Release an xri for reuse.
  11947. * @phba: pointer to lpfc hba data structure.
  11948. *
  11949. * This routine is invoked to release an xri to the pool of
  11950. * available rpis maintained by the driver.
  11951. **/
  11952. void
  11953. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  11954. {
  11955. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  11956. phba->sli4_hba.xri_count--;
  11957. phba->sli4_hba.max_cfg_param.xri_used--;
  11958. }
  11959. }
  11960. /**
  11961. * lpfc_sli4_free_xri - Release an xri for reuse.
  11962. * @phba: pointer to lpfc hba data structure.
  11963. *
  11964. * This routine is invoked to release an xri to the pool of
  11965. * available rpis maintained by the driver.
  11966. **/
  11967. void
  11968. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  11969. {
  11970. spin_lock_irq(&phba->hbalock);
  11971. __lpfc_sli4_free_xri(phba, xri);
  11972. spin_unlock_irq(&phba->hbalock);
  11973. }
  11974. /**
  11975. * lpfc_sli4_next_xritag - Get an xritag for the io
  11976. * @phba: Pointer to HBA context object.
  11977. *
  11978. * This function gets an xritag for the iocb. If there is no unused xritag
  11979. * it will return 0xffff.
  11980. * The function returns the allocated xritag if successful, else returns zero.
  11981. * Zero is not a valid xritag.
  11982. * The caller is not required to hold any lock.
  11983. **/
  11984. uint16_t
  11985. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  11986. {
  11987. uint16_t xri_index;
  11988. xri_index = lpfc_sli4_alloc_xri(phba);
  11989. if (xri_index != NO_XRI)
  11990. return xri_index;
  11991. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  11992. "2004 Failed to allocate XRI.last XRITAG is %d"
  11993. " Max XRI is %d, Used XRI is %d\n",
  11994. xri_index,
  11995. phba->sli4_hba.max_cfg_param.max_xri,
  11996. phba->sli4_hba.max_cfg_param.xri_used);
  11997. return NO_XRI;
  11998. }
  11999. /**
  12000. * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
  12001. * @phba: pointer to lpfc hba data structure.
  12002. *
  12003. * This routine is invoked to post a block of driver's sgl pages to the
  12004. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12005. * is only called when the driver is loading and after all IO has been
  12006. * stopped.
  12007. **/
  12008. int
  12009. lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba)
  12010. {
  12011. struct lpfc_sglq *sglq_entry;
  12012. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12013. struct sgl_page_pairs *sgl_pg_pairs;
  12014. void *viraddr;
  12015. LPFC_MBOXQ_t *mbox;
  12016. uint32_t reqlen, alloclen, pg_pairs;
  12017. uint32_t mbox_tmo;
  12018. uint16_t xritag_start = 0, lxri = 0;
  12019. int els_xri_cnt, rc = 0;
  12020. uint32_t shdr_status, shdr_add_status;
  12021. union lpfc_sli4_cfg_shdr *shdr;
  12022. /* The number of sgls to be posted */
  12023. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  12024. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12025. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12026. if (reqlen > SLI4_PAGE_SIZE) {
  12027. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12028. "2559 Block sgl registration required DMA "
  12029. "size (%d) great than a page\n", reqlen);
  12030. return -ENOMEM;
  12031. }
  12032. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12033. if (!mbox)
  12034. return -ENOMEM;
  12035. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12036. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12037. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12038. LPFC_SLI4_MBX_NEMBED);
  12039. if (alloclen < reqlen) {
  12040. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12041. "0285 Allocated DMA memory size (%d) is "
  12042. "less than the requested DMA memory "
  12043. "size (%d)\n", alloclen, reqlen);
  12044. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12045. return -ENOMEM;
  12046. }
  12047. /* Set up the SGL pages in the non-embedded DMA pages */
  12048. viraddr = mbox->sge_array->addr[0];
  12049. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12050. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12051. for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) {
  12052. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs];
  12053. /*
  12054. * Assign the sglq a physical xri only if the driver has not
  12055. * initialized those resources. A port reset only needs
  12056. * the sglq's posted.
  12057. */
  12058. if (bf_get(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  12059. LPFC_XRI_RSRC_RDY) {
  12060. lxri = lpfc_sli4_next_xritag(phba);
  12061. if (lxri == NO_XRI) {
  12062. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12063. return -ENOMEM;
  12064. }
  12065. sglq_entry->sli4_lxritag = lxri;
  12066. sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  12067. }
  12068. /* Set up the sge entry */
  12069. sgl_pg_pairs->sgl_pg0_addr_lo =
  12070. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12071. sgl_pg_pairs->sgl_pg0_addr_hi =
  12072. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12073. sgl_pg_pairs->sgl_pg1_addr_lo =
  12074. cpu_to_le32(putPaddrLow(0));
  12075. sgl_pg_pairs->sgl_pg1_addr_hi =
  12076. cpu_to_le32(putPaddrHigh(0));
  12077. /* Keep the first xritag on the list */
  12078. if (pg_pairs == 0)
  12079. xritag_start = sglq_entry->sli4_xritag;
  12080. sgl_pg_pairs++;
  12081. }
  12082. /* Complete initialization and perform endian conversion. */
  12083. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12084. bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt);
  12085. sgl->word0 = cpu_to_le32(sgl->word0);
  12086. if (!phba->sli4_hba.intr_enable)
  12087. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12088. else {
  12089. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12090. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12091. }
  12092. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12093. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12094. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12095. if (rc != MBX_TIMEOUT)
  12096. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12097. if (shdr_status || shdr_add_status || rc) {
  12098. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12099. "2513 POST_SGL_BLOCK mailbox command failed "
  12100. "status x%x add_status x%x mbx status x%x\n",
  12101. shdr_status, shdr_add_status, rc);
  12102. rc = -ENXIO;
  12103. }
  12104. if (rc == 0)
  12105. bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  12106. LPFC_XRI_RSRC_RDY);
  12107. return rc;
  12108. }
  12109. /**
  12110. * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port.
  12111. * @phba: pointer to lpfc hba data structure.
  12112. *
  12113. * This routine is invoked to post a block of driver's sgl pages to the
  12114. * HBA using non-embedded mailbox command. No Lock is held. This routine
  12115. * is only called when the driver is loading and after all IO has been
  12116. * stopped.
  12117. **/
  12118. int
  12119. lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba)
  12120. {
  12121. struct lpfc_sglq *sglq_entry;
  12122. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12123. struct sgl_page_pairs *sgl_pg_pairs;
  12124. void *viraddr;
  12125. LPFC_MBOXQ_t *mbox;
  12126. uint32_t reqlen, alloclen, index;
  12127. uint32_t mbox_tmo;
  12128. uint16_t rsrc_start, rsrc_size, els_xri_cnt;
  12129. uint16_t xritag_start = 0, lxri = 0;
  12130. struct lpfc_rsrc_blks *rsrc_blk;
  12131. int cnt, ttl_cnt, rc = 0;
  12132. int loop_cnt;
  12133. uint32_t shdr_status, shdr_add_status;
  12134. union lpfc_sli4_cfg_shdr *shdr;
  12135. /* The number of sgls to be posted */
  12136. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  12137. reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) +
  12138. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12139. if (reqlen > SLI4_PAGE_SIZE) {
  12140. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12141. "2989 Block sgl registration required DMA "
  12142. "size (%d) great than a page\n", reqlen);
  12143. return -ENOMEM;
  12144. }
  12145. cnt = 0;
  12146. ttl_cnt = 0;
  12147. list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list,
  12148. list) {
  12149. rsrc_start = rsrc_blk->rsrc_start;
  12150. rsrc_size = rsrc_blk->rsrc_size;
  12151. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12152. "3014 Working ELS Extent start %d, cnt %d\n",
  12153. rsrc_start, rsrc_size);
  12154. loop_cnt = min(els_xri_cnt, rsrc_size);
  12155. if (ttl_cnt + loop_cnt >= els_xri_cnt) {
  12156. loop_cnt = els_xri_cnt - ttl_cnt;
  12157. ttl_cnt = els_xri_cnt;
  12158. }
  12159. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12160. if (!mbox)
  12161. return -ENOMEM;
  12162. /*
  12163. * Allocate DMA memory and set up the non-embedded mailbox
  12164. * command.
  12165. */
  12166. alloclen = lpfc_sli4_config(phba, mbox,
  12167. LPFC_MBOX_SUBSYSTEM_FCOE,
  12168. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12169. reqlen, LPFC_SLI4_MBX_NEMBED);
  12170. if (alloclen < reqlen) {
  12171. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12172. "2987 Allocated DMA memory size (%d) "
  12173. "is less than the requested DMA memory "
  12174. "size (%d)\n", alloclen, reqlen);
  12175. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12176. return -ENOMEM;
  12177. }
  12178. /* Set up the SGL pages in the non-embedded DMA pages */
  12179. viraddr = mbox->sge_array->addr[0];
  12180. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12181. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12182. /*
  12183. * The starting resource may not begin at zero. Control
  12184. * the loop variants via the block resource parameters,
  12185. * but handle the sge pointers with a zero-based index
  12186. * that doesn't get reset per loop pass.
  12187. */
  12188. for (index = rsrc_start;
  12189. index < rsrc_start + loop_cnt;
  12190. index++) {
  12191. sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[cnt];
  12192. /*
  12193. * Assign the sglq a physical xri only if the driver
  12194. * has not initialized those resources. A port reset
  12195. * only needs the sglq's posted.
  12196. */
  12197. if (bf_get(lpfc_xri_rsrc_rdy,
  12198. &phba->sli4_hba.sli4_flags) !=
  12199. LPFC_XRI_RSRC_RDY) {
  12200. lxri = lpfc_sli4_next_xritag(phba);
  12201. if (lxri == NO_XRI) {
  12202. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12203. rc = -ENOMEM;
  12204. goto err_exit;
  12205. }
  12206. sglq_entry->sli4_lxritag = lxri;
  12207. sglq_entry->sli4_xritag =
  12208. phba->sli4_hba.xri_ids[lxri];
  12209. }
  12210. /* Set up the sge entry */
  12211. sgl_pg_pairs->sgl_pg0_addr_lo =
  12212. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  12213. sgl_pg_pairs->sgl_pg0_addr_hi =
  12214. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  12215. sgl_pg_pairs->sgl_pg1_addr_lo =
  12216. cpu_to_le32(putPaddrLow(0));
  12217. sgl_pg_pairs->sgl_pg1_addr_hi =
  12218. cpu_to_le32(putPaddrHigh(0));
  12219. /* Track the starting physical XRI for the mailbox. */
  12220. if (index == rsrc_start)
  12221. xritag_start = sglq_entry->sli4_xritag;
  12222. sgl_pg_pairs++;
  12223. cnt++;
  12224. }
  12225. /* Complete initialization and perform endian conversion. */
  12226. rsrc_blk->rsrc_used += loop_cnt;
  12227. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12228. bf_set(lpfc_post_sgl_pages_xricnt, sgl, loop_cnt);
  12229. sgl->word0 = cpu_to_le32(sgl->word0);
  12230. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12231. "3015 Post ELS Extent SGL, start %d, "
  12232. "cnt %d, used %d\n",
  12233. xritag_start, loop_cnt, rsrc_blk->rsrc_used);
  12234. if (!phba->sli4_hba.intr_enable)
  12235. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12236. else {
  12237. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12238. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12239. }
  12240. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12241. shdr_status = bf_get(lpfc_mbox_hdr_status,
  12242. &shdr->response);
  12243. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  12244. &shdr->response);
  12245. if (rc != MBX_TIMEOUT)
  12246. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12247. if (shdr_status || shdr_add_status || rc) {
  12248. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12249. "2988 POST_SGL_BLOCK mailbox "
  12250. "command failed status x%x "
  12251. "add_status x%x mbx status x%x\n",
  12252. shdr_status, shdr_add_status, rc);
  12253. rc = -ENXIO;
  12254. goto err_exit;
  12255. }
  12256. if (ttl_cnt >= els_xri_cnt)
  12257. break;
  12258. }
  12259. err_exit:
  12260. if (rc == 0)
  12261. bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  12262. LPFC_XRI_RSRC_RDY);
  12263. return rc;
  12264. }
  12265. /**
  12266. * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
  12267. * @phba: pointer to lpfc hba data structure.
  12268. * @sblist: pointer to scsi buffer list.
  12269. * @count: number of scsi buffers on the list.
  12270. *
  12271. * This routine is invoked to post a block of @count scsi sgl pages from a
  12272. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12273. * No Lock is held.
  12274. *
  12275. **/
  12276. int
  12277. lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist,
  12278. int cnt)
  12279. {
  12280. struct lpfc_scsi_buf *psb;
  12281. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12282. struct sgl_page_pairs *sgl_pg_pairs;
  12283. void *viraddr;
  12284. LPFC_MBOXQ_t *mbox;
  12285. uint32_t reqlen, alloclen, pg_pairs;
  12286. uint32_t mbox_tmo;
  12287. uint16_t xritag_start = 0;
  12288. int rc = 0;
  12289. uint32_t shdr_status, shdr_add_status;
  12290. dma_addr_t pdma_phys_bpl1;
  12291. union lpfc_sli4_cfg_shdr *shdr;
  12292. /* Calculate the requested length of the dma memory */
  12293. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  12294. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12295. if (reqlen > SLI4_PAGE_SIZE) {
  12296. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12297. "0217 Block sgl registration required DMA "
  12298. "size (%d) great than a page\n", reqlen);
  12299. return -ENOMEM;
  12300. }
  12301. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12302. if (!mbox) {
  12303. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12304. "0283 Failed to allocate mbox cmd memory\n");
  12305. return -ENOMEM;
  12306. }
  12307. /* Allocate DMA memory and set up the non-embedded mailbox command */
  12308. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  12309. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  12310. LPFC_SLI4_MBX_NEMBED);
  12311. if (alloclen < reqlen) {
  12312. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12313. "2561 Allocated DMA memory size (%d) is "
  12314. "less than the requested DMA memory "
  12315. "size (%d)\n", alloclen, reqlen);
  12316. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12317. return -ENOMEM;
  12318. }
  12319. /* Get the first SGE entry from the non-embedded DMA memory */
  12320. viraddr = mbox->sge_array->addr[0];
  12321. /* Set up the SGL pages in the non-embedded DMA pages */
  12322. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12323. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12324. pg_pairs = 0;
  12325. list_for_each_entry(psb, sblist, list) {
  12326. /* Set up the sge entry */
  12327. sgl_pg_pairs->sgl_pg0_addr_lo =
  12328. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12329. sgl_pg_pairs->sgl_pg0_addr_hi =
  12330. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12331. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12332. pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
  12333. else
  12334. pdma_phys_bpl1 = 0;
  12335. sgl_pg_pairs->sgl_pg1_addr_lo =
  12336. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12337. sgl_pg_pairs->sgl_pg1_addr_hi =
  12338. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12339. /* Keep the first xritag on the list */
  12340. if (pg_pairs == 0)
  12341. xritag_start = psb->cur_iocbq.sli4_xritag;
  12342. sgl_pg_pairs++;
  12343. pg_pairs++;
  12344. }
  12345. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  12346. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12347. /* Perform endian conversion if necessary */
  12348. sgl->word0 = cpu_to_le32(sgl->word0);
  12349. if (!phba->sli4_hba.intr_enable)
  12350. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12351. else {
  12352. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12353. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12354. }
  12355. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12356. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12357. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  12358. if (rc != MBX_TIMEOUT)
  12359. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12360. if (shdr_status || shdr_add_status || rc) {
  12361. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12362. "2564 POST_SGL_BLOCK mailbox command failed "
  12363. "status x%x add_status x%x mbx status x%x\n",
  12364. shdr_status, shdr_add_status, rc);
  12365. rc = -ENXIO;
  12366. }
  12367. return rc;
  12368. }
  12369. /**
  12370. * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port.
  12371. * @phba: pointer to lpfc hba data structure.
  12372. * @sblist: pointer to scsi buffer list.
  12373. * @count: number of scsi buffers on the list.
  12374. *
  12375. * This routine is invoked to post a block of @count scsi sgl pages from a
  12376. * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
  12377. * No Lock is held.
  12378. *
  12379. **/
  12380. int
  12381. lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *phba, struct list_head *sblist,
  12382. int cnt)
  12383. {
  12384. struct lpfc_scsi_buf *psb = NULL;
  12385. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  12386. struct sgl_page_pairs *sgl_pg_pairs;
  12387. void *viraddr;
  12388. LPFC_MBOXQ_t *mbox;
  12389. uint32_t reqlen, alloclen, pg_pairs;
  12390. uint32_t mbox_tmo;
  12391. uint16_t xri_start = 0, scsi_xri_start;
  12392. uint16_t rsrc_range;
  12393. int rc = 0, avail_cnt;
  12394. uint32_t shdr_status, shdr_add_status;
  12395. dma_addr_t pdma_phys_bpl1;
  12396. union lpfc_sli4_cfg_shdr *shdr;
  12397. struct lpfc_rsrc_blks *rsrc_blk;
  12398. uint32_t xri_cnt = 0;
  12399. /* Calculate the total requested length of the dma memory */
  12400. reqlen = cnt * sizeof(struct sgl_page_pairs) +
  12401. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12402. if (reqlen > SLI4_PAGE_SIZE) {
  12403. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  12404. "2932 Block sgl registration required DMA "
  12405. "size (%d) great than a page\n", reqlen);
  12406. return -ENOMEM;
  12407. }
  12408. /*
  12409. * The use of extents requires the driver to post the sgl headers
  12410. * in multiple postings to meet the contiguous resource assignment.
  12411. */
  12412. psb = list_prepare_entry(psb, sblist, list);
  12413. scsi_xri_start = phba->sli4_hba.scsi_xri_start;
  12414. list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list,
  12415. list) {
  12416. rsrc_range = rsrc_blk->rsrc_start + rsrc_blk->rsrc_size;
  12417. if (rsrc_range < scsi_xri_start)
  12418. continue;
  12419. else if (rsrc_blk->rsrc_used >= rsrc_blk->rsrc_size)
  12420. continue;
  12421. else
  12422. avail_cnt = rsrc_blk->rsrc_size - rsrc_blk->rsrc_used;
  12423. reqlen = (avail_cnt * sizeof(struct sgl_page_pairs)) +
  12424. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  12425. /*
  12426. * Allocate DMA memory and set up the non-embedded mailbox
  12427. * command. The mbox is used to post an SGL page per loop
  12428. * but the DMA memory has a use-once semantic so the mailbox
  12429. * is used and freed per loop pass.
  12430. */
  12431. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  12432. if (!mbox) {
  12433. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12434. "2933 Failed to allocate mbox cmd "
  12435. "memory\n");
  12436. return -ENOMEM;
  12437. }
  12438. alloclen = lpfc_sli4_config(phba, mbox,
  12439. LPFC_MBOX_SUBSYSTEM_FCOE,
  12440. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  12441. reqlen,
  12442. LPFC_SLI4_MBX_NEMBED);
  12443. if (alloclen < reqlen) {
  12444. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  12445. "2934 Allocated DMA memory size (%d) "
  12446. "is less than the requested DMA memory "
  12447. "size (%d)\n", alloclen, reqlen);
  12448. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12449. return -ENOMEM;
  12450. }
  12451. /* Get the first SGE entry from the non-embedded DMA memory */
  12452. viraddr = mbox->sge_array->addr[0];
  12453. /* Set up the SGL pages in the non-embedded DMA pages */
  12454. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  12455. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  12456. /* pg_pairs tracks posted SGEs per loop iteration. */
  12457. pg_pairs = 0;
  12458. list_for_each_entry_continue(psb, sblist, list) {
  12459. /* Set up the sge entry */
  12460. sgl_pg_pairs->sgl_pg0_addr_lo =
  12461. cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
  12462. sgl_pg_pairs->sgl_pg0_addr_hi =
  12463. cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
  12464. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  12465. pdma_phys_bpl1 = psb->dma_phys_bpl +
  12466. SGL_PAGE_SIZE;
  12467. else
  12468. pdma_phys_bpl1 = 0;
  12469. sgl_pg_pairs->sgl_pg1_addr_lo =
  12470. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  12471. sgl_pg_pairs->sgl_pg1_addr_hi =
  12472. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  12473. /* Keep the first xri for this extent. */
  12474. if (pg_pairs == 0)
  12475. xri_start = psb->cur_iocbq.sli4_xritag;
  12476. sgl_pg_pairs++;
  12477. pg_pairs++;
  12478. xri_cnt++;
  12479. /*
  12480. * Track two exit conditions - the loop has constructed
  12481. * all of the caller's SGE pairs or all available
  12482. * resource IDs in this extent are consumed.
  12483. */
  12484. if ((xri_cnt == cnt) || (pg_pairs >= avail_cnt))
  12485. break;
  12486. }
  12487. rsrc_blk->rsrc_used += pg_pairs;
  12488. bf_set(lpfc_post_sgl_pages_xri, sgl, xri_start);
  12489. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  12490. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  12491. "3016 Post SCSI Extent SGL, start %d, cnt %d "
  12492. "blk use %d\n",
  12493. xri_start, pg_pairs, rsrc_blk->rsrc_used);
  12494. /* Perform endian conversion if necessary */
  12495. sgl->word0 = cpu_to_le32(sgl->word0);
  12496. if (!phba->sli4_hba.intr_enable)
  12497. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  12498. else {
  12499. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  12500. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  12501. }
  12502. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  12503. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  12504. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  12505. &shdr->response);
  12506. if (rc != MBX_TIMEOUT)
  12507. lpfc_sli4_mbox_cmd_free(phba, mbox);
  12508. if (shdr_status || shdr_add_status || rc) {
  12509. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12510. "2935 POST_SGL_BLOCK mailbox command "
  12511. "failed status x%x add_status x%x "
  12512. "mbx status x%x\n",
  12513. shdr_status, shdr_add_status, rc);
  12514. return -ENXIO;
  12515. }
  12516. /* Post only what is requested. */
  12517. if (xri_cnt >= cnt)
  12518. break;
  12519. }
  12520. return rc;
  12521. }
  12522. /**
  12523. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  12524. * @phba: pointer to lpfc_hba struct that the frame was received on
  12525. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12526. *
  12527. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  12528. * valid type of frame that the LPFC driver will handle. This function will
  12529. * return a zero if the frame is a valid frame or a non zero value when the
  12530. * frame does not pass the check.
  12531. **/
  12532. static int
  12533. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  12534. {
  12535. /* make rctl_names static to save stack space */
  12536. static char *rctl_names[] = FC_RCTL_NAMES_INIT;
  12537. char *type_names[] = FC_TYPE_NAMES_INIT;
  12538. struct fc_vft_header *fc_vft_hdr;
  12539. uint32_t *header = (uint32_t *) fc_hdr;
  12540. switch (fc_hdr->fh_r_ctl) {
  12541. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  12542. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  12543. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  12544. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  12545. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  12546. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  12547. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  12548. case FC_RCTL_DD_CMD_STATUS: /* command status */
  12549. case FC_RCTL_ELS_REQ: /* extended link services request */
  12550. case FC_RCTL_ELS_REP: /* extended link services reply */
  12551. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  12552. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  12553. case FC_RCTL_BA_NOP: /* basic link service NOP */
  12554. case FC_RCTL_BA_ABTS: /* basic link service abort */
  12555. case FC_RCTL_BA_RMC: /* remove connection */
  12556. case FC_RCTL_BA_ACC: /* basic accept */
  12557. case FC_RCTL_BA_RJT: /* basic reject */
  12558. case FC_RCTL_BA_PRMT:
  12559. case FC_RCTL_ACK_1: /* acknowledge_1 */
  12560. case FC_RCTL_ACK_0: /* acknowledge_0 */
  12561. case FC_RCTL_P_RJT: /* port reject */
  12562. case FC_RCTL_F_RJT: /* fabric reject */
  12563. case FC_RCTL_P_BSY: /* port busy */
  12564. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  12565. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  12566. case FC_RCTL_LCR: /* link credit reset */
  12567. case FC_RCTL_END: /* end */
  12568. break;
  12569. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  12570. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12571. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  12572. return lpfc_fc_frame_check(phba, fc_hdr);
  12573. default:
  12574. goto drop;
  12575. }
  12576. switch (fc_hdr->fh_type) {
  12577. case FC_TYPE_BLS:
  12578. case FC_TYPE_ELS:
  12579. case FC_TYPE_FCP:
  12580. case FC_TYPE_CT:
  12581. break;
  12582. case FC_TYPE_IP:
  12583. case FC_TYPE_ILS:
  12584. default:
  12585. goto drop;
  12586. }
  12587. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  12588. "2538 Received frame rctl:%s type:%s "
  12589. "Frame Data:%08x %08x %08x %08x %08x %08x\n",
  12590. rctl_names[fc_hdr->fh_r_ctl],
  12591. type_names[fc_hdr->fh_type],
  12592. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  12593. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  12594. be32_to_cpu(header[4]), be32_to_cpu(header[5]));
  12595. return 0;
  12596. drop:
  12597. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12598. "2539 Dropped frame rctl:%s type:%s\n",
  12599. rctl_names[fc_hdr->fh_r_ctl],
  12600. type_names[fc_hdr->fh_type]);
  12601. return 1;
  12602. }
  12603. /**
  12604. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  12605. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12606. *
  12607. * This function processes the FC header to retrieve the VFI from the VF
  12608. * header, if one exists. This function will return the VFI if one exists
  12609. * or 0 if no VSAN Header exists.
  12610. **/
  12611. static uint32_t
  12612. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  12613. {
  12614. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  12615. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  12616. return 0;
  12617. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  12618. }
  12619. /**
  12620. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  12621. * @phba: Pointer to the HBA structure to search for the vport on
  12622. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  12623. * @fcfi: The FC Fabric ID that the frame came from
  12624. *
  12625. * This function searches the @phba for a vport that matches the content of the
  12626. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  12627. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  12628. * returns the matching vport pointer or NULL if unable to match frame to a
  12629. * vport.
  12630. **/
  12631. static struct lpfc_vport *
  12632. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  12633. uint16_t fcfi)
  12634. {
  12635. struct lpfc_vport **vports;
  12636. struct lpfc_vport *vport = NULL;
  12637. int i;
  12638. uint32_t did = (fc_hdr->fh_d_id[0] << 16 |
  12639. fc_hdr->fh_d_id[1] << 8 |
  12640. fc_hdr->fh_d_id[2]);
  12641. if (did == Fabric_DID)
  12642. return phba->pport;
  12643. vports = lpfc_create_vport_work_array(phba);
  12644. if (vports != NULL)
  12645. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  12646. if (phba->fcf.fcfi == fcfi &&
  12647. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  12648. vports[i]->fc_myDID == did) {
  12649. vport = vports[i];
  12650. break;
  12651. }
  12652. }
  12653. lpfc_destroy_vport_work_array(phba, vports);
  12654. return vport;
  12655. }
  12656. /**
  12657. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  12658. * @vport: The vport to work on.
  12659. *
  12660. * This function updates the receive sequence time stamp for this vport. The
  12661. * receive sequence time stamp indicates the time that the last frame of the
  12662. * the sequence that has been idle for the longest amount of time was received.
  12663. * the driver uses this time stamp to indicate if any received sequences have
  12664. * timed out.
  12665. **/
  12666. void
  12667. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  12668. {
  12669. struct lpfc_dmabuf *h_buf;
  12670. struct hbq_dmabuf *dmabuf = NULL;
  12671. /* get the oldest sequence on the rcv list */
  12672. h_buf = list_get_first(&vport->rcv_buffer_list,
  12673. struct lpfc_dmabuf, list);
  12674. if (!h_buf)
  12675. return;
  12676. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12677. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  12678. }
  12679. /**
  12680. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  12681. * @vport: The vport that the received sequences were sent to.
  12682. *
  12683. * This function cleans up all outstanding received sequences. This is called
  12684. * by the driver when a link event or user action invalidates all the received
  12685. * sequences.
  12686. **/
  12687. void
  12688. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  12689. {
  12690. struct lpfc_dmabuf *h_buf, *hnext;
  12691. struct lpfc_dmabuf *d_buf, *dnext;
  12692. struct hbq_dmabuf *dmabuf = NULL;
  12693. /* start with the oldest sequence on the rcv list */
  12694. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12695. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12696. list_del_init(&dmabuf->hbuf.list);
  12697. list_for_each_entry_safe(d_buf, dnext,
  12698. &dmabuf->dbuf.list, list) {
  12699. list_del_init(&d_buf->list);
  12700. lpfc_in_buf_free(vport->phba, d_buf);
  12701. }
  12702. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12703. }
  12704. }
  12705. /**
  12706. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  12707. * @vport: The vport that the received sequences were sent to.
  12708. *
  12709. * This function determines whether any received sequences have timed out by
  12710. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  12711. * indicates that there is at least one timed out sequence this routine will
  12712. * go through the received sequences one at a time from most inactive to most
  12713. * active to determine which ones need to be cleaned up. Once it has determined
  12714. * that a sequence needs to be cleaned up it will simply free up the resources
  12715. * without sending an abort.
  12716. **/
  12717. void
  12718. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  12719. {
  12720. struct lpfc_dmabuf *h_buf, *hnext;
  12721. struct lpfc_dmabuf *d_buf, *dnext;
  12722. struct hbq_dmabuf *dmabuf = NULL;
  12723. unsigned long timeout;
  12724. int abort_count = 0;
  12725. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12726. vport->rcv_buffer_time_stamp);
  12727. if (list_empty(&vport->rcv_buffer_list) ||
  12728. time_before(jiffies, timeout))
  12729. return;
  12730. /* start with the oldest sequence on the rcv list */
  12731. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  12732. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12733. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  12734. dmabuf->time_stamp);
  12735. if (time_before(jiffies, timeout))
  12736. break;
  12737. abort_count++;
  12738. list_del_init(&dmabuf->hbuf.list);
  12739. list_for_each_entry_safe(d_buf, dnext,
  12740. &dmabuf->dbuf.list, list) {
  12741. list_del_init(&d_buf->list);
  12742. lpfc_in_buf_free(vport->phba, d_buf);
  12743. }
  12744. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  12745. }
  12746. if (abort_count)
  12747. lpfc_update_rcv_time_stamp(vport);
  12748. }
  12749. /**
  12750. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  12751. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  12752. *
  12753. * This function searches through the existing incomplete sequences that have
  12754. * been sent to this @vport. If the frame matches one of the incomplete
  12755. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  12756. * make up that sequence. If no sequence is found that matches this frame then
  12757. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  12758. * This function returns a pointer to the first dmabuf in the sequence list that
  12759. * the frame was linked to.
  12760. **/
  12761. static struct hbq_dmabuf *
  12762. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  12763. {
  12764. struct fc_frame_header *new_hdr;
  12765. struct fc_frame_header *temp_hdr;
  12766. struct lpfc_dmabuf *d_buf;
  12767. struct lpfc_dmabuf *h_buf;
  12768. struct hbq_dmabuf *seq_dmabuf = NULL;
  12769. struct hbq_dmabuf *temp_dmabuf = NULL;
  12770. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12771. dmabuf->time_stamp = jiffies;
  12772. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12773. /* Use the hdr_buf to find the sequence that this frame belongs to */
  12774. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12775. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12776. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12777. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12778. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12779. continue;
  12780. /* found a pending sequence that matches this frame */
  12781. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12782. break;
  12783. }
  12784. if (!seq_dmabuf) {
  12785. /*
  12786. * This indicates first frame received for this sequence.
  12787. * Queue the buffer on the vport's rcv_buffer_list.
  12788. */
  12789. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12790. lpfc_update_rcv_time_stamp(vport);
  12791. return dmabuf;
  12792. }
  12793. temp_hdr = seq_dmabuf->hbuf.virt;
  12794. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  12795. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12796. list_del_init(&seq_dmabuf->hbuf.list);
  12797. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12798. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12799. lpfc_update_rcv_time_stamp(vport);
  12800. return dmabuf;
  12801. }
  12802. /* move this sequence to the tail to indicate a young sequence */
  12803. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  12804. seq_dmabuf->time_stamp = jiffies;
  12805. lpfc_update_rcv_time_stamp(vport);
  12806. if (list_empty(&seq_dmabuf->dbuf.list)) {
  12807. temp_hdr = dmabuf->hbuf.virt;
  12808. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  12809. return seq_dmabuf;
  12810. }
  12811. /* find the correct place in the sequence to insert this frame */
  12812. list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) {
  12813. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  12814. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  12815. /*
  12816. * If the frame's sequence count is greater than the frame on
  12817. * the list then insert the frame right after this frame
  12818. */
  12819. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  12820. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  12821. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  12822. return seq_dmabuf;
  12823. }
  12824. }
  12825. return NULL;
  12826. }
  12827. /**
  12828. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  12829. * @vport: pointer to a vitural port
  12830. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  12831. *
  12832. * This function tries to abort from the partially assembed sequence, described
  12833. * by the information from basic abbort @dmabuf. It checks to see whether such
  12834. * partially assembled sequence held by the driver. If so, it shall free up all
  12835. * the frames from the partially assembled sequence.
  12836. *
  12837. * Return
  12838. * true -- if there is matching partially assembled sequence present and all
  12839. * the frames freed with the sequence;
  12840. * false -- if there is no matching partially assembled sequence present so
  12841. * nothing got aborted in the lower layer driver
  12842. **/
  12843. static bool
  12844. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  12845. struct hbq_dmabuf *dmabuf)
  12846. {
  12847. struct fc_frame_header *new_hdr;
  12848. struct fc_frame_header *temp_hdr;
  12849. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  12850. struct hbq_dmabuf *seq_dmabuf = NULL;
  12851. /* Use the hdr_buf to find the sequence that matches this frame */
  12852. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  12853. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  12854. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  12855. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  12856. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  12857. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  12858. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  12859. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  12860. continue;
  12861. /* found a pending sequence that matches this frame */
  12862. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  12863. break;
  12864. }
  12865. /* Free up all the frames from the partially assembled sequence */
  12866. if (seq_dmabuf) {
  12867. list_for_each_entry_safe(d_buf, n_buf,
  12868. &seq_dmabuf->dbuf.list, list) {
  12869. list_del_init(&d_buf->list);
  12870. lpfc_in_buf_free(vport->phba, d_buf);
  12871. }
  12872. return true;
  12873. }
  12874. return false;
  12875. }
  12876. /**
  12877. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  12878. * @phba: Pointer to HBA context object.
  12879. * @cmd_iocbq: pointer to the command iocbq structure.
  12880. * @rsp_iocbq: pointer to the response iocbq structure.
  12881. *
  12882. * This function handles the sequence abort response iocb command complete
  12883. * event. It properly releases the memory allocated to the sequence abort
  12884. * accept iocb.
  12885. **/
  12886. static void
  12887. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  12888. struct lpfc_iocbq *cmd_iocbq,
  12889. struct lpfc_iocbq *rsp_iocbq)
  12890. {
  12891. if (cmd_iocbq)
  12892. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  12893. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  12894. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  12895. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  12896. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  12897. rsp_iocbq->iocb.ulpStatus,
  12898. rsp_iocbq->iocb.un.ulpWord[4]);
  12899. }
  12900. /**
  12901. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  12902. * @phba: Pointer to HBA context object.
  12903. * @xri: xri id in transaction.
  12904. *
  12905. * This function validates the xri maps to the known range of XRIs allocated an
  12906. * used by the driver.
  12907. **/
  12908. uint16_t
  12909. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  12910. uint16_t xri)
  12911. {
  12912. int i;
  12913. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  12914. if (xri == phba->sli4_hba.xri_ids[i])
  12915. return i;
  12916. }
  12917. return NO_XRI;
  12918. }
  12919. /**
  12920. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  12921. * @phba: Pointer to HBA context object.
  12922. * @fc_hdr: pointer to a FC frame header.
  12923. *
  12924. * This function sends a basic response to a previous unsol sequence abort
  12925. * event after aborting the sequence handling.
  12926. **/
  12927. static void
  12928. lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba,
  12929. struct fc_frame_header *fc_hdr)
  12930. {
  12931. struct lpfc_iocbq *ctiocb = NULL;
  12932. struct lpfc_nodelist *ndlp;
  12933. uint16_t oxid, rxid;
  12934. uint32_t sid, fctl;
  12935. IOCB_t *icmd;
  12936. int rc;
  12937. if (!lpfc_is_link_up(phba))
  12938. return;
  12939. sid = sli4_sid_from_fc_hdr(fc_hdr);
  12940. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  12941. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  12942. ndlp = lpfc_findnode_did(phba->pport, sid);
  12943. if (!ndlp) {
  12944. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  12945. "1268 Find ndlp returned NULL for oxid:x%x "
  12946. "SID:x%x\n", oxid, sid);
  12947. return;
  12948. }
  12949. if (lpfc_sli4_xri_inrange(phba, rxid))
  12950. lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0);
  12951. /* Allocate buffer for rsp iocb */
  12952. ctiocb = lpfc_sli_get_iocbq(phba);
  12953. if (!ctiocb)
  12954. return;
  12955. /* Extract the F_CTL field from FC_HDR */
  12956. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  12957. icmd = &ctiocb->iocb;
  12958. icmd->un.xseq64.bdl.bdeSize = 0;
  12959. icmd->un.xseq64.bdl.ulpIoTag32 = 0;
  12960. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  12961. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
  12962. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
  12963. /* Fill in the rest of iocb fields */
  12964. icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
  12965. icmd->ulpBdeCount = 0;
  12966. icmd->ulpLe = 1;
  12967. icmd->ulpClass = CLASS3;
  12968. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  12969. ctiocb->context1 = ndlp;
  12970. ctiocb->iocb_cmpl = NULL;
  12971. ctiocb->vport = phba->pport;
  12972. ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  12973. ctiocb->sli4_lxritag = NO_XRI;
  12974. ctiocb->sli4_xritag = NO_XRI;
  12975. /* If the oxid maps to the FCP XRI range or if it is out of range,
  12976. * send a BLS_RJT. The driver no longer has that exchange.
  12977. * Override the IOCB for a BA_RJT.
  12978. */
  12979. if (oxid > (phba->sli4_hba.max_cfg_param.max_xri +
  12980. phba->sli4_hba.max_cfg_param.xri_base) ||
  12981. oxid > (lpfc_sli4_get_els_iocb_cnt(phba) +
  12982. phba->sli4_hba.max_cfg_param.xri_base)) {
  12983. icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
  12984. bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
  12985. bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
  12986. bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
  12987. }
  12988. if (fctl & FC_FC_EX_CTX) {
  12989. /* ABTS sent by responder to CT exchange, construction
  12990. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  12991. * field and RX_ID from ABTS for RX_ID field.
  12992. */
  12993. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
  12994. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
  12995. } else {
  12996. /* ABTS sent by initiator to CT exchange, construction
  12997. * of BA_ACC will need to allocate a new XRI as for the
  12998. * XRI_TAG and RX_ID fields.
  12999. */
  13000. bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
  13001. bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI);
  13002. }
  13003. bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
  13004. /* Xmit CT abts response on exchange <xid> */
  13005. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  13006. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  13007. icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
  13008. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  13009. if (rc == IOCB_ERROR) {
  13010. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  13011. "2925 Failed to issue CT ABTS RSP x%x on "
  13012. "xri x%x, Data x%x\n",
  13013. icmd->un.xseq64.w5.hcsw.Rctl, oxid,
  13014. phba->link_state);
  13015. lpfc_sli_release_iocbq(phba, ctiocb);
  13016. }
  13017. }
  13018. /**
  13019. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  13020. * @vport: Pointer to the vport on which this sequence was received
  13021. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13022. *
  13023. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  13024. * receive sequence is only partially assembed by the driver, it shall abort
  13025. * the partially assembled frames for the sequence. Otherwise, if the
  13026. * unsolicited receive sequence has been completely assembled and passed to
  13027. * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
  13028. * unsolicited sequence has been aborted. After that, it will issue a basic
  13029. * accept to accept the abort.
  13030. **/
  13031. void
  13032. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  13033. struct hbq_dmabuf *dmabuf)
  13034. {
  13035. struct lpfc_hba *phba = vport->phba;
  13036. struct fc_frame_header fc_hdr;
  13037. uint32_t fctl;
  13038. bool abts_par;
  13039. /* Make a copy of fc_hdr before the dmabuf being released */
  13040. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  13041. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  13042. if (fctl & FC_FC_EX_CTX) {
  13043. /*
  13044. * ABTS sent by responder to exchange, just free the buffer
  13045. */
  13046. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13047. } else {
  13048. /*
  13049. * ABTS sent by initiator to exchange, need to do cleanup
  13050. */
  13051. /* Try to abort partially assembled seq */
  13052. abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  13053. /* Send abort to ULP if partially seq abort failed */
  13054. if (abts_par == false)
  13055. lpfc_sli4_send_seq_to_ulp(vport, dmabuf);
  13056. else
  13057. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13058. }
  13059. /* Send basic accept (BA_ACC) to the abort requester */
  13060. lpfc_sli4_seq_abort_rsp(phba, &fc_hdr);
  13061. }
  13062. /**
  13063. * lpfc_seq_complete - Indicates if a sequence is complete
  13064. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13065. *
  13066. * This function checks the sequence, starting with the frame described by
  13067. * @dmabuf, to see if all the frames associated with this sequence are present.
  13068. * the frames associated with this sequence are linked to the @dmabuf using the
  13069. * dbuf list. This function looks for two major things. 1) That the first frame
  13070. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  13071. * set. 3) That there are no holes in the sequence count. The function will
  13072. * return 1 when the sequence is complete, otherwise it will return 0.
  13073. **/
  13074. static int
  13075. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  13076. {
  13077. struct fc_frame_header *hdr;
  13078. struct lpfc_dmabuf *d_buf;
  13079. struct hbq_dmabuf *seq_dmabuf;
  13080. uint32_t fctl;
  13081. int seq_count = 0;
  13082. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13083. /* make sure first fame of sequence has a sequence count of zero */
  13084. if (hdr->fh_seq_cnt != seq_count)
  13085. return 0;
  13086. fctl = (hdr->fh_f_ctl[0] << 16 |
  13087. hdr->fh_f_ctl[1] << 8 |
  13088. hdr->fh_f_ctl[2]);
  13089. /* If last frame of sequence we can return success. */
  13090. if (fctl & FC_FC_END_SEQ)
  13091. return 1;
  13092. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  13093. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13094. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13095. /* If there is a hole in the sequence count then fail. */
  13096. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  13097. return 0;
  13098. fctl = (hdr->fh_f_ctl[0] << 16 |
  13099. hdr->fh_f_ctl[1] << 8 |
  13100. hdr->fh_f_ctl[2]);
  13101. /* If last frame of sequence we can return success. */
  13102. if (fctl & FC_FC_END_SEQ)
  13103. return 1;
  13104. }
  13105. return 0;
  13106. }
  13107. /**
  13108. * lpfc_prep_seq - Prep sequence for ULP processing
  13109. * @vport: Pointer to the vport on which this sequence was received
  13110. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  13111. *
  13112. * This function takes a sequence, described by a list of frames, and creates
  13113. * a list of iocbq structures to describe the sequence. This iocbq list will be
  13114. * used to issue to the generic unsolicited sequence handler. This routine
  13115. * returns a pointer to the first iocbq in the list. If the function is unable
  13116. * to allocate an iocbq then it throw out the received frames that were not
  13117. * able to be described and return a pointer to the first iocbq. If unable to
  13118. * allocate any iocbqs (including the first) this function will return NULL.
  13119. **/
  13120. static struct lpfc_iocbq *
  13121. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  13122. {
  13123. struct hbq_dmabuf *hbq_buf;
  13124. struct lpfc_dmabuf *d_buf, *n_buf;
  13125. struct lpfc_iocbq *first_iocbq, *iocbq;
  13126. struct fc_frame_header *fc_hdr;
  13127. uint32_t sid;
  13128. uint32_t len, tot_len;
  13129. struct ulp_bde64 *pbde;
  13130. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13131. /* remove from receive buffer list */
  13132. list_del_init(&seq_dmabuf->hbuf.list);
  13133. lpfc_update_rcv_time_stamp(vport);
  13134. /* get the Remote Port's SID */
  13135. sid = sli4_sid_from_fc_hdr(fc_hdr);
  13136. tot_len = 0;
  13137. /* Get an iocbq struct to fill in. */
  13138. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  13139. if (first_iocbq) {
  13140. /* Initialize the first IOCB. */
  13141. first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
  13142. first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
  13143. first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
  13144. first_iocbq->iocb.ulpContext = NO_XRI;
  13145. first_iocbq->iocb.unsli3.rcvsli3.ox_id =
  13146. be16_to_cpu(fc_hdr->fh_ox_id);
  13147. /* iocbq is prepped for internal consumption. Physical vpi. */
  13148. first_iocbq->iocb.unsli3.rcvsli3.vpi =
  13149. vport->phba->vpi_ids[vport->vpi];
  13150. /* put the first buffer into the first IOCBq */
  13151. first_iocbq->context2 = &seq_dmabuf->dbuf;
  13152. first_iocbq->context3 = NULL;
  13153. first_iocbq->iocb.ulpBdeCount = 1;
  13154. first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13155. LPFC_DATA_BUF_SIZE;
  13156. first_iocbq->iocb.un.rcvels.remoteID = sid;
  13157. tot_len = bf_get(lpfc_rcqe_length,
  13158. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  13159. first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13160. }
  13161. iocbq = first_iocbq;
  13162. /*
  13163. * Each IOCBq can have two Buffers assigned, so go through the list
  13164. * of buffers for this sequence and save two buffers in each IOCBq
  13165. */
  13166. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  13167. if (!iocbq) {
  13168. lpfc_in_buf_free(vport->phba, d_buf);
  13169. continue;
  13170. }
  13171. if (!iocbq->context3) {
  13172. iocbq->context3 = d_buf;
  13173. iocbq->iocb.ulpBdeCount++;
  13174. pbde = (struct ulp_bde64 *)
  13175. &iocbq->iocb.unsli3.sli3Words[4];
  13176. pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
  13177. /* We need to get the size out of the right CQE */
  13178. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13179. len = bf_get(lpfc_rcqe_length,
  13180. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13181. iocbq->iocb.unsli3.rcvsli3.acc_len += len;
  13182. tot_len += len;
  13183. } else {
  13184. iocbq = lpfc_sli_get_iocbq(vport->phba);
  13185. if (!iocbq) {
  13186. if (first_iocbq) {
  13187. first_iocbq->iocb.ulpStatus =
  13188. IOSTAT_FCP_RSP_ERROR;
  13189. first_iocbq->iocb.un.ulpWord[4] =
  13190. IOERR_NO_RESOURCES;
  13191. }
  13192. lpfc_in_buf_free(vport->phba, d_buf);
  13193. continue;
  13194. }
  13195. iocbq->context2 = d_buf;
  13196. iocbq->context3 = NULL;
  13197. iocbq->iocb.ulpBdeCount = 1;
  13198. iocbq->iocb.un.cont64[0].tus.f.bdeSize =
  13199. LPFC_DATA_BUF_SIZE;
  13200. /* We need to get the size out of the right CQE */
  13201. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  13202. len = bf_get(lpfc_rcqe_length,
  13203. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  13204. tot_len += len;
  13205. iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
  13206. iocbq->iocb.un.rcvels.remoteID = sid;
  13207. list_add_tail(&iocbq->list, &first_iocbq->list);
  13208. }
  13209. }
  13210. return first_iocbq;
  13211. }
  13212. static void
  13213. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  13214. struct hbq_dmabuf *seq_dmabuf)
  13215. {
  13216. struct fc_frame_header *fc_hdr;
  13217. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  13218. struct lpfc_hba *phba = vport->phba;
  13219. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  13220. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  13221. if (!iocbq) {
  13222. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13223. "2707 Ring %d handler: Failed to allocate "
  13224. "iocb Rctl x%x Type x%x received\n",
  13225. LPFC_ELS_RING,
  13226. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13227. return;
  13228. }
  13229. if (!lpfc_complete_unsol_iocb(phba,
  13230. &phba->sli.ring[LPFC_ELS_RING],
  13231. iocbq, fc_hdr->fh_r_ctl,
  13232. fc_hdr->fh_type))
  13233. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13234. "2540 Ring %d handler: unexpected Rctl "
  13235. "x%x Type x%x received\n",
  13236. LPFC_ELS_RING,
  13237. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  13238. /* Free iocb created in lpfc_prep_seq */
  13239. list_for_each_entry_safe(curr_iocb, next_iocb,
  13240. &iocbq->list, list) {
  13241. list_del_init(&curr_iocb->list);
  13242. lpfc_sli_release_iocbq(phba, curr_iocb);
  13243. }
  13244. lpfc_sli_release_iocbq(phba, iocbq);
  13245. }
  13246. /**
  13247. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  13248. * @phba: Pointer to HBA context object.
  13249. *
  13250. * This function is called with no lock held. This function processes all
  13251. * the received buffers and gives it to upper layers when a received buffer
  13252. * indicates that it is the final frame in the sequence. The interrupt
  13253. * service routine processes received buffers at interrupt contexts and adds
  13254. * received dma buffers to the rb_pend_list queue and signals the worker thread.
  13255. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  13256. * appropriate receive function when the final frame in a sequence is received.
  13257. **/
  13258. void
  13259. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  13260. struct hbq_dmabuf *dmabuf)
  13261. {
  13262. struct hbq_dmabuf *seq_dmabuf;
  13263. struct fc_frame_header *fc_hdr;
  13264. struct lpfc_vport *vport;
  13265. uint32_t fcfi;
  13266. /* Process each received buffer */
  13267. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  13268. /* check to see if this a valid type of frame */
  13269. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  13270. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13271. return;
  13272. }
  13273. if ((bf_get(lpfc_cqe_code,
  13274. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  13275. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  13276. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13277. else
  13278. fcfi = bf_get(lpfc_rcqe_fcf_id,
  13279. &dmabuf->cq_event.cqe.rcqe_cmpl);
  13280. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi);
  13281. if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) {
  13282. /* throw out the frame */
  13283. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13284. return;
  13285. }
  13286. /* Handle the basic abort sequence (BA_ABTS) event */
  13287. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  13288. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  13289. return;
  13290. }
  13291. /* Link this frame */
  13292. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  13293. if (!seq_dmabuf) {
  13294. /* unable to add frame to vport - throw it out */
  13295. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  13296. return;
  13297. }
  13298. /* If not last frame in sequence continue processing frames. */
  13299. if (!lpfc_seq_complete(seq_dmabuf))
  13300. return;
  13301. /* Send the complete sequence to the upper layer protocol */
  13302. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  13303. }
  13304. /**
  13305. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  13306. * @phba: pointer to lpfc hba data structure.
  13307. *
  13308. * This routine is invoked to post rpi header templates to the
  13309. * HBA consistent with the SLI-4 interface spec. This routine
  13310. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13311. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13312. *
  13313. * This routine does not require any locks. It's usage is expected
  13314. * to be driver load or reset recovery when the driver is
  13315. * sequential.
  13316. *
  13317. * Return codes
  13318. * 0 - successful
  13319. * -EIO - The mailbox failed to complete successfully.
  13320. * When this error occurs, the driver is not guaranteed
  13321. * to have any rpi regions posted to the device and
  13322. * must either attempt to repost the regions or take a
  13323. * fatal error.
  13324. **/
  13325. int
  13326. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  13327. {
  13328. struct lpfc_rpi_hdr *rpi_page;
  13329. uint32_t rc = 0;
  13330. uint16_t lrpi = 0;
  13331. /* SLI4 ports that support extents do not require RPI headers. */
  13332. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13333. goto exit;
  13334. if (phba->sli4_hba.extents_in_use)
  13335. return -EIO;
  13336. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  13337. /*
  13338. * Assign the rpi headers a physical rpi only if the driver
  13339. * has not initialized those resources. A port reset only
  13340. * needs the headers posted.
  13341. */
  13342. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  13343. LPFC_RPI_RSRC_RDY)
  13344. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13345. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  13346. if (rc != MBX_SUCCESS) {
  13347. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13348. "2008 Error %d posting all rpi "
  13349. "headers\n", rc);
  13350. rc = -EIO;
  13351. break;
  13352. }
  13353. }
  13354. exit:
  13355. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  13356. LPFC_RPI_RSRC_RDY);
  13357. return rc;
  13358. }
  13359. /**
  13360. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  13361. * @phba: pointer to lpfc hba data structure.
  13362. * @rpi_page: pointer to the rpi memory region.
  13363. *
  13364. * This routine is invoked to post a single rpi header to the
  13365. * HBA consistent with the SLI-4 interface spec. This memory region
  13366. * maps up to 64 rpi context regions.
  13367. *
  13368. * Return codes
  13369. * 0 - successful
  13370. * -ENOMEM - No available memory
  13371. * -EIO - The mailbox failed to complete successfully.
  13372. **/
  13373. int
  13374. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  13375. {
  13376. LPFC_MBOXQ_t *mboxq;
  13377. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  13378. uint32_t rc = 0;
  13379. uint32_t shdr_status, shdr_add_status;
  13380. union lpfc_sli4_cfg_shdr *shdr;
  13381. /* SLI4 ports that support extents do not require RPI headers. */
  13382. if (!phba->sli4_hba.rpi_hdrs_in_use)
  13383. return rc;
  13384. if (phba->sli4_hba.extents_in_use)
  13385. return -EIO;
  13386. /* The port is notified of the header region via a mailbox command. */
  13387. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13388. if (!mboxq) {
  13389. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13390. "2001 Unable to allocate memory for issuing "
  13391. "SLI_CONFIG_SPECIAL mailbox command\n");
  13392. return -ENOMEM;
  13393. }
  13394. /* Post all rpi memory regions to the port. */
  13395. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  13396. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13397. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  13398. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  13399. sizeof(struct lpfc_sli4_cfg_mhdr),
  13400. LPFC_SLI4_MBX_EMBED);
  13401. /* Post the physical rpi to the port for this rpi header. */
  13402. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  13403. rpi_page->start_rpi);
  13404. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  13405. hdr_tmpl, rpi_page->page_count);
  13406. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  13407. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  13408. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  13409. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  13410. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13411. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13412. if (rc != MBX_TIMEOUT)
  13413. mempool_free(mboxq, phba->mbox_mem_pool);
  13414. if (shdr_status || shdr_add_status || rc) {
  13415. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13416. "2514 POST_RPI_HDR mailbox failed with "
  13417. "status x%x add_status x%x, mbx status x%x\n",
  13418. shdr_status, shdr_add_status, rc);
  13419. rc = -ENXIO;
  13420. }
  13421. return rc;
  13422. }
  13423. /**
  13424. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  13425. * @phba: pointer to lpfc hba data structure.
  13426. *
  13427. * This routine is invoked to post rpi header templates to the
  13428. * HBA consistent with the SLI-4 interface spec. This routine
  13429. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  13430. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  13431. *
  13432. * Returns
  13433. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  13434. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  13435. **/
  13436. int
  13437. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  13438. {
  13439. unsigned long rpi;
  13440. uint16_t max_rpi, rpi_limit;
  13441. uint16_t rpi_remaining, lrpi = 0;
  13442. struct lpfc_rpi_hdr *rpi_hdr;
  13443. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  13444. rpi_limit = phba->sli4_hba.next_rpi;
  13445. /*
  13446. * Fetch the next logical rpi. Because this index is logical,
  13447. * the driver starts at 0 each time.
  13448. */
  13449. spin_lock_irq(&phba->hbalock);
  13450. rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
  13451. if (rpi >= rpi_limit)
  13452. rpi = LPFC_RPI_ALLOC_ERROR;
  13453. else {
  13454. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  13455. phba->sli4_hba.max_cfg_param.rpi_used++;
  13456. phba->sli4_hba.rpi_count++;
  13457. }
  13458. /*
  13459. * Don't try to allocate more rpi header regions if the device limit
  13460. * has been exhausted.
  13461. */
  13462. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  13463. (phba->sli4_hba.rpi_count >= max_rpi)) {
  13464. spin_unlock_irq(&phba->hbalock);
  13465. return rpi;
  13466. }
  13467. /*
  13468. * RPI header postings are not required for SLI4 ports capable of
  13469. * extents.
  13470. */
  13471. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  13472. spin_unlock_irq(&phba->hbalock);
  13473. return rpi;
  13474. }
  13475. /*
  13476. * If the driver is running low on rpi resources, allocate another
  13477. * page now. Note that the next_rpi value is used because
  13478. * it represents how many are actually in use whereas max_rpi notes
  13479. * how many are supported max by the device.
  13480. */
  13481. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  13482. spin_unlock_irq(&phba->hbalock);
  13483. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  13484. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  13485. if (!rpi_hdr) {
  13486. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13487. "2002 Error Could not grow rpi "
  13488. "count\n");
  13489. } else {
  13490. lrpi = rpi_hdr->start_rpi;
  13491. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  13492. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  13493. }
  13494. }
  13495. return rpi;
  13496. }
  13497. /**
  13498. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13499. * @phba: pointer to lpfc hba data structure.
  13500. *
  13501. * This routine is invoked to release an rpi to the pool of
  13502. * available rpis maintained by the driver.
  13503. **/
  13504. void
  13505. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13506. {
  13507. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  13508. phba->sli4_hba.rpi_count--;
  13509. phba->sli4_hba.max_cfg_param.rpi_used--;
  13510. }
  13511. }
  13512. /**
  13513. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  13514. * @phba: pointer to lpfc hba data structure.
  13515. *
  13516. * This routine is invoked to release an rpi to the pool of
  13517. * available rpis maintained by the driver.
  13518. **/
  13519. void
  13520. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  13521. {
  13522. spin_lock_irq(&phba->hbalock);
  13523. __lpfc_sli4_free_rpi(phba, rpi);
  13524. spin_unlock_irq(&phba->hbalock);
  13525. }
  13526. /**
  13527. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  13528. * @phba: pointer to lpfc hba data structure.
  13529. *
  13530. * This routine is invoked to remove the memory region that
  13531. * provided rpi via a bitmask.
  13532. **/
  13533. void
  13534. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  13535. {
  13536. kfree(phba->sli4_hba.rpi_bmask);
  13537. kfree(phba->sli4_hba.rpi_ids);
  13538. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  13539. }
  13540. /**
  13541. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  13542. * @phba: pointer to lpfc hba data structure.
  13543. *
  13544. * This routine is invoked to remove the memory region that
  13545. * provided rpi via a bitmask.
  13546. **/
  13547. int
  13548. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  13549. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  13550. {
  13551. LPFC_MBOXQ_t *mboxq;
  13552. struct lpfc_hba *phba = ndlp->phba;
  13553. int rc;
  13554. /* The port is notified of the header region via a mailbox command. */
  13555. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13556. if (!mboxq)
  13557. return -ENOMEM;
  13558. /* Post all rpi memory regions to the port. */
  13559. lpfc_resume_rpi(mboxq, ndlp);
  13560. if (cmpl) {
  13561. mboxq->mbox_cmpl = cmpl;
  13562. mboxq->context1 = arg;
  13563. mboxq->context2 = ndlp;
  13564. }
  13565. mboxq->vport = ndlp->vport;
  13566. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13567. if (rc == MBX_NOT_FINISHED) {
  13568. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  13569. "2010 Resume RPI Mailbox failed "
  13570. "status %d, mbxStatus x%x\n", rc,
  13571. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13572. mempool_free(mboxq, phba->mbox_mem_pool);
  13573. return -EIO;
  13574. }
  13575. return 0;
  13576. }
  13577. /**
  13578. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  13579. * @vport: Pointer to the vport for which the vpi is being initialized
  13580. *
  13581. * This routine is invoked to activate a vpi with the port.
  13582. *
  13583. * Returns:
  13584. * 0 success
  13585. * -Evalue otherwise
  13586. **/
  13587. int
  13588. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  13589. {
  13590. LPFC_MBOXQ_t *mboxq;
  13591. int rc = 0;
  13592. int retval = MBX_SUCCESS;
  13593. uint32_t mbox_tmo;
  13594. struct lpfc_hba *phba = vport->phba;
  13595. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13596. if (!mboxq)
  13597. return -ENOMEM;
  13598. lpfc_init_vpi(phba, mboxq, vport->vpi);
  13599. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  13600. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  13601. if (rc != MBX_SUCCESS) {
  13602. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  13603. "2022 INIT VPI Mailbox failed "
  13604. "status %d, mbxStatus x%x\n", rc,
  13605. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  13606. retval = -EIO;
  13607. }
  13608. if (rc != MBX_TIMEOUT)
  13609. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  13610. return retval;
  13611. }
  13612. /**
  13613. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  13614. * @phba: pointer to lpfc hba data structure.
  13615. * @mboxq: Pointer to mailbox object.
  13616. *
  13617. * This routine is invoked to manually add a single FCF record. The caller
  13618. * must pass a completely initialized FCF_Record. This routine takes
  13619. * care of the nonembedded mailbox operations.
  13620. **/
  13621. static void
  13622. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  13623. {
  13624. void *virt_addr;
  13625. union lpfc_sli4_cfg_shdr *shdr;
  13626. uint32_t shdr_status, shdr_add_status;
  13627. virt_addr = mboxq->sge_array->addr[0];
  13628. /* The IOCTL status is embedded in the mailbox subheader. */
  13629. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  13630. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  13631. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  13632. if ((shdr_status || shdr_add_status) &&
  13633. (shdr_status != STATUS_FCF_IN_USE))
  13634. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13635. "2558 ADD_FCF_RECORD mailbox failed with "
  13636. "status x%x add_status x%x\n",
  13637. shdr_status, shdr_add_status);
  13638. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13639. }
  13640. /**
  13641. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  13642. * @phba: pointer to lpfc hba data structure.
  13643. * @fcf_record: pointer to the initialized fcf record to add.
  13644. *
  13645. * This routine is invoked to manually add a single FCF record. The caller
  13646. * must pass a completely initialized FCF_Record. This routine takes
  13647. * care of the nonembedded mailbox operations.
  13648. **/
  13649. int
  13650. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  13651. {
  13652. int rc = 0;
  13653. LPFC_MBOXQ_t *mboxq;
  13654. uint8_t *bytep;
  13655. void *virt_addr;
  13656. dma_addr_t phys_addr;
  13657. struct lpfc_mbx_sge sge;
  13658. uint32_t alloc_len, req_len;
  13659. uint32_t fcfindex;
  13660. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13661. if (!mboxq) {
  13662. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13663. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  13664. return -ENOMEM;
  13665. }
  13666. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  13667. sizeof(uint32_t);
  13668. /* Allocate DMA memory and set up the non-embedded mailbox command */
  13669. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  13670. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  13671. req_len, LPFC_SLI4_MBX_NEMBED);
  13672. if (alloc_len < req_len) {
  13673. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13674. "2523 Allocated DMA memory size (x%x) is "
  13675. "less than the requested DMA memory "
  13676. "size (x%x)\n", alloc_len, req_len);
  13677. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13678. return -ENOMEM;
  13679. }
  13680. /*
  13681. * Get the first SGE entry from the non-embedded DMA memory. This
  13682. * routine only uses a single SGE.
  13683. */
  13684. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  13685. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  13686. virt_addr = mboxq->sge_array->addr[0];
  13687. /*
  13688. * Configure the FCF record for FCFI 0. This is the driver's
  13689. * hardcoded default and gets used in nonFIP mode.
  13690. */
  13691. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  13692. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  13693. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  13694. /*
  13695. * Copy the fcf_index and the FCF Record Data. The data starts after
  13696. * the FCoE header plus word10. The data copy needs to be endian
  13697. * correct.
  13698. */
  13699. bytep += sizeof(uint32_t);
  13700. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  13701. mboxq->vport = phba->pport;
  13702. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  13703. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13704. if (rc == MBX_NOT_FINISHED) {
  13705. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13706. "2515 ADD_FCF_RECORD mailbox failed with "
  13707. "status 0x%x\n", rc);
  13708. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13709. rc = -EIO;
  13710. } else
  13711. rc = 0;
  13712. return rc;
  13713. }
  13714. /**
  13715. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  13716. * @phba: pointer to lpfc hba data structure.
  13717. * @fcf_record: pointer to the fcf record to write the default data.
  13718. * @fcf_index: FCF table entry index.
  13719. *
  13720. * This routine is invoked to build the driver's default FCF record. The
  13721. * values used are hardcoded. This routine handles memory initialization.
  13722. *
  13723. **/
  13724. void
  13725. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  13726. struct fcf_record *fcf_record,
  13727. uint16_t fcf_index)
  13728. {
  13729. memset(fcf_record, 0, sizeof(struct fcf_record));
  13730. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  13731. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  13732. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  13733. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  13734. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  13735. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  13736. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  13737. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  13738. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  13739. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  13740. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  13741. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  13742. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  13743. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  13744. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  13745. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  13746. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  13747. /* Set the VLAN bit map */
  13748. if (phba->valid_vlan) {
  13749. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  13750. = 1 << (phba->vlan_id % 8);
  13751. }
  13752. }
  13753. /**
  13754. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  13755. * @phba: pointer to lpfc hba data structure.
  13756. * @fcf_index: FCF table entry offset.
  13757. *
  13758. * This routine is invoked to scan the entire FCF table by reading FCF
  13759. * record and processing it one at a time starting from the @fcf_index
  13760. * for initial FCF discovery or fast FCF failover rediscovery.
  13761. *
  13762. * Return 0 if the mailbox command is submitted successfully, none 0
  13763. * otherwise.
  13764. **/
  13765. int
  13766. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13767. {
  13768. int rc = 0, error;
  13769. LPFC_MBOXQ_t *mboxq;
  13770. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  13771. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13772. if (!mboxq) {
  13773. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  13774. "2000 Failed to allocate mbox for "
  13775. "READ_FCF cmd\n");
  13776. error = -ENOMEM;
  13777. goto fail_fcf_scan;
  13778. }
  13779. /* Construct the read FCF record mailbox command */
  13780. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13781. if (rc) {
  13782. error = -EINVAL;
  13783. goto fail_fcf_scan;
  13784. }
  13785. /* Issue the mailbox command asynchronously */
  13786. mboxq->vport = phba->pport;
  13787. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  13788. spin_lock_irq(&phba->hbalock);
  13789. phba->hba_flag |= FCF_TS_INPROG;
  13790. spin_unlock_irq(&phba->hbalock);
  13791. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13792. if (rc == MBX_NOT_FINISHED)
  13793. error = -EIO;
  13794. else {
  13795. /* Reset eligible FCF count for new scan */
  13796. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  13797. phba->fcf.eligible_fcf_cnt = 0;
  13798. error = 0;
  13799. }
  13800. fail_fcf_scan:
  13801. if (error) {
  13802. if (mboxq)
  13803. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13804. /* FCF scan failed, clear FCF_TS_INPROG flag */
  13805. spin_lock_irq(&phba->hbalock);
  13806. phba->hba_flag &= ~FCF_TS_INPROG;
  13807. spin_unlock_irq(&phba->hbalock);
  13808. }
  13809. return error;
  13810. }
  13811. /**
  13812. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  13813. * @phba: pointer to lpfc hba data structure.
  13814. * @fcf_index: FCF table entry offset.
  13815. *
  13816. * This routine is invoked to read an FCF record indicated by @fcf_index
  13817. * and to use it for FLOGI roundrobin FCF failover.
  13818. *
  13819. * Return 0 if the mailbox command is submitted successfully, none 0
  13820. * otherwise.
  13821. **/
  13822. int
  13823. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13824. {
  13825. int rc = 0, error;
  13826. LPFC_MBOXQ_t *mboxq;
  13827. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13828. if (!mboxq) {
  13829. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13830. "2763 Failed to allocate mbox for "
  13831. "READ_FCF cmd\n");
  13832. error = -ENOMEM;
  13833. goto fail_fcf_read;
  13834. }
  13835. /* Construct the read FCF record mailbox command */
  13836. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13837. if (rc) {
  13838. error = -EINVAL;
  13839. goto fail_fcf_read;
  13840. }
  13841. /* Issue the mailbox command asynchronously */
  13842. mboxq->vport = phba->pport;
  13843. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  13844. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13845. if (rc == MBX_NOT_FINISHED)
  13846. error = -EIO;
  13847. else
  13848. error = 0;
  13849. fail_fcf_read:
  13850. if (error && mboxq)
  13851. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13852. return error;
  13853. }
  13854. /**
  13855. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  13856. * @phba: pointer to lpfc hba data structure.
  13857. * @fcf_index: FCF table entry offset.
  13858. *
  13859. * This routine is invoked to read an FCF record indicated by @fcf_index to
  13860. * determine whether it's eligible for FLOGI roundrobin failover list.
  13861. *
  13862. * Return 0 if the mailbox command is submitted successfully, none 0
  13863. * otherwise.
  13864. **/
  13865. int
  13866. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  13867. {
  13868. int rc = 0, error;
  13869. LPFC_MBOXQ_t *mboxq;
  13870. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  13871. if (!mboxq) {
  13872. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  13873. "2758 Failed to allocate mbox for "
  13874. "READ_FCF cmd\n");
  13875. error = -ENOMEM;
  13876. goto fail_fcf_read;
  13877. }
  13878. /* Construct the read FCF record mailbox command */
  13879. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  13880. if (rc) {
  13881. error = -EINVAL;
  13882. goto fail_fcf_read;
  13883. }
  13884. /* Issue the mailbox command asynchronously */
  13885. mboxq->vport = phba->pport;
  13886. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  13887. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  13888. if (rc == MBX_NOT_FINISHED)
  13889. error = -EIO;
  13890. else
  13891. error = 0;
  13892. fail_fcf_read:
  13893. if (error && mboxq)
  13894. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  13895. return error;
  13896. }
  13897. /**
  13898. * lpfc_check_next_fcf_pri
  13899. * phba pointer to the lpfc_hba struct for this port.
  13900. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  13901. * routine when the rr_bmask is empty. The FCF indecies are put into the
  13902. * rr_bmask based on their priority level. Starting from the highest priority
  13903. * to the lowest. The most likely FCF candidate will be in the highest
  13904. * priority group. When this routine is called it searches the fcf_pri list for
  13905. * next lowest priority group and repopulates the rr_bmask with only those
  13906. * fcf_indexes.
  13907. * returns:
  13908. * 1=success 0=failure
  13909. **/
  13910. int
  13911. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  13912. {
  13913. uint16_t next_fcf_pri;
  13914. uint16_t last_index;
  13915. struct lpfc_fcf_pri *fcf_pri;
  13916. int rc;
  13917. int ret = 0;
  13918. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  13919. LPFC_SLI4_FCF_TBL_INDX_MAX);
  13920. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  13921. "3060 Last IDX %d\n", last_index);
  13922. if (list_empty(&phba->fcf.fcf_pri_list)) {
  13923. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  13924. "3061 Last IDX %d\n", last_index);
  13925. return 0; /* Empty rr list */
  13926. }
  13927. next_fcf_pri = 0;
  13928. /*
  13929. * Clear the rr_bmask and set all of the bits that are at this
  13930. * priority.
  13931. */
  13932. memset(phba->fcf.fcf_rr_bmask, 0,
  13933. sizeof(*phba->fcf.fcf_rr_bmask));
  13934. spin_lock_irq(&phba->hbalock);
  13935. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13936. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  13937. continue;
  13938. /*
  13939. * the 1st priority that has not FLOGI failed
  13940. * will be the highest.
  13941. */
  13942. if (!next_fcf_pri)
  13943. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13944. spin_unlock_irq(&phba->hbalock);
  13945. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13946. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13947. fcf_pri->fcf_rec.fcf_index);
  13948. if (rc)
  13949. return 0;
  13950. }
  13951. spin_lock_irq(&phba->hbalock);
  13952. }
  13953. /*
  13954. * if next_fcf_pri was not set above and the list is not empty then
  13955. * we have failed flogis on all of them. So reset flogi failed
  13956. * and start at the begining.
  13957. */
  13958. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  13959. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  13960. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  13961. /*
  13962. * the 1st priority that has not FLOGI failed
  13963. * will be the highest.
  13964. */
  13965. if (!next_fcf_pri)
  13966. next_fcf_pri = fcf_pri->fcf_rec.priority;
  13967. spin_unlock_irq(&phba->hbalock);
  13968. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  13969. rc = lpfc_sli4_fcf_rr_index_set(phba,
  13970. fcf_pri->fcf_rec.fcf_index);
  13971. if (rc)
  13972. return 0;
  13973. }
  13974. spin_lock_irq(&phba->hbalock);
  13975. }
  13976. } else
  13977. ret = 1;
  13978. spin_unlock_irq(&phba->hbalock);
  13979. return ret;
  13980. }
  13981. /**
  13982. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  13983. * @phba: pointer to lpfc hba data structure.
  13984. *
  13985. * This routine is to get the next eligible FCF record index in a round
  13986. * robin fashion. If the next eligible FCF record index equals to the
  13987. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  13988. * shall be returned, otherwise, the next eligible FCF record's index
  13989. * shall be returned.
  13990. **/
  13991. uint16_t
  13992. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  13993. {
  13994. uint16_t next_fcf_index;
  13995. /* Search start from next bit of currently registered FCF index */
  13996. next_priority:
  13997. next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) %
  13998. LPFC_SLI4_FCF_TBL_INDX_MAX;
  13999. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14000. LPFC_SLI4_FCF_TBL_INDX_MAX,
  14001. next_fcf_index);
  14002. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  14003. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14004. /*
  14005. * If we have wrapped then we need to clear the bits that
  14006. * have been tested so that we can detect when we should
  14007. * change the priority level.
  14008. */
  14009. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  14010. LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
  14011. }
  14012. /* Check roundrobin failover list empty condition */
  14013. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  14014. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  14015. /*
  14016. * If next fcf index is not found check if there are lower
  14017. * Priority level fcf's in the fcf_priority list.
  14018. * Set up the rr_bmask with all of the avaiable fcf bits
  14019. * at that level and continue the selection process.
  14020. */
  14021. if (lpfc_check_next_fcf_pri_level(phba))
  14022. goto next_priority;
  14023. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14024. "2844 No roundrobin failover FCF available\n");
  14025. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
  14026. return LPFC_FCOE_FCF_NEXT_NONE;
  14027. else {
  14028. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  14029. "3063 Only FCF available idx %d, flag %x\n",
  14030. next_fcf_index,
  14031. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
  14032. return next_fcf_index;
  14033. }
  14034. }
  14035. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  14036. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  14037. LPFC_FCF_FLOGI_FAILED)
  14038. goto next_priority;
  14039. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14040. "2845 Get next roundrobin failover FCF (x%x)\n",
  14041. next_fcf_index);
  14042. return next_fcf_index;
  14043. }
  14044. /**
  14045. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  14046. * @phba: pointer to lpfc hba data structure.
  14047. *
  14048. * This routine sets the FCF record index in to the eligible bmask for
  14049. * roundrobin failover search. It checks to make sure that the index
  14050. * does not go beyond the range of the driver allocated bmask dimension
  14051. * before setting the bit.
  14052. *
  14053. * Returns 0 if the index bit successfully set, otherwise, it returns
  14054. * -EINVAL.
  14055. **/
  14056. int
  14057. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  14058. {
  14059. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14060. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14061. "2610 FCF (x%x) reached driver's book "
  14062. "keeping dimension:x%x\n",
  14063. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14064. return -EINVAL;
  14065. }
  14066. /* Set the eligible FCF record index bmask */
  14067. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14068. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14069. "2790 Set FCF (x%x) to roundrobin FCF failover "
  14070. "bmask\n", fcf_index);
  14071. return 0;
  14072. }
  14073. /**
  14074. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  14075. * @phba: pointer to lpfc hba data structure.
  14076. *
  14077. * This routine clears the FCF record index from the eligible bmask for
  14078. * roundrobin failover search. It checks to make sure that the index
  14079. * does not go beyond the range of the driver allocated bmask dimension
  14080. * before clearing the bit.
  14081. **/
  14082. void
  14083. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  14084. {
  14085. struct lpfc_fcf_pri *fcf_pri;
  14086. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  14087. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14088. "2762 FCF (x%x) reached driver's book "
  14089. "keeping dimension:x%x\n",
  14090. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  14091. return;
  14092. }
  14093. /* Clear the eligible FCF record index bmask */
  14094. spin_lock_irq(&phba->hbalock);
  14095. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  14096. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  14097. list_del_init(&fcf_pri->list);
  14098. break;
  14099. }
  14100. }
  14101. spin_unlock_irq(&phba->hbalock);
  14102. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  14103. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14104. "2791 Clear FCF (x%x) from roundrobin failover "
  14105. "bmask\n", fcf_index);
  14106. }
  14107. /**
  14108. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  14109. * @phba: pointer to lpfc hba data structure.
  14110. *
  14111. * This routine is the completion routine for the rediscover FCF table mailbox
  14112. * command. If the mailbox command returned failure, it will try to stop the
  14113. * FCF rediscover wait timer.
  14114. **/
  14115. void
  14116. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  14117. {
  14118. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14119. uint32_t shdr_status, shdr_add_status;
  14120. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14121. shdr_status = bf_get(lpfc_mbox_hdr_status,
  14122. &redisc_fcf->header.cfg_shdr.response);
  14123. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  14124. &redisc_fcf->header.cfg_shdr.response);
  14125. if (shdr_status || shdr_add_status) {
  14126. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  14127. "2746 Requesting for FCF rediscovery failed "
  14128. "status x%x add_status x%x\n",
  14129. shdr_status, shdr_add_status);
  14130. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  14131. spin_lock_irq(&phba->hbalock);
  14132. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  14133. spin_unlock_irq(&phba->hbalock);
  14134. /*
  14135. * CVL event triggered FCF rediscover request failed,
  14136. * last resort to re-try current registered FCF entry.
  14137. */
  14138. lpfc_retry_pport_discovery(phba);
  14139. } else {
  14140. spin_lock_irq(&phba->hbalock);
  14141. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  14142. spin_unlock_irq(&phba->hbalock);
  14143. /*
  14144. * DEAD FCF event triggered FCF rediscover request
  14145. * failed, last resort to fail over as a link down
  14146. * to FCF registration.
  14147. */
  14148. lpfc_sli4_fcf_dead_failthrough(phba);
  14149. }
  14150. } else {
  14151. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  14152. "2775 Start FCF rediscover quiescent timer\n");
  14153. /*
  14154. * Start FCF rediscovery wait timer for pending FCF
  14155. * before rescan FCF record table.
  14156. */
  14157. lpfc_fcf_redisc_wait_start_timer(phba);
  14158. }
  14159. mempool_free(mbox, phba->mbox_mem_pool);
  14160. }
  14161. /**
  14162. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  14163. * @phba: pointer to lpfc hba data structure.
  14164. *
  14165. * This routine is invoked to request for rediscovery of the entire FCF table
  14166. * by the port.
  14167. **/
  14168. int
  14169. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  14170. {
  14171. LPFC_MBOXQ_t *mbox;
  14172. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  14173. int rc, length;
  14174. /* Cancel retry delay timers to all vports before FCF rediscover */
  14175. lpfc_cancel_all_vport_retry_delay_timer(phba);
  14176. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14177. if (!mbox) {
  14178. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14179. "2745 Failed to allocate mbox for "
  14180. "requesting FCF rediscover.\n");
  14181. return -ENOMEM;
  14182. }
  14183. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  14184. sizeof(struct lpfc_sli4_cfg_mhdr));
  14185. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14186. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  14187. length, LPFC_SLI4_MBX_EMBED);
  14188. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  14189. /* Set count to 0 for invalidating the entire FCF database */
  14190. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  14191. /* Issue the mailbox command asynchronously */
  14192. mbox->vport = phba->pport;
  14193. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  14194. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  14195. if (rc == MBX_NOT_FINISHED) {
  14196. mempool_free(mbox, phba->mbox_mem_pool);
  14197. return -EIO;
  14198. }
  14199. return 0;
  14200. }
  14201. /**
  14202. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  14203. * @phba: pointer to lpfc hba data structure.
  14204. *
  14205. * This function is the failover routine as a last resort to the FCF DEAD
  14206. * event when driver failed to perform fast FCF failover.
  14207. **/
  14208. void
  14209. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  14210. {
  14211. uint32_t link_state;
  14212. /*
  14213. * Last resort as FCF DEAD event failover will treat this as
  14214. * a link down, but save the link state because we don't want
  14215. * it to be changed to Link Down unless it is already down.
  14216. */
  14217. link_state = phba->link_state;
  14218. lpfc_linkdown(phba);
  14219. phba->link_state = link_state;
  14220. /* Unregister FCF if no devices connected to it */
  14221. lpfc_unregister_unused_fcf(phba);
  14222. }
  14223. /**
  14224. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  14225. * @phba: pointer to lpfc hba data structure.
  14226. * @rgn23_data: pointer to configure region 23 data.
  14227. *
  14228. * This function gets SLI3 port configure region 23 data through memory dump
  14229. * mailbox command. When it successfully retrieves data, the size of the data
  14230. * will be returned, otherwise, 0 will be returned.
  14231. **/
  14232. static uint32_t
  14233. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14234. {
  14235. LPFC_MBOXQ_t *pmb = NULL;
  14236. MAILBOX_t *mb;
  14237. uint32_t offset = 0;
  14238. int rc;
  14239. if (!rgn23_data)
  14240. return 0;
  14241. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14242. if (!pmb) {
  14243. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14244. "2600 failed to allocate mailbox memory\n");
  14245. return 0;
  14246. }
  14247. mb = &pmb->u.mb;
  14248. do {
  14249. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  14250. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  14251. if (rc != MBX_SUCCESS) {
  14252. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  14253. "2601 failed to read config "
  14254. "region 23, rc 0x%x Status 0x%x\n",
  14255. rc, mb->mbxStatus);
  14256. mb->un.varDmp.word_cnt = 0;
  14257. }
  14258. /*
  14259. * dump mem may return a zero when finished or we got a
  14260. * mailbox error, either way we are done.
  14261. */
  14262. if (mb->un.varDmp.word_cnt == 0)
  14263. break;
  14264. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  14265. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  14266. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  14267. rgn23_data + offset,
  14268. mb->un.varDmp.word_cnt);
  14269. offset += mb->un.varDmp.word_cnt;
  14270. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  14271. mempool_free(pmb, phba->mbox_mem_pool);
  14272. return offset;
  14273. }
  14274. /**
  14275. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  14276. * @phba: pointer to lpfc hba data structure.
  14277. * @rgn23_data: pointer to configure region 23 data.
  14278. *
  14279. * This function gets SLI4 port configure region 23 data through memory dump
  14280. * mailbox command. When it successfully retrieves data, the size of the data
  14281. * will be returned, otherwise, 0 will be returned.
  14282. **/
  14283. static uint32_t
  14284. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  14285. {
  14286. LPFC_MBOXQ_t *mboxq = NULL;
  14287. struct lpfc_dmabuf *mp = NULL;
  14288. struct lpfc_mqe *mqe;
  14289. uint32_t data_length = 0;
  14290. int rc;
  14291. if (!rgn23_data)
  14292. return 0;
  14293. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14294. if (!mboxq) {
  14295. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14296. "3105 failed to allocate mailbox memory\n");
  14297. return 0;
  14298. }
  14299. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  14300. goto out;
  14301. mqe = &mboxq->u.mqe;
  14302. mp = (struct lpfc_dmabuf *) mboxq->context1;
  14303. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  14304. if (rc)
  14305. goto out;
  14306. data_length = mqe->un.mb_words[5];
  14307. if (data_length == 0)
  14308. goto out;
  14309. if (data_length > DMP_RGN23_SIZE) {
  14310. data_length = 0;
  14311. goto out;
  14312. }
  14313. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  14314. out:
  14315. mempool_free(mboxq, phba->mbox_mem_pool);
  14316. if (mp) {
  14317. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14318. kfree(mp);
  14319. }
  14320. return data_length;
  14321. }
  14322. /**
  14323. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  14324. * @phba: pointer to lpfc hba data structure.
  14325. *
  14326. * This function read region 23 and parse TLV for port status to
  14327. * decide if the user disaled the port. If the TLV indicates the
  14328. * port is disabled, the hba_flag is set accordingly.
  14329. **/
  14330. void
  14331. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  14332. {
  14333. uint8_t *rgn23_data = NULL;
  14334. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  14335. uint32_t offset = 0;
  14336. /* Get adapter Region 23 data */
  14337. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  14338. if (!rgn23_data)
  14339. goto out;
  14340. if (phba->sli_rev < LPFC_SLI_REV4)
  14341. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  14342. else {
  14343. if_type = bf_get(lpfc_sli_intf_if_type,
  14344. &phba->sli4_hba.sli_intf);
  14345. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  14346. goto out;
  14347. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  14348. }
  14349. if (!data_size)
  14350. goto out;
  14351. /* Check the region signature first */
  14352. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  14353. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14354. "2619 Config region 23 has bad signature\n");
  14355. goto out;
  14356. }
  14357. offset += 4;
  14358. /* Check the data structure version */
  14359. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  14360. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14361. "2620 Config region 23 has bad version\n");
  14362. goto out;
  14363. }
  14364. offset += 4;
  14365. /* Parse TLV entries in the region */
  14366. while (offset < data_size) {
  14367. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  14368. break;
  14369. /*
  14370. * If the TLV is not driver specific TLV or driver id is
  14371. * not linux driver id, skip the record.
  14372. */
  14373. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  14374. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  14375. (rgn23_data[offset + 3] != 0)) {
  14376. offset += rgn23_data[offset + 1] * 4 + 4;
  14377. continue;
  14378. }
  14379. /* Driver found a driver specific TLV in the config region */
  14380. sub_tlv_len = rgn23_data[offset + 1] * 4;
  14381. offset += 4;
  14382. tlv_offset = 0;
  14383. /*
  14384. * Search for configured port state sub-TLV.
  14385. */
  14386. while ((offset < data_size) &&
  14387. (tlv_offset < sub_tlv_len)) {
  14388. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  14389. offset += 4;
  14390. tlv_offset += 4;
  14391. break;
  14392. }
  14393. if (rgn23_data[offset] != PORT_STE_TYPE) {
  14394. offset += rgn23_data[offset + 1] * 4 + 4;
  14395. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  14396. continue;
  14397. }
  14398. /* This HBA contains PORT_STE configured */
  14399. if (!rgn23_data[offset + 2])
  14400. phba->hba_flag |= LINK_DISABLED;
  14401. goto out;
  14402. }
  14403. }
  14404. out:
  14405. kfree(rgn23_data);
  14406. return;
  14407. }
  14408. /**
  14409. * lpfc_wr_object - write an object to the firmware
  14410. * @phba: HBA structure that indicates port to create a queue on.
  14411. * @dmabuf_list: list of dmabufs to write to the port.
  14412. * @size: the total byte value of the objects to write to the port.
  14413. * @offset: the current offset to be used to start the transfer.
  14414. *
  14415. * This routine will create a wr_object mailbox command to send to the port.
  14416. * the mailbox command will be constructed using the dma buffers described in
  14417. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  14418. * BDEs that the imbedded mailbox can support. The @offset variable will be
  14419. * used to indicate the starting offset of the transfer and will also return
  14420. * the offset after the write object mailbox has completed. @size is used to
  14421. * determine the end of the object and whether the eof bit should be set.
  14422. *
  14423. * Return 0 is successful and offset will contain the the new offset to use
  14424. * for the next write.
  14425. * Return negative value for error cases.
  14426. **/
  14427. int
  14428. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  14429. uint32_t size, uint32_t *offset)
  14430. {
  14431. struct lpfc_mbx_wr_object *wr_object;
  14432. LPFC_MBOXQ_t *mbox;
  14433. int rc = 0, i = 0;
  14434. uint32_t shdr_status, shdr_add_status;
  14435. uint32_t mbox_tmo;
  14436. union lpfc_sli4_cfg_shdr *shdr;
  14437. struct lpfc_dmabuf *dmabuf;
  14438. uint32_t written = 0;
  14439. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14440. if (!mbox)
  14441. return -ENOMEM;
  14442. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14443. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  14444. sizeof(struct lpfc_mbx_wr_object) -
  14445. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  14446. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  14447. wr_object->u.request.write_offset = *offset;
  14448. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  14449. wr_object->u.request.object_name[0] =
  14450. cpu_to_le32(wr_object->u.request.object_name[0]);
  14451. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  14452. list_for_each_entry(dmabuf, dmabuf_list, list) {
  14453. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  14454. break;
  14455. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  14456. wr_object->u.request.bde[i].addrHigh =
  14457. putPaddrHigh(dmabuf->phys);
  14458. if (written + SLI4_PAGE_SIZE >= size) {
  14459. wr_object->u.request.bde[i].tus.f.bdeSize =
  14460. (size - written);
  14461. written += (size - written);
  14462. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  14463. } else {
  14464. wr_object->u.request.bde[i].tus.f.bdeSize =
  14465. SLI4_PAGE_SIZE;
  14466. written += SLI4_PAGE_SIZE;
  14467. }
  14468. i++;
  14469. }
  14470. wr_object->u.request.bde_count = i;
  14471. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  14472. if (!phba->sli4_hba.intr_enable)
  14473. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14474. else {
  14475. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  14476. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  14477. }
  14478. /* The IOCTL status is embedded in the mailbox subheader. */
  14479. shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
  14480. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14481. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14482. if (rc != MBX_TIMEOUT)
  14483. mempool_free(mbox, phba->mbox_mem_pool);
  14484. if (shdr_status || shdr_add_status || rc) {
  14485. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  14486. "3025 Write Object mailbox failed with "
  14487. "status x%x add_status x%x, mbx status x%x\n",
  14488. shdr_status, shdr_add_status, rc);
  14489. rc = -ENXIO;
  14490. } else
  14491. *offset += wr_object->u.response.actual_write_length;
  14492. return rc;
  14493. }
  14494. /**
  14495. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  14496. * @vport: pointer to vport data structure.
  14497. *
  14498. * This function iterate through the mailboxq and clean up all REG_LOGIN
  14499. * and REG_VPI mailbox commands associated with the vport. This function
  14500. * is called when driver want to restart discovery of the vport due to
  14501. * a Clear Virtual Link event.
  14502. **/
  14503. void
  14504. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  14505. {
  14506. struct lpfc_hba *phba = vport->phba;
  14507. LPFC_MBOXQ_t *mb, *nextmb;
  14508. struct lpfc_dmabuf *mp;
  14509. struct lpfc_nodelist *ndlp;
  14510. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  14511. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  14512. LIST_HEAD(mbox_cmd_list);
  14513. uint8_t restart_loop;
  14514. /* Clean up internally queued mailbox commands with the vport */
  14515. spin_lock_irq(&phba->hbalock);
  14516. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  14517. if (mb->vport != vport)
  14518. continue;
  14519. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14520. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14521. continue;
  14522. list_del(&mb->list);
  14523. list_add_tail(&mb->list, &mbox_cmd_list);
  14524. }
  14525. /* Clean up active mailbox command with the vport */
  14526. mb = phba->sli.mbox_active;
  14527. if (mb && (mb->vport == vport)) {
  14528. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  14529. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  14530. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14531. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14532. act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
  14533. /* Put reference count for delayed processing */
  14534. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  14535. /* Unregister the RPI when mailbox complete */
  14536. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14537. }
  14538. }
  14539. /* Cleanup any mailbox completions which are not yet processed */
  14540. do {
  14541. restart_loop = 0;
  14542. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  14543. /*
  14544. * If this mailox is already processed or it is
  14545. * for another vport ignore it.
  14546. */
  14547. if ((mb->vport != vport) ||
  14548. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  14549. continue;
  14550. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  14551. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  14552. continue;
  14553. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14554. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14555. ndlp = (struct lpfc_nodelist *)mb->context2;
  14556. /* Unregister the RPI when mailbox complete */
  14557. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  14558. restart_loop = 1;
  14559. spin_unlock_irq(&phba->hbalock);
  14560. spin_lock(shost->host_lock);
  14561. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14562. spin_unlock(shost->host_lock);
  14563. spin_lock_irq(&phba->hbalock);
  14564. break;
  14565. }
  14566. }
  14567. } while (restart_loop);
  14568. spin_unlock_irq(&phba->hbalock);
  14569. /* Release the cleaned-up mailbox commands */
  14570. while (!list_empty(&mbox_cmd_list)) {
  14571. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  14572. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  14573. mp = (struct lpfc_dmabuf *) (mb->context1);
  14574. if (mp) {
  14575. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  14576. kfree(mp);
  14577. }
  14578. ndlp = (struct lpfc_nodelist *) mb->context2;
  14579. mb->context2 = NULL;
  14580. if (ndlp) {
  14581. spin_lock(shost->host_lock);
  14582. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14583. spin_unlock(shost->host_lock);
  14584. lpfc_nlp_put(ndlp);
  14585. }
  14586. }
  14587. mempool_free(mb, phba->mbox_mem_pool);
  14588. }
  14589. /* Release the ndlp with the cleaned-up active mailbox command */
  14590. if (act_mbx_ndlp) {
  14591. spin_lock(shost->host_lock);
  14592. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  14593. spin_unlock(shost->host_lock);
  14594. lpfc_nlp_put(act_mbx_ndlp);
  14595. }
  14596. }
  14597. /**
  14598. * lpfc_drain_txq - Drain the txq
  14599. * @phba: Pointer to HBA context object.
  14600. *
  14601. * This function attempt to submit IOCBs on the txq
  14602. * to the adapter. For SLI4 adapters, the txq contains
  14603. * ELS IOCBs that have been deferred because the there
  14604. * are no SGLs. This congestion can occur with large
  14605. * vport counts during node discovery.
  14606. **/
  14607. uint32_t
  14608. lpfc_drain_txq(struct lpfc_hba *phba)
  14609. {
  14610. LIST_HEAD(completions);
  14611. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  14612. struct lpfc_iocbq *piocbq = 0;
  14613. unsigned long iflags = 0;
  14614. char *fail_msg = NULL;
  14615. struct lpfc_sglq *sglq;
  14616. union lpfc_wqe wqe;
  14617. spin_lock_irqsave(&phba->hbalock, iflags);
  14618. if (pring->txq_cnt > pring->txq_max)
  14619. pring->txq_max = pring->txq_cnt;
  14620. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14621. while (pring->txq_cnt) {
  14622. spin_lock_irqsave(&phba->hbalock, iflags);
  14623. piocbq = lpfc_sli_ringtx_get(phba, pring);
  14624. sglq = __lpfc_sli_get_sglq(phba, piocbq);
  14625. if (!sglq) {
  14626. __lpfc_sli_ringtx_put(phba, pring, piocbq);
  14627. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14628. break;
  14629. } else {
  14630. if (!piocbq) {
  14631. /* The txq_cnt out of sync. This should
  14632. * never happen
  14633. */
  14634. sglq = __lpfc_clear_active_sglq(phba,
  14635. sglq->sli4_lxritag);
  14636. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14637. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14638. "2823 txq empty and txq_cnt is %d\n ",
  14639. pring->txq_cnt);
  14640. break;
  14641. }
  14642. }
  14643. /* The xri and iocb resources secured,
  14644. * attempt to issue request
  14645. */
  14646. piocbq->sli4_lxritag = sglq->sli4_lxritag;
  14647. piocbq->sli4_xritag = sglq->sli4_xritag;
  14648. if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
  14649. fail_msg = "to convert bpl to sgl";
  14650. else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
  14651. fail_msg = "to convert iocb to wqe";
  14652. else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
  14653. fail_msg = " - Wq is full";
  14654. else
  14655. lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
  14656. if (fail_msg) {
  14657. /* Failed means we can't issue and need to cancel */
  14658. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  14659. "2822 IOCB failed %s iotag 0x%x "
  14660. "xri 0x%x\n",
  14661. fail_msg,
  14662. piocbq->iotag, piocbq->sli4_xritag);
  14663. list_add_tail(&piocbq->list, &completions);
  14664. }
  14665. spin_unlock_irqrestore(&phba->hbalock, iflags);
  14666. }
  14667. /* Cancel all the IOCBs that cannot be issued */
  14668. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  14669. IOERR_SLI_ABORTED);
  14670. return pring->txq_cnt;
  14671. }